【问题标题】:Unable to send custom payload via DialogFlow Fulfilment npm for Slack无法通过 DialogFlow Fulfillment npm 为 Slack 发送自定义有效负载
【发布时间】:2021-06-24 12:15:51
【问题描述】:

我无法将自定义负载从我的 SLACK 平台的 nodejs webhook 代码发送回 dialogflow。

const {WebhookClient, Payload, Platforms, Suggestion} = require('dialogflow-fulfillment');

let payloadObj = new Payload(Platforms.SLACK, questionStringToSend);
agent.add(payloadObj);

这里,questionStringToSend 是我要发送的 JSON 负载。

任何帮助将不胜感激。

我的 JSON 结构如下:

{
   "blocks":[
      {
         "type":"section",
         "text":{
            "type":"mrkdwn",
            "text":"How do you rate the company?"
         }
      },
      {
         "type":"actions",
         "elements":[
            {
               "type":"button",
               "text":{
                  "type":"plain_text",
                  "text":0
               },
               "value":0
            },
            {
               "type":"button",
               "text":{
                  "type":"plain_text",
                  "text":1
               },
               "value":1
            }
         ]
      }
   ]
}

【问题讨论】:

    标签: node.js dialogflow-es slack-api dialogflow-es-fulfillment slack-block-kit


    【解决方案1】:

    从 webhook 发送响应时,json 的格式非常重要Link

    自定义负载响应是一个具有特定结构的 json 文件,如果不遵循该结构,我们将无法获得预期的响应。

    所以json文件可以编辑如下:

    {
    "fulfillmentMessages": [
        
        {
            "payload": {
                "slack": {
                    "attachments": [
                    {"blocks":[
      {
         "type":"section",
         "text":{
            "type":"mrkdwn",
            "text":"How do you rate the company?"
         }
      },
        {
         "type":"actions",
         "elements":[
            {
               "type":"button",
               "text":{
                  "type":"plain_text",
                  "text":"0"
               },
               "value":"0",
               "action_id": "button"
            },
            {
               "type":"button",
               "text":{
                  "type":"plain_text",
                  "text":"1"
               },
               "value":"1"
            }
             ]
            }
           ]
          }
         ] 
        }
       } 
      }
    ]
    }
    

    【讨论】:

      【解决方案2】:

      试试这个

      {
          "blocks": [
              {
                  "type": "section",
                  "text": {
                      "type": "mrkdwn",
                      "text": "How do you rate the company?"
                  }
              },
              {
                  "type": "actions",
                  "elements": [
                      {
                          "type": "button",
                          "text": {
                              "type": "plain_text",
                              "text": "0"
                          },
                          "value": "0"
                      },
                      {
                          "type": "button",
                          "text": {
                              "type": "plain_text",
                              "text": "1"
                          },
                          "value": "1"
                      }
                  ]
              }
          ]
      }
      

      【讨论】:

      • 我仍然无法通过 dialogflow-fulfillment 将其作为自定义负载发送
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-06-10
      • 2020-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-06
      • 1970-01-01
      相关资源
      最近更新 更多