-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistening.py
More file actions
39 lines (37 loc) · 1.03 KB
/
Copy pathlistening.py
File metadata and controls
39 lines (37 loc) · 1.03 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
from dotenv import load_dotenv
load_dotenv()
import json
from slack_bolt import App
from slack_bolt.adapter.flask import SlackRequestHandler
from flask import Flask, request
from answer import answer_question
with open("config.json", "r") as f:
response_channels = json.load(f)
import os
app = App(
token=os.environ.get("SLACK_BOT_TOKEN"),
signing_secret=os.environ.get("SLACK_SIGNING_SECRET")
)
flask_app = Flask(__name__)
handler = SlackRequestHandler(app)
@app.event("message")
def handle_message(event, say, client):
if event.get("bot_id"):
return
channel_id = event.get("channel")
if channel_id not in response_channels:
return
text = event.get("text", "")
user_id = event.get("user")
result = answer_question(text)
if result is None:
return
say(
text=result["answer"],
thread_ts=event.get("ts")
)
@flask_app.route("/slack/events", methods=["POST"])
def slack_events():
return handler.handle(request)
if __name__ == "__main__":
flask_app.run(port=3000)