【发布时间】:2019-01-10 21:27:10
【问题描述】:
我有一个无服务器应用程序,我想通过来自 Facebook Messenger 的聊天机器人请求运行我的逻辑。当我为 test_handler 运行意图函数时,我得到了正确的响应。但是在我为 skillRatio 添加了另一个处理程序之后,我似乎在标题中遇到了错误,即
错误:平台不能在新的有效负载处为空
。我的代码如下。
const serverless = require('serverless-http');
const bodyParser = require('body-parser');
const express = require('express');
const app = express();
app.use(bodyParser.json({ strict: false }));
const {WebhookClient, Payload, Image, Card, Suggestion} = require('dialogflow-fulfillment');
const request = require('request');
app.get('/', function (req, res) {
res.send('Hello World !!!\n');
console.log("Testing express lambda\n");
})
app.post('/', function (req, res) {
const agent = new WebhookClient({request: req, response: res});
function test_handler(agent) {
agent.add(`Welcome to my agent on AWS Lambda!`);
agent.add(new Image("https://image-charts.com/chart?chs=700x190&chd=t:60,40&cht=p3&chl=Hello%7CWorld&chf=ps0-0,lg,45,ffeb3b,0.2,f44336,1|ps0-1,lg,45,8bc34a,0.2,009688,1"))
}
function skillRatio(agent) {
agent.add(`Let me just have a look and I'll gather the data. *Processing Chart Data....Mmmm Pie*.
Here we go! Here is the data on your $Skills.original request.`);
//agent.add(`Feel free to save or share :)`);
//agent.add(new Image("https://image-charts.com/chart?chs=700x190&chd=t:60,40&cht=p3&chl=Hello%7CWorld&chf=ps0-0,lg,45,ffeb3b,0.2,f44336,1|ps0-1,lg,45,8bc34a,0.2,009688,1"))
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('super-test', test_handler);
//intentMap.set('skill-ratio', skillRatio);
if (agent.requestSource === agent.FACEBOOK) {
intentMap.set('super-test', test_handler);
intentMap.set('skill-ratio', skillRatio);
} else {
}
agent.handleRequest(intentMap);
})
module.exports.handler = serverless(app);
对话流图像:
我正在尝试在 Messenger 上运行代码。任何帮助都将不胜感激,因为我一直在努力解决这个问题。
【问题讨论】:
-
您能否通过 Dialogflow 中
skillRatioIntent 屏幕的屏幕截图更新您的问题?我还看到您正在专门测试agent.FACEBOOK。如果您取消注释intentMap.set()的技能比率并删除此 if 块会发生什么? -
囚徒,我当然可以,裸露在外。你只是想看短语吗?也感谢一百万的快速回复!我尝试测试 agent.FACEBOOK,因为我觉得它专门寻找平台。但我可以在 AWS CloudWatch 中看到 Facebook 已经设置好了。当我取消注释技能比率映射时,什么也没有发生。尝试调用它时,我的日志中出现错误。
-
查看整个 Intent 的所有部分可以帮助您了解问题是否出在短语之外 - 所以请尽可能包含所有内容。
-
我真的对自己很生气。事实证明,Dialogflow 图像上的默认有效负载导致了该问题。两次我以为我可以删除它,但认为它太小了,不能成为问题。删除自定义有效负载后,代码现在可以正常工作。很抱歉造成混乱,但也许这可能会在未来对其他人有所帮助。感谢您的帮助!
-
(但这就是我要求发布所有内容的原因。{:)
标签: node.js dialogflow-es