Skip to content

Commit 1b4d903

Browse files
committed
Add slash prompt command and remove app_mention
1 parent 0924d12 commit 1b4d903

File tree

1 file changed

+17
-32
lines changed

1 file changed

+17
-32
lines changed

app/main.py

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,6 @@
1414
client = WebClient(token=slack_token)
1515
verifier = SignatureVerifier(signing_secret)
1616

17-
18-
@app.route("/slack/events", methods=["POST"])
19-
def slack_events():
20-
if not verifier.is_valid_request(request.get_data(), request.headers):
21-
return "Request verification failed", 403
22-
23-
event_data = request.json
24-
25-
if "challenge" in event_data:
26-
return jsonify({"challenge": event_data["challenge"]})
27-
28-
if "event" in event_data:
29-
event = event_data["event"]
30-
31-
if event.get("type") == "app_mention":
32-
user = event["user"]
33-
text = event["text"]
34-
channel = event["channel"]
35-
36-
# Change this to your RAG model's response function
37-
# This is where you would call your RAG model
38-
# For example, if you have a function `get_rag_response`:
39-
response_text = get_rag_response(text)
40-
41-
# Respond to Slack
42-
client.chat_postMessage(
43-
channel=channel,
44-
text=f"<@{user}> {response_text}"
45-
)
46-
47-
return "OK", 200
48-
4917
@app.route("/slack/commands", methods=["POST"])
5018
def slack_commands():
5119
data = request.form
@@ -57,5 +25,22 @@ def slack_commands():
5725
})
5826
return "Unknown command", 200
5927

28+
@app.route("/slack/prompt", methods=["POST"])
29+
def slack_prompt():
30+
data = request.form
31+
user_id = data.get("user_id")
32+
query = data.get("text") # This is the user's prompt message
33+
34+
# Change this to your RAG model's response function
35+
# This is where you would call your RAG model
36+
# For example, if you have a function `get_rag_response`:
37+
response = get_rag_response(query)
38+
39+
# Respond back publicly in the slack channel or privately to the user
40+
return jsonify({
41+
"response_type": "in_channel", # or "ephemeral" for private replies
42+
"text": f"<@{user_id}> {response}"
43+
})
44+
6045
if __name__ == "__main__":
6146
app.run(debug=True,port=3000)

0 commit comments

Comments
 (0)