【问题标题】:Error: Platform can NOT be empty at new Payload in Dialogflow错误:在 Dialogflow 中的新有效负载处平台不能为空
【发布时间】: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 中 skillRatio Intent 屏幕的屏幕截图更新您的问题?我还看到您正在专门测试agent.FACEBOOK。如果您取消注释 intentMap.set() 的技能比率并删除此 if 块会发生什么?
  • 囚徒,我当然可以,裸露在外。你只是想看短语吗?也感谢一百万的快速回复!我尝试测试 agent.FACEBOOK,因为我觉得它专门寻找平台。但我可以在 AWS CloudWatch 中看到 Facebook 已经设置好了。当我取消注释技能比率映射时,什么也没有发生。尝试调用它时,我的日志中出现错误。
  • 查看整个 Intent 的所有部分可以帮助您了解问题是否出在短语之外 - 所以请尽可能包含所有内容。
  • 我真的对自己很生气。事实证明,Dialogflow 图像上的默认有效负载导致了该问题。两次我以为我可以删除它,但认为它太小了,不能成为问题。删除自定义有效负载后,代码现在可以正常工作。很抱歉造成混乱,但也许这可能会在未来对其他人有所帮助。感谢您的帮助!
  • (但这就是我要求发布所有内容的原因。{:)

标签: node.js dialogflow-es


【解决方案1】:

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

错误:在新的 Payload 处平台不能为空。

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

【讨论】:

    【解决方案2】:

    您的分辨率有点直观,并不完全正确。这不是一个空有效负载的具体问题,一般来说,如果有一个有效负载,问题仍然存在。

    您可以尝试像这样手动设置平台 => 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;
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-17
      • 1970-01-01
      • 1970-01-01
      • 2012-10-30
      相关资源
      最近更新 更多