0

我无法将自定义有效负载从我的 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
            }
         ]
      }
   ]
}
4

2 回答 2

3

从 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"
        }
         ]
        }
       ]
      }
     ] 
    }
   } 
  }
]
}
于 2021-06-29T03:59:34.373 回答
0

尝试这个

{
    "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"
                }
            ]
        }
    ]
}
于 2021-06-24T17:12:28.513 回答