The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(telegram): uncaptioned voice notes and audio files keep the silence notice in groups
kshitijk4poor5bb0e7d87d46
diff --git a/plugins/platforms/telegram/telegram_context.py b/plugins/platforms/telegram/telegram_context.pyindex 9bdb767976f..339b63c8148 100644--- a/plugins/platforms/telegram/telegram_context.py+++ b/plugins/platforms/telegram/telegram_context.py@@ -74,7 +74,9 @@ def group_reply_expected(adapter: "TelegramAdapter", message: "Message", chat_tyreturn Noneif _replies_to_other_member(adapter, message) or starts_with_other_participant_mention(adapter, message):return False- return None if "?" in text else False+ # Words in a voice note or audio file are not in the message text, so the "?" rule cannot read them.+ spoken = not text and any(getattr(message, kind, None) for kind in ("voice", "audio"))+ return None if "?" in text or spoken else Falsedef group_trigger_text(adapter: "TelegramAdapter", message: "Message", text: Optional[str]) -> Optional[str]:diff --git a/tests/gateway/test_telegram_group_gating.py b/tests/gateway/test_telegram_group_gating.pyindex 0565bc07984..3f3e7cdc1e7 100644--- a/tests/gateway/test_telegram_group_gating.py+++ b/tests/gateway/test_telegram_group_gating.py@@ -1021,6 +1021,11 @@ def _replying_to(message, *, user_id=None, message_id=10):return message+def _with_media(message, kind):+ setattr(message, kind, SimpleNamespace(file_id="f"))+ return message++@pytest.mark.parametrize("message, expected", [(_group_message("@hermes_bot when is rent due?", entities=[_mention_entity("@hermes_bot when is rent due?")]), True),(_group_message("sure, saturday", reply_to_bot=True), True),@@ -1035,10 +1040,15 @@ def _replying_to(message, *, user_id=None, message_id=10):(_group_message("what did @alice say?", entities=[_mention_entity("what did @alice say?", "@alice")]), None),(_replying_to(_group_message("anyone up for dinner?", thread_id=5), user_id=222, message_id=5), None),(_replying_to(_group_message("agreed?")), None),+ (_with_media(_group_message(None), "voice"), None),+ (_with_media(_group_message(None), "audio"), None),+ (_with_media(_group_message(None, caption="the fridge arrives on saturday"), "voice"), False),+ (_with_media(_group_message(None), "photo"), False),], ids=["mention", "reply-to-bot", "wake-word", "caption-command", "indented-command", "dm","reply-to-other-member", "opens-with-other-mention", "chatter","question", "mentions-other-mid-question", "forum-topic-root", "reply-to-unknown-author",+ "voice-note", "audio-file", "captioned-voice-chatter", "photo-without-caption",])def test_reply_expected_follows_who_the_group_message_addresses(message, expected):adapter = _make_adapter(require_mention=False, mention_patterns=["hermes"])diff --git a/website/docs/user-guide/messaging/telegram.md b/website/docs/user-guide/messaging/telegram.mdindex 1a171e9487c..3c70a7f1054 100644--- a/website/docs/user-guide/messaging/telegram.md+++ b/website/docs/user-guide/messaging/telegram.md@@ -656,7 +656,7 @@ A bot that reads every group message can answer exactly `[SILENT]` (or another [| Any other message without a `?` | Stays silent || Any other message with a `?` (it may be a question for the bot) | Replaced by the notice |-A message still gets the notice while the bot's own identity is unknown, or when it replies to a message whose author is unknown. A forum topic's root message is not a reply to another member.+A message still gets the notice while the bot's own identity is unknown, or when it replies to a message whose author is unknown. A voice note or audio file without a caption also gets the notice, because its words are not in the message text. A forum topic's root message is not a reply to another member.### Multiple Hermes bots in one group