错误:Dialogflow中新的有效载荷平台不能为空

时间:2019-01-10 21:27:11

标签: node.js dialogflow

我有一个无服务器应用程序,我想在其中运行来自Facebook Messenger的chatbot请求中的逻辑。当我为 test_handler 运行intent函数时,我会得到正确的响应。但是在为 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);

Dialogflow图片:

Training Phrases enter image description here enter image description here enter image description here

我正在尝试在Messenger上运行代码。任何帮助将不胜感激,因为我一直努力设法解决这个问题。

2 个答案:

答案 0 :(得分:1)

事实证明,在下图中,自定义有效载荷导致了我遇到的问题。如果您遇到相同的错误

  

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

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

enter image description here

答案 1 :(得分:0)

您的分辨率有些直觉,而且并不完全正确。有效负载为空并不是一个特别的问题,一般来说,有效负载仍然存在问题。

您可以尝试像这样手动设置平台=> How to set a custom platform in Dialogflow NodeJS Client

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

设置用于初始化WebHookClient的平台

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;
});