1414client = WebClient (token = slack_token )
1515verifier = 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" ])
5018def 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+
6045if __name__ == "__main__" :
6146 app .run (debug = True ,port = 3000 )
0 commit comments