I am trying to create a Slack bot in Python. I want my bot to send a message with interactive buttons on it, and then based on which the user clicks, runs the function in Python. I don't seem to know how to do this.
Now my code is as follows:
message = "message"
attachments = [{"text": "message",
"attachment_type": "default",
"actions": [
{
"name": "list",
"text": "message",
"type": "select",
"options": [
{
"name": "1",
"text": "1",
"type": "button",
"value": "1"
},
{
"name": "1",
"text": "1",
"type": "button",
"value": "2"
}
]}]}]
sc.api_call("chat.postMessage",
channel=channel,
text=message,
attachments=attachments)
So this gives me a message with two buttons. However, I want to run a function based on the response that the user gives.
So say that if they press 1, function1 () starts, and when they press 2, function2 () starts.
The Slack api documentation is rather confusing on how to do this, and the “listener” they provide rtm_read () does not select the user clicking on one of the buttons.
, - , .