forked from jacklowrie/piazza-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
30 lines (23 loc) · 884 Bytes
/
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
import os
from dotenv import load_dotenv
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler
import re
# Make the app
load_dotenv()
app = App(token=os.environ.get("SLACK_BOT_TOKEN"))
base_url = "https://piazza.com/class/%s" % os.environ.get("COURSE_ID")
posts_url = f"{base_url}/post/"
# Listens to incoming messages that contain "hello"
# To learn available listener arguments, visit
# https://slack.dev/bolt-python/api-docs/slack_bolt/kwargs_injection/args.html
@app.message(re.compile("(@\d\d*)"))
def post_link(say, context):
for match in context['matches']:
number = match.replace('@','')
url = posts_url + number
# say() sends a message to the channel where the event was triggered
say(url)
# Run the app
if __name__ == "__main__":
SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"]).start()