javascript - Dialogflow:如何在环聊中接收图片?(Javascript)
问题描述
我正在尝试在连接到环聊的 Dialogflow 中构建一个聊天机器人。我正在接收图像等文件。
我发现了一个关于“如何在 WhatsApp 聊天机器人(通过对话流)上接收图像、音频、视频和富媒体”的youtube 视频。我已按照说明进行操作,但有些东西不起作用。
这是我的 index.js 代码(内联编辑器 - Fulfillment):
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
process.env.DEBUG = 'dialogflow:debug';
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(`¡Bienvenido a mi chatbot! ¿Quieres subir un código QR?`);
}
function fallback(agent) {
agent.add(`Lo siento, no te he entendido.`);
agent.add(`¿Podrías repetir otra vez?`);
}
function mediaHandler(agent) {
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
let originalRequest = request.body.originalDetectIntentRequest;
agent.add(`Aquí tengo el archivo que me has mandado, gracias.` + originalRequest.payload.data.MediaUrl0);
});
}
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
intentMap.set('Hangouts Media - fallback', mediaHandler);
agent.handleRequest(intentMap);});
这些是我的意图:
这是错误:
错误:Exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/srv/index.js) 处的 WebhookClient.handleRequest (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:327:29) 中没有请求意图的处理程序:94:9) 在 cloudFunction (/srv/node_modules/firebase-functions/lib/providers/https.js:26:47) 在 /worker/worker.js:783:7 在 /worker/worker.js:766: 11 在 _combinedTickCallback (internal/process/next_tick.js:132:7) 在 process._tickDomainCallback (internal/process/next_tick.js:219:9)
最后,这是 package.json:
{
"name": "dialogflowFirebaseFulfillment",
"description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
"engines": {
"node": "^6.0"
},
"scripts": {
"start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
"deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
},
"dependencies": {
"actions-on-google": "^2.0.0-alpha.4",
"firebase-admin": "^4.2.1",
"firebase-functions": "^0.5.7",
"dialogflow": "^0.1.0",
"dialogflow-fulfillment": "^0.6.1",
"qrcode-decoder": "^0.1.2",
"xmlhttprequest": "^1.8.0",
"filereader": "^0.10.3"
}
}
你知道我该如何解决我的错误吗?先感谢您!
解决方案
推荐阅读
- html - CSS 溢出不适用于表格选择器
- tabs - 使用 conemu GuiMacro Tab() 函数切换选项卡不起作用
- docker - 如何在 Jelastic 环境中将数据卷挂载到添加的节点上
- python - 获取 2 个列表之间的不常见项目
- php - 在 Wordpress/Woocommerce 中将特定作者的产品推送到搜索结果的顶部
- reactjs - gatsby + react hook masonry 在构建时中断,因为没有窗口
- python - 使用 Python 根据另一列的条件计算同一列中最小值之间的日期差异
- c# - 通过API获取签名文档时,下载时没有签名
- linux - 为什么htop命令显示黑屏
- scheme - 在我的 Script-Fu 中使用除非指令阻止它工作