@@ -384,14 +384,18 @@ def bot_commands_from_command_string(self, tokens: List[str], message: Message,
384384
385385 # entity detection
386386 if entity_map and token in entity_map :
387- # symphony and slack handle tagging opposite
388- if message .backend == "symphony" :
389- name , id = entity_map [token ]
390- elif message .backend == "slack" :
391- id , name = entity_map [token ]
392- elif message .backend == "discord" :
393- name , id = entity_map [token ]
394- target_tags .append (User (name = name , id = id , backend = message .backend ))
387+ # entity_map stores (entity_text, tag_value) where:
388+ # - For Slack: entity_text is "@USER_ID", tag_value is display name
389+ # - For Symphony/Discord: entity_text is "@DisplayName", tag_value is user ID
390+ entity_text , tag_value = entity_map [token ]
391+ if message .backend == "slack" :
392+ # For Slack: entity_text has the user ID (with @ prefix), tag_value is display name
393+ # Strip @ from entity_text to get clean user ID matching source.id format
394+ user_id = entity_text [1 :] if entity_text .startswith ("@" ) else entity_text
395+ target_tags .append (User (name = tag_value , id = user_id , backend = message .backend ))
396+ else :
397+ # Symphony/Discord: entity_text is display name, tag_value is user ID
398+ target_tags .append (User (name = entity_text , id = tag_value , backend = message .backend ))
395399 continue
396400
397401 command_args .append (token )
@@ -427,6 +431,7 @@ def extract_bot_commands(self, message: Message, channel: str, text: str, entiti
427431 if message .backend == "symphony" :
428432 text = text .replace (entity , entity_placeholder , 1 )
429433 elif message .backend == "slack" :
434+ # NOTE: don't replace the @ in front of entity, to match other frameworks
430435 text = text .replace (f"<{ entity } >" , entity_placeholder , 1 )
431436 elif message .backend == "discord" :
432437 text = text .replace (f"<{ entity } >" , entity_placeholder , 1 )
@@ -436,9 +441,19 @@ def extract_bot_commands(self, message: Message, channel: str, text: str, entiti
436441
437442 tokens = next (reader (StringIO (text ), delimiter = " " , quotechar = '"' , skipinitialspace = True ))
438443
439- if tokens [0 ] in entity_map and entity_map [tokens [0 ]][0 ] == f"@{ self ._get_bot_tag (message .backend )} " :
440- # remove initial bot directive
441- tokens = tokens [1 :]
444+ # Check if the first token is the bot being tagged - if so, remove it
445+ if tokens [0 ] in entity_map :
446+ entity_text , tag_value = entity_map [tokens [0 ]]
447+ bot_tag = self ._get_bot_tag (message .backend )
448+ if message .backend == "slack" :
449+ # Slack: entity_text is "@USER_ID", strip @ and compare with bot_tag (user ID)
450+ entity_user_id = entity_text [1 :] if entity_text .startswith ("@" ) else entity_text
451+ if entity_user_id == bot_tag :
452+ tokens = tokens [1 :]
453+ else :
454+ # Symphony/Discord: entity_text contains @name
455+ if entity_text == f"@{ bot_tag } " :
456+ tokens = tokens [1 :]
442457
443458 ret = self .bot_commands_from_command_string (tokens , message , channel , entity_map )
444459 if not ret :
0 commit comments