如何使用Dialogflow Fulfillment Library WebhookClient类设置“结束对话”标志?我正在使用由Cloud Functions for Firebase提供支持的内联编辑器,以防万一 .
情况是特定意图不能访问超过3次 . 在第一次和第二次访问中,您会收到回复,它可以让您说出一些内容并继续;在第三次访问时,它应该给出响应然后结束对话/关闭麦克风/杀死应用程序(无论适当的术语是什么)
对于非结束响应,我正在使用WebhookClient.add(),我正在使用丰富的响应和文本到语音的字符串 .
从我在github(https://github.com/dialogflow/dialogflow-fulfillment-nodejs)上看到的,我假设WebhookClient.end()将是我想要的 . 但是当我使用它时,sript崩溃了,我什么都没得到 . 以下全部内容 exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {...}
const agent = new WebhookClient({ request, response });
const fbContext = 'fallbackcount';
function fallback(agent) {
//all fallbacks use this fulfillment, we give up after 3 bunk responses
//check if we've been here before - we will find a context with a counter if we have
let countContext = agent.getContext(fbContext);
let fbcount = 0;
if (countContext)
{
if (typeof countContext.parameters !== "undefined" )
{
if(typeof countContext.parameters.count !== "undefined" )
{
fbcount = countContext.parameters.count;
}
}
}
console.log("current tracking" + fbcount.toString());
switch(fbcount) {
case 0:
{
agent.add(`Fallback response 1");
break;
}
case 1:
{
agent.add("Fallback response 2");
break;
}
default:
{
//intention: die on third bunk response
//reality: following line causes a problem and i get no response, and the app doesn't close
agent.end("Fallback response 3 - Goodbye!");
}
}
let newcount = fbcount + 1;
console.log("new tracking " + newcount.toString());
agent.setContext({
name: fbContext,
lifespan: 1,
parameters:{count: newcount}
});
}
我究竟做错了什么?
请注意,这不是Actions on Google: Unable to Close Convo in DialogFlow Fulfillment的副本,因为他询问有关Google图库的操作,我正在使用dialogflow-fulfillment-nodejs
我也看过Dialogflow API V2 "End of conversation" flag in webhook request,这似乎是在处理原始的json,我认为应该可以避免我在docs中看到的内容
2 回答
在这种情况下,我不知道这是否是正确的方法,但我猜你可以使用有效负载响应关闭对话,在其中将“expectedUserResponse”设置为“false”:
这对我有用: