33Handles conversation memory, Bedrock queries, and responding back to Slack
44"""
55
6+ import json
67import re
78import time
89import traceback
9- import json
10- from typing import Any , Dict
10+ from typing import Any , dict
11+
1112from botocore .exceptions import ClientError
1213from slack_sdk import WebClient
14+
1315from app .core .config import (
1416 bot_messages ,
1517 constants ,
4345
4446
4547def cleanup_previous_unfeedback_qa (
46- conversation_key : str , current_message_ts : str , session_data : Dict [str , Any ]
48+ conversation_key : str , current_message_ts : str , session_data : dict [str , Any ]
4749) -> None :
4850 """Delete previous Q&A pair if no feedback received using atomic operation"""
4951 try :
@@ -112,9 +114,9 @@ def _mark_qa_feedback_received(conversation_key: str, message_ts: str) -> None:
112114
113115def _handle_session_management (
114116 conversation_key : str ,
115- session_data : Dict [str , Any ],
117+ session_data : dict [str , Any ],
116118 session_id : str ,
117- kb_response : Dict [str , Any ],
119+ kb_response : dict [str , Any ],
118120 user_id : str ,
119121 channel : str ,
120122 thread_ts : str ,
@@ -184,7 +186,7 @@ def process_feedback_event(
184186 channel_id : str ,
185187 thread_root : str ,
186188 client : WebClient ,
187- event : Dict [str , Any ],
189+ event : dict [str , Any ],
188190) -> None :
189191 feedback_text = message_text .split (":" , 1 )[1 ].strip () if ":" in message_text else ""
190192 try :
@@ -208,7 +210,7 @@ def process_feedback_event(
208210 post_error_message (channel = channel_id , thread_ts = thread_ts , client = client )
209211
210212
211- def process_async_slack_action (body : Dict [str , Any ], client : WebClient ) -> None :
213+ def process_async_slack_action (body : dict [str , Any ], client : WebClient ) -> None :
212214 try :
213215 channel_id = body ["channel" ]["id" ]
214216 action_id = body ["actions" ][0 ]["action_id" ]
@@ -261,7 +263,7 @@ def process_async_slack_action(body: Dict[str, Any], client: WebClient) -> None:
261263 logger .error (f"Error handling feedback: { e } " , extra = {"error" : traceback .format_exc ()})
262264
263265
264- def process_async_slack_event (event : Dict [str , Any ], event_id : str , client : WebClient ) -> None :
266+ def process_async_slack_event (event : dict [str , Any ], event_id : str , client : WebClient ) -> None :
265267 logger .debug ("Processing async Slack event" , extra = {"event_id" : event_id , "event" : event })
266268 original_message_text = (event .get ("text" ) or "" ).strip ()
267269 message_text = strip_mentions (message_text = original_message_text )
@@ -293,7 +295,7 @@ def process_async_slack_event(event: Dict[str, Any], event_id: str, client: WebC
293295 process_slack_message (event = event , event_id = event_id , client = client )
294296
295297
296- def process_slack_message (event : Dict [str , Any ], event_id : str , client : WebClient ) -> None :
298+ def process_slack_message (event : dict [str , Any ], event_id : str , client : WebClient ) -> None :
297299 """
298300 Process Slack events asynchronously after initial acknowledgment
299301
@@ -369,7 +371,7 @@ def process_slack_message(event: Dict[str, Any], event_id: str, client: WebClien
369371 post_error_message (channel = channel , thread_ts = thread_ts , client = client )
370372
371373
372- def process_pull_request_slack_event (slack_event_data : Dict [str , Any ]) -> None :
374+ def process_pull_request_slack_event (slack_event_data : dict [str , Any ]) -> None :
373375 # separate function to process pull requests so that we can ensure we store session information
374376 try :
375377 event_id = slack_event_data ["event_id" ]
@@ -384,7 +386,7 @@ def process_pull_request_slack_event(slack_event_data: Dict[str, Any]) -> None:
384386 logger .error ("Error processing message" , extra = {"event_id" : event_id , "error" : traceback .format_exc ()})
385387
386388
387- def process_pull_request_slack_action (slack_body_data : Dict [str , Any ]) -> None :
389+ def process_pull_request_slack_action (slack_body_data : dict [str , Any ]) -> None :
388390 # separate function to process pull requests so that we can ensure we store session information
389391 try :
390392 token = get_bot_token ()
@@ -395,7 +397,7 @@ def process_pull_request_slack_action(slack_body_data: Dict[str, Any]) -> None:
395397 logger .error ("Error processing message" , extra = {"error" : traceback .format_exc ()})
396398
397399
398- def log_query_stats (user_query : str , event : Dict [str , Any ], channel : str , client : WebClient , thread_ts : str ) -> None :
400+ def log_query_stats (user_query : str , event : dict [str , Any ], channel : str , client : WebClient , thread_ts : str ) -> None :
399401 query_length = len (user_query )
400402 start_time = float (event ["event_ts" ])
401403 end_time = time .time ()
@@ -520,7 +522,7 @@ def get_conversation_session(conversation_key: str) -> str | None:
520522 return session_data .get ("session_id" ) if session_data else None
521523
522524
523- def get_conversation_session_data (conversation_key : str ) -> Dict [str , Any ]:
525+ def get_conversation_session_data (conversation_key : str ) -> dict [str , Any ]:
524526 """
525527 Get full session data for this conversation
526528 """
0 commit comments