10

我有一个 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);
});

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

水图像介绍

在 Dialogflow 的内部测试器中:

水图像介绍

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

4

2 回答 2

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"
          }
        ]
      }
    }
  }
}

当您使用 DialogFlow Fulfillment 库时,您希望查看Payload对象。

agent.add(new Payload(agent.FACEBOOK, {/*your custom payload here*/});
于 2020-05-27T21:54:01.023 回答
0

我注意到我的 Dialogflow 实现 webhook 服务的 HTTP 响应有些奇怪:当我使用嵌入在我的网页上的Dialogflow Messenger 客户端时,收到的 JSON 有效负载在 JSON 的开头注入了 4 个不需要的字符。但是,当我在 Dialogflow 代理控制台中使用“立即尝试”测试器时,这些字符不会出现在 JSON 响应负载中。

这些额外的字符可能会导致 JSON 无效,从而破坏消息客户端中卡片的呈现和快速回复。这是导致呈现问题的 Dialogflow Messenger 中的错误吗?

)]}' <---What are these???
{
  "responseId": "xxxxx",
  "queryResult": {
    "queryText": "baby shower",
    "parameters": {
      "occassionType": "baby shower"
    },
    "allRequiredParamsPresent": true,
    "fulfillmentText": "Ok, you are looking for your baby shower",
    "fulfillmentMessages": [{
      "text": {
        "text": ["Ok, you are looking for your baby shower"]
      }
    }, {
      "payload": {
        "queryResult": {
          "action": "input.welcome",
          "allRequiredParamsPresent": true,
          "diagnosticInfo": {
            "webhook_latency_ms": 191.0
          },
          "fulfillmentMessages": [{
            "text": {
              "text": ["Hi! My name is Buffie. XXXXXXX"]
            }
          }, {
            "card": {
              "buttons": [{
                "postback": "https://somewhere.com",
                "text": "Button"
              }],
              "imageUri": "https://www.gstatic.com/webp/gallery/4.jpg",
              "subtitle": "This is some example text...",
              "title": "Card Title"
            }
          }],
          "fulfillmentText": "Hi! My name is Buffie, how can I help you",
          "intent": {
            "displayName": "Default Welcome Intent",
            "name": "projects/xxxxx/xxxxx"
          },
          "intentDetectionConfidence": 1.0,
          "languageCode": "en",
          "parameters": {
          },
          "queryText": "hi"
        },
        "responseId": "XXXXXXXX",
        "webhookStatus": {
          "message": "Webhook execution successful"
        }
      }
    }],
    "intent": {
      "name": "projects/xxxxx/xxxx/xxxx",
      "displayName": "Occassion"
    },
    "intentDetectionConfidence": 1.0,
    "languageCode": "en"
  }
}

于 2020-06-29T12:17:15.390 回答