我有一个带有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);
});
答案 0 :(得分:1)
问题是您在代码中调用了app.tell()
,这是向助理发送消息然后结束对话的信号。
如果您要发送消息然后打开麦克风供用户回复,则应使用app.ask()
代替。它采用相同的参数 - 唯一的区别是它希望用户回复。
因此,您的代码部分可能类似于
if (name) {
app.ask(`You are name ${name}. What would you like to do now?`);
}
(您应确保该用户的提示是他们希望回复的提示。如果您回复,审核流程将拒绝您的操作,并且用户不应该回复您。)