![](/img/trans.png)
[英]How to use android deeplink with custom DialogFlow action for google assistant?
[英]How do I end my custom action on assistant?
我有一个非常简单的操作,只是给了我一些状态,然后我想结束它,没有对话,没有别的,只是获取状态并结束它。 现在我正在这样做:
agent.add(message1);
agent.add(message2);
agent.end('done');
我也尝试过(正如您将在下面的代码中看到的那样,只是在做agent.end(completeMessage);
但助手一直在等待我做更多事情,我的行动并没有结束。
我制作了一个完全简单的示例来演示, test intent
是具有end()
调用的意图:
代码:
'use strict';
const functions = require('firebase-functions');
const { WebhookClient } = require('dialogflow-fulfillment');
const { Card, Suggestion } = require('dialogflow-fulfillment');
const fetch = require("node-fetch");
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
function welcome(agent) {
agent.add(`Welcome to my agent!`);
}
function fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
function testIntent(agent) {
agent.end('done');
}
intent name
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
intentMap.set('test intent', testIntent);
agent.handleRequest(intentMap);
});
当我调用test intent
时,任何人都知道如何让我的行为完全结束?
如果您将 dialogflow-fulfillment 库与 Actions on Google 一起使用,则只能有两个简单的响应(文本或 SSML 字符串)。 由于您的代码在设置了两条消息后调用agent.end()
,因此它可能会被忽略。
相反,您可以将其称为
agent.add(message1);
agent.end(message2);
agent
的文档适用于WebhookClient object。 如果你想跳过这个库,还有webhook 响应JSON 文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.