Skip to content

feat(telegram): add configurable regex wake-word gating for group text and media#3539

Open
mcleay wants to merge 1 commit intoNousResearch:mainfrom
mcleay:feat/telegram-group-invocation-gating-clean
Open

feat(telegram): add configurable regex wake-word gating for group text and media#3539
mcleay wants to merge 1 commit intoNousResearch:mainfrom
mcleay:feat/telegram-group-invocation-gating-clean

Conversation

@mcleay
Copy link
Copy Markdown
Contributor

@mcleay mcleay commented Mar 28, 2026

What does this PR do?

This PR adds Telegram-specific group invocation gating with configurable regex wake words.

The goal is to let Hermes ignore ambient group chatter while still responding to explicit Telegram group triggers. It adds Hermes-side gating for Telegram group messages and captions so the bot only responds when explicitly invoked.

Changes Made

  • Added Telegram config bridging in gateway/config.py for:
    • telegram.require_mention
    • telegram.mention_patterns
  • Added Telegram group invocation handling in gateway/platforms/telegram.py
  • Group messages are now processed when they:
    • match a configured regex wake word
    • reply to one of the bot’s messages
  • Strips the matched wake-word prefix from the beginning of the text/caption before dispatching to the model
  • Applies the same invocation gating to media/caption messages, not just plain text
  • Avoids mutating Telegram Message objects directly when cleaning invocation prefixes
  • Added focused Telegram gating tests in:
    • tests/gateway/test_telegram_group_gating.py

Example config

telegram:
  require_mention: true
  mention_patterns:
    - "^\\s*wakeword\\b"

With the example above:

  • wakeword hi in a group is processed
  • a plain uninvoked group message is ignored
  • an image with caption wakeword what is this is processed
  • a plain image with no caption is ignored
  • replies to the bot are processed

How to Test

Run:

  • pytest -q tests/gateway/test_telegram_group_gating.py tests/gateway/test_telegram_text_batching.py

Then verify in a Telegram group where the bot receives group messages:

  • plain text with no invocation is ignored
  • wakeword hi is processed
  • reply-to-bot is processed
  • plain image with no caption is ignored
  • image with a wake-word caption is processed

Notes

  • This is Telegram-specific behavior and does not change Discord or other platform adapters.
  • The tests use generic placeholder names/patterns rather than user-specific wake words.

Checklist

  • Code changes tested
  • Group text invocation gating works
  • Group media invocation gating works
  • No private/local config included
  • No user-specific bot names or wake words used in tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant