Skip to content

feat(telegram): transcribe replied-to voice messages as context - #18887

Closed
kaizen403 wants to merge 2 commits into
NousResearch:mainfrom
kaizen403:feat/replied-voice-stt-context
Closed

kaizen403 wants to merge 2 commits into
NousResearch:mainfrom
kaizen403:feat/replied-voice-stt-context

Conversation

@kaizen403

Copy link
Copy Markdown

Problem

When require_mention=true is set for a Telegram group, users cannot use voice messages to give commands to bots. If they send a voice note and then reply to it with @BotName do this, the bot sees the @mention but has no visibility into the voice message content — it can't transcribe it.

This made it impossible to use voice for task assignment in groups with mention gating enabled.

Solution

When a message that triggers the bot is itself a reply to a voice/audio message, download and transcribe that voice note via the STT pipeline, and inject it as context:

[Replying to voice message: "I need you to research XYZ and write a report"]

@Ren handle this

Changes

  • gateway/platforms/base.py: add reply_to_audio_path: Optional[str] field to MessageEvent
  • gateway/platforms/telegram.py: add _enrich_event_with_replied_audio() async helper that downloads replied-to voice/audio; called in _handle_text_message and _handle_media_message
  • gateway/run.py: transcribe reply_to_audio_path via the existing STT pipeline and prepend as [Replying to voice message: "..."] context block

Behavior

  • Only triggers when the replied-to message is a voice or audio message
  • Falls back silently if STT is unavailable (no error, voice context just omitted)
  • Works for both .ogg (voice notes) and .mp3/.m4a (audio files)
  • Reuses the existing cache_audio_from_bytes and _enrich_message_with_transcription infrastructure — no new dependencies

kaizen403 added 2 commits May 2, 2026 16:16
When require_mention=true is enabled in a group and a user @mentions
the bot in a reply to a voice/audio message, the bot now downloads
and transcribes that replied-to voice note and injects it as context
into the message (e.g. '[Replying to voice message: "..."]').

Previously, the bot would only see the @mention text and had no
visibility into the voice message being replied to. This made it
impossible to assign tasks by replying to a voice note with @botName.

Changes:
- gateway/platforms/base.py: add reply_to_audio_path field to MessageEvent
- gateway/platforms/telegram.py: add _enrich_event_with_replied_audio()
  async helper; called in _handle_text_message and _handle_media_message
  to download replied-to voice/audio before dispatch
- gateway/run.py: transcribe reply_to_audio_path via STT pipeline and
  prepend as [Replying to voice message: "..."] context block

Fixes: users unable to assign tasks to bots by replying to voice notes
with @botName in groups where require_mention=true
@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter tool/tts Text-to-speech and transcription labels May 2, 2026
@kaizen403

Copy link
Copy Markdown
Author

@teknium1 could you take a look when you have a moment? Small, additive change — three new lines of state plumbing plus an STT call on a new code path (replied-to voice notes). No behavior changes for existing flows. Happy to adjust scope or split if preferred.

@teknium1

Copy link
Copy Markdown
Collaborator

Thanks for the focused Telegram/STT contribution. This is an automated hermes-sweeper review; the requested behavior is already implemented on current main.

  • efbe1635dd2ee544afb850a23e0939560e3e0418 (fix(gateway): include replied-to media attachments (#46107)) added the generic replied-to-media path.
  • plugins/platforms/telegram/adapter.py:7507 calls _cache_replied_media() for a processed text trigger; plugins/platforms/telegram/adapter.py:7196 classifies and caches replied Telegram voice/audio into event.media_urls/media_types.
  • gateway/run.py:10398-10438 routes the resulting audio/* attachment through _enrich_message_with_transcription() before the agent receives the turn.
  • The fix is contained in release tag v2026.6.19.

Closing as implemented on main.

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

Labels

comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have platform/telegram Telegram bot adapter sweeper:implemented-on-main Sweeper: behavior already present on current main tool/tts Text-to-speech and transcription type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants