fix(telegram): use word-boundary matching for bot mention detection (#12545)

This commit is contained in:
Tranquil-Flow
2026-04-20 01:35:21 +00:00
committed by Teknium
parent 5157f5427f
commit 1e18e0503f
2 changed files with 113 additions and 2 deletions

View File

@@ -2264,8 +2264,9 @@ class TelegramAdapter(BasePlatformAdapter):
yield getattr(message, "caption", None) or "", getattr(message, "caption_entities", None) or []
for source_text, entities in _iter_sources():
if bot_username and f"@{bot_username}" in source_text.lower():
return True
if bot_username:
if re.search(rf'(?<!\w)@{re.escape(bot_username)}(?!\w)', source_text, re.IGNORECASE):
return True
for entity in entities:
entity_type = str(getattr(entity, "type", "")).split(".")[-1].lower()
if entity_type == "mention" and bot_username: