forked from insightbuilder/python_de_learners_data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
55 lines (41 loc) · 1.65 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
import logging
from slack_bolt import App
from slack_sdk.web import WebClient
from chat import OnboardingTutorial
import ssl as ssl_lib
import os
app = App()
onboarding_tutorial_sent = {}
def start_onboarding(user_id: str, channel: str, client: WebClient):
# Create a new onboarding tutorial.
onboarding_tutorial = OnboardingTutorial(channel)
# Get the onboarding message payload
message = onboarding_tutorial.get_message_payload()
# Post the onboarding message in Slack
response = client.chat_postMessage(**message)
# Capture the timestamp of the message we've just posted so
# we can use it to update the message after a user
# has completed an onboarding task.
onboarding_tutorial.timestamp = response["ts"]
# Store the message sent in onboarding_tutorials_sent
if channel not in onboarding_tutorials_sent:
onboarding_tutorials_sent[channel] = {}
onboarding_tutorials_sent[channel][user_id] = onboarding_tutorial
# ============== Message Events ============= #
# When a user sends a DM, the event type will be 'message'.
# Here we'll link the message callback to the 'message' event.
@app.event("message")
def message(event, client):
"""Display the onboarding welcome message after receiving a message
that contains "start".
"""
channel_id = event.get("channel")
user_id = event.get("user")
text = event.get("text")
if text and text.lower() == "start":
return start_onboarding(user_id, channel_id, client)
if __name__ == "__main__":
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
app.start(3000)