0

I am unable to send a custom payload back to dialogflow from my nodejs webhook code for SLACK platform.

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

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

Here, questionStringToSend is the JSON payload that i want to send.

Any help would be appreciated.

Structure of my JSON is below:

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

2 Answers2

2

While sending a response from webhook the format of json is very important Link.

Custom payload response is a json file which has a specific structure and if the structure isn't followed we won't get the expected response.

So the json file can be edited as follows:

{
"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"
        }
         ]
        }
       ]
      }
     ] 
    }
   } 
  }
]
}
Sakshi Gatyan
  • 1,903
  • 7
  • 13
0

try this

{
    "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"
                }
            ]
        }
    ]
}
kendomen
  • 770
  • 6
  • 13