简体   繁体   中英

Processing Post Request from Slack

I've setup an asp.net MVC web application to capture post request. I've set breakpoints to see what info is coming through. When an interactive button is clicked, my breakpoint is hit but the object has no details. It simply says {Object} when i hover over value . When I use Postman and send a raw JSON body, it displays the JSON. May I ask how am i suppose to process the slack object that is sent?

public void Post(object value)
{
    // breakpoint here
}

For interactive messages Slack send a standard POST request with a single form-data encoded parameter called payload in the body. This parameter contains the data of the actual request as JSON string.

You can simulate this with Postman by using the following parameters:

  • Request type: POST
  • Header: Content-Type: application/x-www-form-urlencoded
  • Body: form-data , with key = payload and value = JSON string.

So the body is not fully JSON as you assumed, but contains a form parameter with a JSON encoded string. If you change your app accordingly, it will work.

In c# you can access the content of the payload parameter with Request["payload"] (see this answer or details).

Then you still need to decode the JSON string into an object of course. An easy approach is to use JavaScriptSerializer.Deserialize . (see this answer for details and alternative approaches).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM