Search code examples
pythonslack-apislack

How to access Slack's Interactive Message request payload parameter?


I would like to access the payload parameter sent by Slack to Interactive Message Request Url when a user clicks on a button in one of these messages.

How do I do this?


Solution

  • On your server side, check your request url route is allowed to receive POST. As said in theirs docs (https://api.slack.com/docs/message-buttons) :

    Your Action URL will receive a HTTP POST request, including a payload body parameter, itself containing an application/x-www-form-urlencoded JSON string.

    You first have to decode the x-www-form-urlencoded format of the request, then json decode it.

    In python, I end up with this line of code :

    payload = json.loads(urlparse.parse_qs(request.get_data())['payload'][0])
    

    Hope it helps someone else one day !