我有一个带有3个意图的dialogflow助手应用程序 . 第一个意图要求用户提供谷歌的位置和名称详细信息 . 我正在使用webhook来实现这个意图 . 我能够提取用户信息的名称和位置,但在显示webhook的输出后,它将退出流程 . 但它应该将位置参数传递给下一个意图并保持流程 . 任何人都可以帮助我如何阻止助手退出?这是webhook代码
'use strict';
const functions = require('firebase-functions');
const DialogflowApp = require('actions-on-google').DialogflowApp;
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const requestPermission = (app) => {
app.askForPermissions('To report ', [app.SupportedPermissions.NAME, app.SupportedPermissions.DEVICE_PRECISE_LOCATION]);
};
const userInfo = (app) => {
if (app.isPermissionGranted()) {
const address = app.getDeviceLocation().coordinates;
const name = app.getUserName().givenName;
if (name) {
app.tell(`You are name ${name}`);
}
else {
// Note: Currently, precise locaton only returns lat/lng coordinates on phones and lat/lng coordinates
// and a geocoded address on voice-activated speakers.
// Coarse location only works on voice-activated speakers.
app.tell('Sorry, I could not figure out where you are.Plaese try again');
}
} else {
app.tell('Sorry, I could not figure out where you are.Please try again');
}
};
const app = new DialogflowApp({request, response});
const actions = new Map();
actions.set('request_permission', requestPermission);
actions.set('user_info', userInfo);
app.handleRequest(actions);
});
1 回答
问题是您在代码中调用
app.tell()
,这是向助理发送消息然后结束对话的信号 .如果您要发送消息然后让麦克风打开以供用户回复,则应使用
app.ask()
代替 . 它采用相同的参数 - 唯一的区别是它希望用户回复 .因此,您的代码部分可能看起来像
(您应该确保用户的提示是他们希望回复的 . 如果您回复,审核过程将拒绝您的操作,并且用户应该回复您并不明显 . )