Noobie
Noobie

Reputation: 31

how to get actions result from slack api's attachment

How to receive attachment actions using python SlackClient. How to get user's reply?

enter image description here

Code :

intro_msg = json.dumps([{"text": "Choose an action", "fallback": "You are unable to choose an option",
                                     "callback_id": "lunch_intro", "color": "#3AA3E3", "attachment_type": "default",
                                     "actions": [
                                         {"name": "enroll", "text": "Enroll", "type": "button", "value": "enroll"},
                                         {"name": "leave", "text": "Leave", "type": "button", "value": "leave"}]}])
result = self.sc.api_call("chat.postMessage", channel=channel, text="What would you like to do?",attachments=intro_msg,as_user=True)

https://api.slack.com/interactive-messages

Upvotes: 1

Views: 352

Answers (1)

Erik Kalkoken
Erik Kalkoken

Reputation: 32757

  1. Define a Slack app
  2. Your app (Python script) needs to run on a public webserver that can be reached by Slack (can also by your local machine if you use tools like ngrok)
  3. Put the URL for your app as "request URL" in your Slack app configuration under "Interactive messages"
  4. Once the user clicks one of the button, Slack will call your app with a POST request which will contain the action that the use chose

Check out the documentation you linked for details like how the data structure of the Slack request looks like.

Upvotes: 1

Related Questions