-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathapp.py
More file actions
43 lines (34 loc) · 1.24 KB
/
app.py
File metadata and controls
43 lines (34 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler
# This sample slack application uses SocketMode
# For the companion getting started setup guide,
# see: https://docs.slack.dev/tools/bolt-python/getting-started
# Initializes your app with your bot token
app = App(token=os.environ.get("SLACK_BOT_TOKEN"))
# Listens to incoming messages that contain "hello"
@app.message("hello")
def message_hello(message, say):
# say() sends a message to the channel where the event was triggered
say(
blocks=[
{
"type": "section",
"text": {"type": "mrkdwn", "text": f"Hey there <@{message['user']}>!"},
"accessory": {
"type": "button",
"text": {"type": "plain_text", "text": "Click Me"},
"action_id": "button_click",
},
}
],
text=f"Hey there <@{message['user']}>!",
)
@app.action("button_click")
def action_button_click(body, ack, say):
# Acknowledge the action
ack()
say(f"<@{body['user']['id']}> clicked the button")
# Start your app
if __name__ == "__main__":
SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"]).start()