-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbot.py
More file actions
41 lines (34 loc) · 1.88 KB
/
bot.py
File metadata and controls
41 lines (34 loc) · 1.88 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
import os
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler
# Initializes your app with your bot token and socket mode handler
app = App(token="xoxb-")
@app.event("app_mention")
def mention_handler(body, say):
say('Hello World! ......')
# 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, "xapp-").start()