@@ -289,7 +289,7 @@ async def _is_bot_in_thread(self, channel: str, thread_ts: str) -> bool:
289289 thread_ts: Thread timestamp
290290
291291 Returns:
292- True if bot has sent messages in the thread, False otherwise
292+ True if bot has sent messages or been mentioned in the thread, False otherwise
293293 """
294294 try :
295295 # Get bot's user ID
@@ -310,17 +310,28 @@ async def _is_bot_in_thread(self, channel: str, thread_ts: str) -> bool:
310310 messages = result .get ("messages" , [])
311311 logger .debug (f"Found { len (messages )} messages in thread { thread_ts } " )
312312
313- # Check if any message is from the bot
313+ # Bot mention pattern: <@USER_ID>
314+ bot_mention = f"<@{ bot_user_id } >"
315+
316+ # Check if any message is from the bot or mentions the bot
314317 for msg in messages :
315318 msg_user = msg .get ("user" )
316319 msg_bot_id = msg .get ("bot_id" )
320+ msg_text = msg .get ("text" , "" )
321+
317322 logger .debug (f"Message from user={ msg_user } , bot_id={ msg_bot_id } " )
318323
324+ # Check if message is from the bot
319325 if msg_user == bot_user_id or msg_bot_id :
320326 logger .debug (f"Found bot message in thread" )
321327 return True
322328
323- logger .debug (f"No bot messages found in thread" )
329+ # Check if message mentions the bot
330+ if bot_mention in msg_text :
331+ logger .debug (f"Found bot mention in thread" )
332+ return True
333+
334+ logger .debug (f"No bot messages or mentions found in thread" )
324335 return False
325336
326337 except Exception as e :
0 commit comments