-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
88 lines (75 loc) · 3.04 KB
/
app.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import os
from slack_bolt import App
#from slack_bolt.adapter.socket_mode import SocketModeHandler
import helpers
app = App(
token=os.environ.get("SLACK_BOT_TOKEN"), signing_secret=os.environ.get("SLACK_SIGNING_SECRET")
)
@app.message("Hi dc-bot!")
def message_hello(message, say, logger):
say(f"Hi <@{message['user']}>! My name is DC-bot.")
@app.event("message")
def default_message_response():
pass
@app.event("app_mention")
def respond_to_mention(body, say, logger):
message = body["event"]["text"].lower()
parts = message.split()
if len(parts) == 1:
say(f"Hi <@{body['event']['user']}>!")
elif parts[1] == "github":
if len(parts) > 2:
if parts[2] == "help":
say(
(
"Information about using Github is available on "
"<https://scilifelab.atlassian.net/wiki/spaces/DC/pages/2198339588/Using+Github|Confluence>"
)
)
elif parts[2] == "org":
say(
"Data Centre has an organisation on <https://github.com/ScilifelabDataCentre|Github>"
)
elif parts[1] == "menu":
if len(parts) > 2:
restaurant_info = helpers.get_menu(parts[2])
if restaurant_info:
if restaurant_info["menu"]:
blocks = [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": f"Today at *{restaurant_info['name']}*",
},
}
]
for entry in restaurant_info["menu"]:
blocks.append(
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": entry,
},
}
)
say(blocks=blocks, text=f"Today at *{restaurant_info['name']}*")
else:
say(f"Unable to retrieve the menu for *{restaurant_info['name']}*")
else:
say("Unable to retrieve the menu")
else:
pass # should probably list the choices here as a silent message
@app.event("member_joined_channel")
def respond_to_channel_join(body, say, logger):
"""Greetings when people join channels."""
say(f"Check if userid: <@{body['event']['user']}>")
if body["event"]["channel"] == "GQY2NLTPA":
say(f"Welcome <@{body['event']['user']}> to the Data Centre Development Team!")
elif body["event"]["channel"] == "GADPJCJRW":
say(f"Welcome <@{body['event']['user']}> to SciLifeLab Data Centre!")
# Start your app
if __name__ == "__main__":
app.start(port=int(os.environ.get("PORT", 3000)))
# SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"]).start()