![](/img/trans.png)
[英]How to show Rich Response Buttons (''Chips) Using Dialogflow Fulfillment?
[英]How to add Suggestion Chips through Fulfillment for the Dialogflow Messenger integration?
所以我在网站中嵌入了 Dialogflow Messenger,并想添加一些 Suggestion 芯片。 通过自定义有效负载响应类型很容易,它们显示得很好。 但是我如何通过履行添加它们?
我目前有一个自定义的 webhook 设置,想法是有这样的东西:
if (x) {
agent.add('blablabla');
agent.add(new Suggestion('One');
} else {
agent.add('blablabla');
agent.add(new Suggestion('Two');
}
新建议虽然不起作用,那么还有另一种方法吗? 我在想这样的事情:
agent.add(new Payload(
"richContent": [
[
{
"options": [
{
"text": "One"
},
{
"text": "Two"
}
],
"type": "chips"
}
]
]));
本质上是尝试将自定义有效负载直接插入到响应 JSON 中,如果这有意义的话。 但是是的,不知道如何实际做到这一点。 有谁知道怎么做?
我不清楚您所说的new Suggestion() 不起作用究竟是什么意思。 您是说 Dialogflow Messenger 中不显示建议芯片? 它们是否显示在 Dialogflow 本身中?
让我分享几点:
agent.add(new Suggestion(“One”));
应该管用。 我尝试了一个简单的例子,它在 Dialogflow UI 中运行良好,代码如下:const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
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));
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
function welcome(agent){
agent.add("What is your favorite animal?");
agent.add(new Suggestion("Dog"));
agent.add(new Suggestion("Cat"));
}
function fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
agent.handleRequest(intentMap);
});
如果即使在 Dialogflow UI 中也没有呈现建议芯片,我建议您尝试使用之前的代码来消除 Dialogflow 设置的任何潜在问题。 您可能需要升级一些依赖项,例如"dialogflow-fulfillment": "^0.6.1"
。
一些集成,例如 Google Assistant 使用来自actions-on-google
的Suggestions
库。 例如,请参阅官方 Google 助理代码示例。 如果它适合您的用例,您可以尝试遵循类似的行为,尽管我认为情况并非如此。 作为参考,您可以查看此github 问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.