DialogFlow:通过 Fulfillment 通过 Firebase(内联)云功能将附件发布到 Facebook

DialogFlow: Posting attchment to Facebook via Fullfillment via Firebase (inline) Cloud functions

我正在为我的 Facebook 页面设置聊天机器人,使用 Google Dialogflow 处理对话。

对于特定的 Intent,我需要发送 2 个响应。

  1. 包含用户名的常规语句。
  2. 具有 3 个按钮的永久菜单

我了解,对于单个 Intent,我无法通过 Fulfillment 代码发送第一个响应,也无法通过 Dialogflow 控制台发送第二个响应设置 UI。因此,我需要编写代码来发送这两个响应。

我可以发送第一个回复。但无法发送 Rich 消息内容。 DialogFlow文档显示了代码片段,但不清楚不同页面的代码片段如何适合它。

这是我的代码(只是发布 actionHandlers),试图发送一个语句和一个音频 (https://dialogflow.com/docs/rich-messages#custom_payload)

const actionHandlers = {
    'input.welcome': () => {

        const speechText = 'Hi ' + userProfile['first_name'] + ', This is Eva, digital assistant of LMES Academy. Since my people are busy working on the content for the next video, I\'d like to help you with your needs ';
        const responsePayload = {
            'speech': speechText,
            'outputContexts': [{
                'user-name': userProfile.first_name 
            }],
            "data": {
                "facebook": {
                    "attachment": {
                        "type": "audio",
                        "payload": {
                            "url": "http://incompetech.com/music/royalty-free/mp3-royaltyfree/Funk%20Game%20Loop.mp3"
                        }
                    }
                }
            }
        };

        sendResponse(responsePayload);
    },

    // The default fallback intent has been matched, try to recover (https://dialogflow.com/docs/intents#fallback_intents)
    'input.unknown': () => {
        sendResponse('I\'m having trouble, can you try that again?'); // Send simple response to user
    }

};

文本响应有效,但 Audio 无效。我做的对吗?任何帮助表示赞赏。

更新 1: 更改 mp3 link 后音频正常工作。但是文本响应不起作用。

在我的云功能中发送到 response.json() 的对象的日志。

{
    "speech": "Hi Saiyasodharan, This is Eva, digital assistant of LMES Academy. Since my people are busy working on the content for the next video, I'd like to help you with your needs ",
    "displayText": "Hi Saiyasodharan, This is Eva, digital assistant of LMES Academy. Since my people are busy working on the content for the next video, I'd like to help you with your needs ",
    "data": {
        "facebook": {
            "attachment": {
                "type": "audio",
                "payload": {
                    "url": "http://66.90.93.122/ost/death-note-original-soundtrack/bowkqzxs/01%20Death%20note.mp3"
                }
            }
        }
    },
    "contextOut": [{
        "user-name": "Saiyasodharan"
    }]
}

在上面的代码中,我期望

我认为我需要通过 data 属性 提供文本回复和音频回复。让我在这里尝试更新。

如果您对给定集成使用负载,则响应文本将被忽略。您需要将具有属性 text 的消息添加到 facebook 负载,以便它显示在 Facebook Messenger 中。例如:

{
  "contextOut": [
    {
      "user-name": "Saiyasodharan"
    }
  ],
  "data": {
    "facebook": {
      "attachment": {
        "payload": {
          "url": "http://66.90.93.122/ost/death-note-original-soundtrack/bowkqzxs/01%20Death%20note.mp3"
        },
        "type": "audio"
      },
      "text": "Hi Saiyasodharan, This is Eva, digital assistant of LMES Academy. Since my people are busy working on the content for the next video, I'd like to help you with your needs "
    }
  },
  "displayText": "Hi Saiyasodharan, This is Eva, digital assistant of LMES Academy. Since my people are busy working on the content for the next video, I'd like to help you with your needs ",
  "speech": "Hi Saiyasodharan, This is Eva, digital assistant of LMES Academy. Since my people are busy working on the content for the next video, I'd like to help you with your needs "
}