#17748: fix: transcribe voice messages in Telegram DMs (v2)
channel: telegram
stale
size: XS
## Summary
Fixed critical TDZ bug and improved DM voice transcription support.
## Changes
- Move preflightTranscript declaration before first use (fixes TDZ error)
- Add transcription for all voice messages in DMs
## Testing
- pnpm build
- pnpm check
## AI-assisted
Yes - AI-assisted with human review
Fixes #17101
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR extends Telegram preflight audio transcription to cover DM voice messages, not just group messages with mention requirements. The single condition `needsPreflightTranscription` is split into two clearly named flags: `needsGroupMentionTranscription` (unchanged group logic) and `needsDmTranscription` (`!isGroup && hasAudio`).
- Splits the transcription condition into `needsGroupMentionTranscription` and `needsDmTranscription` for clarity
- Group transcription behavior is unchanged (`isGroup && requireMention && hasAudio && !hasUserText && mentionRegexes.length > 0`)
- DM voice messages without captions will now be transcribed and the `<media:audio>` placeholder replaced with transcript text
- The existing `bodyText === "<media:audio>"` guard at line 434 ensures transcripts only replace the placeholder, not user-supplied captions
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge — the change is minimal, clearly scoped, and preserves existing group transcription behavior.
- Score of 4 reflects a small, focused change with clear intent. The group transcription condition is unchanged (no regression risk). The new DM transcription path correctly integrates with the existing bodyText replacement logic for caption-less voice messages. One minor inefficiency exists (transcribing captioned DM audio unnecessarily) but it was already flagged in a prior review thread and is non-critical.
- No files require special attention. The single changed file (`src/telegram/bot-message-context.ts`) has a clean, well-bounded modification.
<sub>Last reviewed commit: 77ba49c</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#17120: fix: transcribe all Telegram voice messages, not just mention-gated...
by MisterGuy420 · 2026-02-15
90.6%
#23067: feat(telegram): add disableAudioPreflight config for groups and topics
by yangnim21029 · 2026-02-22
77.9%
#22940: fix(discord): detect voice messages for preflight transcription bef...
by aldoeliacim · 2026-02-21
77.4%
#19213: Telegram: preserve DM topic thread in direct replies
by Kemalau · 2026-02-17
77.0%
#3368: fix: sessions navigation, DM thread display, and DM thread delivery...
by Lukavyi · 2026-01-28
77.0%
#17952: fix(telegram): support message_thread_id for DM topics
by timbrinded · 2026-02-16
77.0%
#7261: fix(telegram): preserve DM topic thread id for outbound media
by ViffyGwaanl · 2026-02-02
76.3%
#23572: feat(voice): enable voice note conversation loop for Telegram and W...
by davidrudduck · 2026-02-22
76.2%
#12936: fix(telegram): omit message_thread_id for private DM chats
by omair445 · 2026-02-09
75.6%
#20155: feat(telegram): add tg-network-guard transcript status + reply flow
by artemgetmann · 2026-02-18
74.1%