富消息在内部测试器中显示,为什么不能在Messenger中显示?

Igg*_*ass 9 javascript rich-media dialogflow-es-fulfillment

我有一个 Dialogflow 聊天机器人。在 Dialogflow 内部测试器中一切正常,但在 facebook 上显示的版本中,我无法获得卡片或建议。即使我用另一个工作聊天机器人的代码替换它们。

const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion, Payload} = require('dialogflow-fulfillment');
var answers = [];

process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const agent = new WebhookClient({ request, response });

  function welcome(agent) {
    agent.add('Hi! Do you want to discover your lockdown personality?');
    agent.add(new Card({
        title: '1. How has the COVID-19 crisis',
        imageUrl: 'https://ejoy-english.com/blog/wp-content/uploads/2018/08/shutterstock_524250877-e1496428580440.jpg',
        text: 'impacted the stability of your life?',
      })
    );
    agent.add(new Suggestion("1 more exasperated and hopeless"));
    agent.add(new Suggestion("2 less freaked out than other people"));
    agent.add(new Suggestion("3 More calm and hopeful"));
    agent.add(new Suggestion("4 More scared and panicked"));
    agent.add(new Suggestion("5 More surprised and baffled"));
  }
  let intentMap = new Map();
  intentMap.set('Default Welcome Intent', welcome);


  agent.handleRequest(intentMap);
});
Run Code Online (Sandbox Code Playgroud)

这是我在 Facebook 上得到的信息:

图像描述简介

在 Dialogflow 的内部测试器中:

图像描述简介

它在 Slack 上运行良好,我设法做另一个聊天机器人,它也使用富消息而不使用 JSON 有效负载,并且它在 Messenger 上运行良好。我不知道为什么不能在带有此特定聊天机器人的 Messenger 中显示富消息。

Bep*_*e C 0

DialogFlow 内置测试器是验证对话流和测试意图识别的好方法,但是关于响应的呈现(从快速回复到附件),您需要考虑 Facebook 有不同的呈现引擎(对于其他引擎也是如此)频道),因此某些类型不能很好地发挥作用,而且它们也不是绝对标准化的。

我相信这种情况下的解决方案会提供自定义 Facebook 有效负载,这正是 Messenger 平台所期望的。

以按钮为例:

 {
  "facebook": {
    "attachment": {
      "type": "template",
      "payload": {
        "template_type": "button",
        "text": "Can I ask you a few questions?",
        "buttons": [
          {
            "title": "Yes",
            "payload": "Yes",
            "type": "postback"
          },
          {
            "payload": "No",
            "title": "No",
            "type": "postback"
          }
        ]
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

当您使用 DialogFlow Fulfillment 库时,您需要查看Payload对象。

agent.add(new Payload(agent.FACEBOOK, {/*your custom payload here*/});
Run Code Online (Sandbox Code Playgroud)