首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误:对话流中的新有效载荷下的平台不能为空

错误:对话流中的新有效载荷下的平台不能为空
EN

Stack Overflow用户
提问于 2019-01-10 21:27:10
回答 2查看 2K关注 0票数 3

我有一个无服务器应用程序,我想运行我的逻辑从聊天机器人请求来自Facebook Messenger。当我运行test_handler的意图函数时,我会得到正确的响应。但是,在我为skillRatio添加了另一个处理程序之后,我似乎得到了标题中的错误,即

错误:在新的有效载荷下,平台不能为空

。我的代码如下。

代码语言:javascript
复制
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上运行代码。任何帮助都将是非常感谢的,因为我被困在试图使我的头在这里。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-01-11 11:57:35

结果,在下面的图片中,一个自定义的有效载荷导致了我遇到的问题。如果你有同样的错误

错误:在新的有效载荷下平台不能是空的。

三次检查所有响应类型的默认响应,并删除任何有空有效负载的内容。

票数 2
EN

Stack Overflow用户

发布于 2020-03-13 13:18:15

你的决议有点直观,也不完全正确。它不是一个具体的问题,一个空的有效载荷,问题仍然存在的有效载荷在一般情况下。

您可以尝试手动设置平台,比如=> How to set a custom platform in Dialogflow NodeJS Client

或选择此处描述的方法之一=> https://github.com/dialogflow/dialogflow-fulfillment-nodejs/issues/153

在初始化WebHookClient之前设置平台

代码语言:javascript
复制
if (!request.body.queryResult.fulfillmentMessages)
    return;
request.body.queryResult.fulfillmentMessages = request.body.queryResult.fulfillmentMessages.map(m => {
    if (!m.platform)
        m.platform = 'PLATFORM_UNSPECIFIED';
    return m;
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54137145

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档