DialogFlow,完成操作后保持助手打开
DialogFlow, keep assistant open after completing action
我在测试我的 Google 助手应用程序(在 DialogFlow 中制作)时遇到问题。每次我 运行 第一个意图并满足 运行 相应操作的条件时,助手结束并且不允许用户输入可能触发后续意图的值。每次都关闭麦克风而不是继续对话。
有没有办法设置 intents 和相应的 webhook 以确保应用程序不会在每次完成单个操作时自行关闭?
'use strict';
process.env.DEBUG = 'actions-on-google:*';
const App = require('actions-on-google').DialogflowApp;
const functions = require('firebase-functions');
// x. start custom code
const orderLists = [
{
reference: '0',
clothing: ['shirt', 'top', 'bra'],
deliveryStatus: 'will be delivered before 1pm, make sure youre in!'
},
{
reference: '1',
clothing: ['shirt', 'top', 'bra'],
deliveryStatus: 'is due for delivery on February 2nd.'
},
{
reference: '2',
clothing: ['shirt', 'top', 'bra'],
deliveryStatus: 'is due for delivery on February 3rd.'
},
{
reference: '3',
clothing: ['shirt', 'top', 'bra'],
deliveryStatus: 'was delivered today at 2pm to your default address.'
},
{
reference: '4',
clothing: ['shirt', 'top', 'bra'],
deliveryStatus: 'was left with your neighbour at 22 Waltham Drive, today at 2pm.'
}
]
// a. the action name from the make_name Dialogflow intent
// const NAME_ACTION = 'make_name';
const NAME_ACTION = 'query_order';
const NAME_ACTION2 = 'query_order.query_order-more';
// b. the parameters that are parsed from the make_name intent
// const COLOR_ARGUMENT = 'color';
// const NUMBER_ARGUMENT = 'number';
const ORDERNUMBER_ARGUMENT = 'number';
const min = 0;
const max = 10;
exports.sillyNameMaker = functions.https.onRequest((request, response) => {
const app = new App({request, response});
console.log('Request headers: ' + JSON.stringify(request.headers));
console.log('Request body: ' + JSON.stringify(request.body));
// c. The function that generates the silly name
function queryOrder (app) {
let number = app.getArgument(ORDERNUMBER_ARGUMENT);
app.tell('Order number '+ number + ', ' + orderLists[number].deliveryStatus) + 'Would you like to know more?';
}
function queryOrderItems (app) {
let number = app.getArgument(ORDERNUMBER_ARGUMENT);
app.tell('Order number '+ number + ', ' + orderLists[number].clothing);
}
// d. build an action map, which maps intent names to functions
let actionMap = new Map();
actionMap.set(NAME_ACTION, queryOrder);
let actionMap2 = new Map();
actionMap2.set(NAME_ACTION2, queryOrderItems);
app.handleRequest(actionMap);
app.handleRequest(actionMap2);
});
问题是,在每种情况下,您都使用 app.tell()
将消息发回给用户。这不仅会发送消息,还会告诉智能助理对话结束并关闭麦克风。
如果您想继续对话(保持麦克风打开并等待用户回复),您应该改用 app.ask()
。
因此您的 queryOrder()
方法可能如下所示:
function queryOrder (app) {
let number = app.getArgument(ORDERNUMBER_ARGUMENT);
app.ask('Order number '+ number + ', ' + orderLists[number].deliveryStatus) + 'Would you like to know more?';
}
(顺便说一句 - 在这种情况下询问 "Would you like more?" 是非常好的做法。切勿在未提示用户预期内容的情况下让麦克风保持打开状态。)
我在测试我的 Google 助手应用程序(在 DialogFlow 中制作)时遇到问题。每次我 运行 第一个意图并满足 运行 相应操作的条件时,助手结束并且不允许用户输入可能触发后续意图的值。每次都关闭麦克风而不是继续对话。
有没有办法设置 intents 和相应的 webhook 以确保应用程序不会在每次完成单个操作时自行关闭?
'use strict';
process.env.DEBUG = 'actions-on-google:*';
const App = require('actions-on-google').DialogflowApp;
const functions = require('firebase-functions');
// x. start custom code
const orderLists = [
{
reference: '0',
clothing: ['shirt', 'top', 'bra'],
deliveryStatus: 'will be delivered before 1pm, make sure youre in!'
},
{
reference: '1',
clothing: ['shirt', 'top', 'bra'],
deliveryStatus: 'is due for delivery on February 2nd.'
},
{
reference: '2',
clothing: ['shirt', 'top', 'bra'],
deliveryStatus: 'is due for delivery on February 3rd.'
},
{
reference: '3',
clothing: ['shirt', 'top', 'bra'],
deliveryStatus: 'was delivered today at 2pm to your default address.'
},
{
reference: '4',
clothing: ['shirt', 'top', 'bra'],
deliveryStatus: 'was left with your neighbour at 22 Waltham Drive, today at 2pm.'
}
]
// a. the action name from the make_name Dialogflow intent
// const NAME_ACTION = 'make_name';
const NAME_ACTION = 'query_order';
const NAME_ACTION2 = 'query_order.query_order-more';
// b. the parameters that are parsed from the make_name intent
// const COLOR_ARGUMENT = 'color';
// const NUMBER_ARGUMENT = 'number';
const ORDERNUMBER_ARGUMENT = 'number';
const min = 0;
const max = 10;
exports.sillyNameMaker = functions.https.onRequest((request, response) => {
const app = new App({request, response});
console.log('Request headers: ' + JSON.stringify(request.headers));
console.log('Request body: ' + JSON.stringify(request.body));
// c. The function that generates the silly name
function queryOrder (app) {
let number = app.getArgument(ORDERNUMBER_ARGUMENT);
app.tell('Order number '+ number + ', ' + orderLists[number].deliveryStatus) + 'Would you like to know more?';
}
function queryOrderItems (app) {
let number = app.getArgument(ORDERNUMBER_ARGUMENT);
app.tell('Order number '+ number + ', ' + orderLists[number].clothing);
}
// d. build an action map, which maps intent names to functions
let actionMap = new Map();
actionMap.set(NAME_ACTION, queryOrder);
let actionMap2 = new Map();
actionMap2.set(NAME_ACTION2, queryOrderItems);
app.handleRequest(actionMap);
app.handleRequest(actionMap2);
});
问题是,在每种情况下,您都使用 app.tell()
将消息发回给用户。这不仅会发送消息,还会告诉智能助理对话结束并关闭麦克风。
如果您想继续对话(保持麦克风打开并等待用户回复),您应该改用 app.ask()
。
因此您的 queryOrder()
方法可能如下所示:
function queryOrder (app) {
let number = app.getArgument(ORDERNUMBER_ARGUMENT);
app.ask('Order number '+ number + ', ' + orderLists[number].deliveryStatus) + 'Would you like to know more?';
}
(顺便说一句 - 在这种情况下询问 "Would you like more?" 是非常好的做法。切勿在未提示用户预期内容的情况下让麦克风保持打开状态。)