dialogflow-es - Google dialogflow agent.add(new Suggestion()) 无法在 dialogflow Messenger 上运行
问题描述
我正在尝试使用实现(内联编辑器)添加建议芯片的非常基本的代码,但它不起作用。以下是我尝试使用的代码:
'use strict';
const functions = require('firebase-functions');
const { WebhookClient } = require('dialogflow-fulfillment');
const { Card, Suggestion } = require('dialogflow-fulfillment');
const { Suggestions } = require('actions-on-google');
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(new Suggestion(`Quick Reply`));
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 yourFunctionHandler(agent) {
agent.add(`This message is from Dialogflow's Cloud Functions for Firebase editor!`);
//the following suggestion chips are not working
agent.add(new Suggestion(`Quick Reply`));
agent.add(new Suggestion(`Suggestion`));
}
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
intentMap.set('car', yourFunctionHandler);
agent.handleRequest(intentMap);
});
以下是对话流信使的图像:
解决方案
您的代码中的 Suggestions Chips 指令似乎是用于 Assistant 集成的。如果您在 Google 助理中测试您的代理很可能会工作(对于电话设备)。我测试了以下代码,在这种情况下得到了预期的输出:
function yourFunctionHandler(agent) {
agent.add(`This message is from Dialogflow's Cloud Functions for Firebase editor!`);
agent.add(new Card({
title: `Title: this is a card title`,
imageUrl: 'https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png',
text: `This is the body text of a card. You can even use line\n breaks and emoji! `,
buttonText: 'This is a button',
buttonUrl: 'https://assistant.google.com/'
})
);
agent.add(new Suggestion(`Quick Reply`));
agent.add(new Suggestion(`Suggestion`));
}
由于您的目标是通过 Dialogflow Messenger 集成使其工作,我可以想到两个选项:
您可以在 Dialogflow 控制台中指定自定义负载。在您的意图中有一个默认响应部分,当您单击时,
ADD RESPONSE
您将看到选项自定义有效负载。您可以在其中粘贴Chips 代码示例,并且 Intent 将使用 Dialogflow Messenger 中的芯片进行响应。要使其从 Fulfillment 部分工作,您需要为丰富的响应构建 json 结构,有效负载应该在其中
richContent
。我不确定如何在内联编辑器中使用 NodeJS 来返回 json 响应,但我使用 python 构建了自己的 Cloud Function 并将其配置为我的Webhook。
这种方法有效,我遵循的程序发布在这里,这是我的功能:
def entry_function(request):
response_json = jsonify(
fulfillment_text="This message is from Dialogflow's testing!",
fulfillment_messages=[
{
"payload": {
"richContent": [[{
"actionLink": "https://assistant.google.com/",
"subtitle": "This is the body text of a card. You can even use line\n breaks and emoji! ",
"title": "Title: this is a card title",
"type": "info"
},
{
"type": "chips",
"options": [
{
"text": "Chip 1",
"image": {
"src": {
"rawUrl": "https://example.com/images/logo.png"
}
},
"link": "https://example.com"
},
{
"text": "Chip 2",
"image": {
"src": {
"rawUrl": "https://example.com/images/logo.png"
}
},
"link": "https://example.com"
}
]
}]]
}
}
]
)
return response_json
推荐阅读
- discord - 将反应复制到不和谐消息
- reactjs - 找不到模块:无法解析 header.js 或 app.js
- javascript - 结合ChartsJs以德语数据格式输入数据
- java - Mockito,如何验证是否调用了测试类的方法?
- javascript - `Object.prototype.constructor` 和 `Symbol.species` 有什么区别?
- windows - JFrog 工件:配置向导未启动
- python - VS 2019 中的 Python 代码,突出显示的引用颜色不起作用
- python - 根据条件合并两个具有相同维度的数组
- c# - UWP XAML 如何识别来自字符串的 ImageSource 转换
- postgresql - 如何从 Postgres 循环流式传输行?(F#/.NET 但任何其他语言都可以)