| 38-telegram-bridge |
02 |
api |
| telegram |
| grammy |
| voice |
| whisper |
| piper |
| ogg |
| ffmpeg |
| tts |
| stt |
|
| phase |
provides |
| 38-01 |
telegramService factory with text relay, session map, bot lifecycle |
|
| phase |
provides |
| 36-voice-pipeline |
voicePipelineService (transcribe, synthesize, formatForVoice, transcodeToWav16k) |
|
|
| Voice message handler |
| OGG download via ctx.getFile(), transcription via voicePipelineService |
|
| Shared relayToAgent() function used by both text and voice message handlers |
| transcodeToOggOpus() helper |
| raw PCM s16le (Piper 22050Hz) -> OGG Opus 48000Hz for Telegram |
|
| TTS voice reply |
| agent responses synthesized to OGG voice note via ctx.replyWithVoice() |
|
| Graceful TTS degradation |
| text reply always sent first; voice is a bonus that silently fails |
|
|
| 38-03 (onboarding step unchanged — already uses POST /telegram/token) |
|
| added |
patterns |
|
|
| Immediate 'Transcribing...' reply prevents Telegram update resend (Pitfall 1) |
| Fire-and-forget async: processVoiceMessage() not awaited inside handler body |
| Shared relayToAgent(ctx, chatId, userText, db, voiceMode) eliminates duplicate relay logic |
| TTS reply wrapped in try/catch — voice failure never blocks text response |
| transcodeToOggOpus uses same ffmpeg spawn pattern as voice-pipeline.ts |
|
|
| created |
modified |
|
|
| server/src/services/telegram.ts |
|
|
| Both tasks implemented together in one atomic file write — Task 1 (voice handler + relay refactor) and Task 2 (TTS reply) both modify telegram.ts; committing as one coherent change |
| processVoiceMessage() extracted as top-level async function — keeps bot handler clean and makes error handling explicit |
| voiceMode flag passed to relayToAgent() rather than checking ctx type — simpler and avoids grammy type gymnastics |
| botToken stored as module-level mutable ref (botToken = token) in start() — processVoiceMessage needs token for CDN URL construction |
| Piper hardcoded to 22050Hz in transcodeToOggOpus with comment — matches en_US-lessac-medium model spec |
|
| duration |
completed |
tasks_completed |
tasks_total |
files_modified |
| 10min |
2026-04-04 |
2 |
2 |
1 |
|