@llblab/pi-telegram 0.37.2 → 0.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/BACKLOG.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  _This file owns unresolved project work only. Completed behavior belongs in `CHANGELOG.md`; durable contracts belong in `AGENTS.md` and `/docs`._
4
4
 
5
+ - [ ] `Coherent voice reply policy`: Release the validated `manual`, `mirror`, and `always` policy cleanup as `0.38.0`, then reconcile issue #235 and open exact migration issues for `johnlam1968/pi-voice-telegram` and `luxus/pi-xai-voice`, whose TTS providers still consume the removed transcript-caption API.
5
6
  - [ ] `Operator-confirmed pairing`: Replace first-contact automatic ownership with an explicit pending request that the trusted Pi interface can allow or reject before `allowedUserId` is persisted or any Telegram prompt executes; retain manual preconfiguration, bound pending-request lifetime and multiplicity, fail closed across session/transport replacement, and cover unauthorized-first-contact races.
6
7
  - [ ] `Environment-backed bot tokens`: Let each profile store an exact Pi-native `$ENV_VAR` or `${ENV_VAR}` reference in `telegram.json` instead of copying the resolved secret; preserve the originating alias when `/telegram-setup` prefills from a supported environment variable, resolve only at validation/activation boundaries, fail closed with a redacted named-variable diagnostic when unresolved, retain literal-token compatibility, and cover named profiles, reload, persistence, status, and secret-redaction paths.
7
8
  - [ ] [`Inference bypass Generative Apps`](./docs/generative-apps.md): Let the agent install and bind one managed JavaScript app owner for a generated-prompt prefix so deterministic controls can bypass model inference without creating another button grammar.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  > Each release keeps at most 8 outcome records of at most 512 characters.
4
4
 
5
+ ## 0.38.0: Coherent Voice Reply Policy
6
+
7
+ - `Voice Reply Policy`: Renames the default user-facing `hidden` mode to `manual` while retaining `hidden` as a read-only configuration and callback compatibility alias. `manual`, `mirror`, and `always` remain the complete policy set: explicit `telegram_voice`, modality mirroring, or automatic voice replacement.
8
+ - `Voice Provider Contract`: Removes the redundant `voice.sendTranscript` configuration, `getTelegramVoiceSendTranscript()` public helper, provider-returned `transcriptText`, and voice-caption path. Synthesis providers now return only an OGG/Opus path or `undefined`; text-plus-voice remains an explicit agent composition rather than a parallel automatic policy.
9
+
5
10
  ## 0.37.2: Follower Recovery Delivery Hotfix
6
11
 
7
12
  - `Follower Recovery Delivery`: Holds follower Bot API calls behind a bounded registration wait when heartbeat recovery temporarily clears local authority, then sends once with the restored exact generation. Calls still fail closed if registration is not restored, and acknowledgement ambiguity remains non-retryable.
package/README.md CHANGED
@@ -130,7 +130,7 @@ Enable the optional capabilities the bridge needs in the [@BotFather](https://t.
130
130
  | Inbound files | Download inbound files to the Pi agent temp directory with size limits. | Screenshots, PDFs, datasets, and artifacts enter Pi as inspectable local files. |
131
131
  | Outbound artifacts | Return generated files through `telegram_attach` during active turns or explicit direct delivery. | Agents send real artifacts as files, not pasted blobs. |
132
132
  | Voice input | Route audio through configured command-template handlers, programmatic handlers, or STT providers. | Voice notes become usable prompt context. |
133
- | Voice output | Choose `hidden`, `mirror`, or `always`; active automatic turns carry one compact `[voice] delivery: automatic voice` line, while explicit `telegram_voice` remains available. | Voice policy stays dynamic and model-legible without duplicating the full action contract in every prompt. |
133
+ | Voice output | Choose `manual`, `mirror`, or `always`; active automatic turns carry one compact `[voice] delivery: automatic voice` line, while explicit `telegram_voice` remains available. | Voice policy stays dynamic and model-legible without duplicating the full action contract in every prompt. |
134
134
  | Buttons | Turn top-level `telegram_button` comments into inline buttons. | Assistant-authored choices become native Telegram interactions. |
135
135
  | Generative Apps | Install or explicitly replace a reviewed `.mjs` application whose generated JSON button view may mix direct `app::method` actions with ordinary model prompts. | Repeated games, controls, tutors, and adapters compile routine interaction without losing selective model interpretation, explanation, or adaptation. |
136
136
  | Callback routing | Route known callbacks to the owner extension and unknown callbacks back into Pi. | Companion extensions can build UI without polling Telegram themselves. |
@@ -218,7 +218,7 @@ Inbound files land under `<agent-dir>/tmp/telegram` and default to a 50 MiB limi
218
218
 
219
219
  ### Voice And Media
220
220
 
221
- Voice notes, audio, images, PDFs, and other media can pass through configured inbound handlers, programmatic handlers, or registered STT providers. Outbound voice can use configured `outboundHandlers` or registered TTS providers; `pi-telegram` owns reply policy and Telegram transport, while providers own synthesis. Configure provider-neutral local/API pipelines and ordered fallbacks through [`telegram.json` command templates](./docs/voice.md#choose-an-integration-path). The default `hidden` reply mode still supports intentional voice delivery through explicit `telegram_voice` actions; `mirror` and `always` add automatic voice policy. Explicit actions accept either a JSON object or compact double-quoted attributes, with equivalent `text` and `value` payload keys and one colon-free action marker.
221
+ Voice notes, audio, images, PDFs, and other media can pass through configured inbound handlers, programmatic handlers, or registered STT providers. Outbound voice can use configured `outboundHandlers` or registered TTS providers; `pi-telegram` owns reply policy and Telegram transport, while providers own synthesis. Configure provider-neutral local/API pipelines and ordered fallbacks through [`telegram.json` command templates](./docs/voice.md#choose-an-integration-path). The default `manual` reply mode still supports intentional voice delivery through explicit `telegram_voice` actions; `mirror` and `always` add automatic voice policy. Explicit actions accept either a JSON object or compact double-quoted attributes, with equivalent `text` and `value` payload keys and one colon-free action marker.
222
222
 
223
223
  ### Buttons And Callbacks
224
224
 
package/api/voice.ts CHANGED
@@ -9,7 +9,6 @@ export {
9
9
  computeVoicePromptContribution,
10
10
  computeVoiceTurnFlags,
11
11
  getTelegramVoiceReplyMode,
12
- getTelegramVoiceSendTranscript,
13
12
  isVoiceTurn,
14
13
  registerTelegramVoiceSynthesisProvider,
15
14
  registerTelegramVoiceTranscriptionProvider,
@@ -314,7 +314,7 @@ Every outbound request carries its target. The leader injects `message_thread_id
314
314
  Threaded Mode should make follower threads behave like normal Telegram instance surfaces, with the leader acting only as transport owner. Any feature in the matrix below that works for the leader must either work for followers or have an explicit documented exception.
315
315
 
316
316
  | Surface | Leader behavior | Follower requirement | Routing/ownership invariant | Regression evidence |
317
- | -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
317
+ | --- | --- | --- | --- | --- |
318
318
  | Prompt intake | Thread prompt queues locally | Thread prompt is forwarded and queued by the owning follower | Target ownership routes by `{ chatId, threadId }` before local handling | Routing tests for foreign target message forwarding |
319
319
  | Queued-message removal reactions | 👎/👻/💔/💩/🗑 marks a pending prompt/media turn for deletion when it reaches dispatch | Same reaction on a queued follower prompt marks that follower's pending turn for deletion before model dispatch | When the leader forwards a prompt to a follower, it records `chatId/messageId -> follower instance` because Bot API reaction updates expose chat/message but not thread id | Update runtime regression records forwarded message ownership and forwards the later reaction |
320
320
  | Queue priority reactions | 👍/⚡/❤/🕊/🔥 prioritizes queued prompts | Same reactions prioritize follower queued prompts | Reaction forwarding uses stored message ownership, then follower mutates its local queue | Reaction mutation tests plus forwarded-reaction coverage |
package/docs/outbound.md CHANGED
@@ -119,14 +119,13 @@ import { registerTelegramVoiceSynthesisProvider } from "@llblab/pi-telegram/voic
119
119
 
120
120
  const dispose = registerTelegramVoiceSynthesisProvider(
121
121
  async (text, options) => {
122
- const audioPath = await synthesizeToOggOpus(text, options);
123
- return { audioPath, transcriptText: text };
122
+ return await synthesizeToOggOpus(text, options);
124
123
  },
125
124
  { id: "my-extension/tts" },
126
125
  );
127
126
  ```
128
127
 
129
- Synthesis providers receive the extracted `telegram_voice` text plus optional `lang`/`rate` hints. Stable registrations pass a durable `id`; omitted ids remain a compatibility path for older providers. Providers own translation, TTS, speech rewriting, transcript choice, and OGG/Opus conversion. The bridge validates that the returned file ends in `.ogg` or `.opus`, sends it through Telegram `sendVoice`, and falls back to planned text if delivery fails before any visible text was delivered. Providers run after configured and programmatic voice handlers in the priority chain above.
128
+ Synthesis providers receive the extracted `telegram_voice` text plus optional `lang`/`rate` hints. Stable registrations pass a durable `id`; omitted ids remain a compatibility path for older providers. Providers own translation, TTS, speech rewriting, and OGG/Opus conversion. The bridge validates that the returned file ends in `.ogg` or `.opus`, sends it through Telegram `sendVoice`, and falls back to planned text if delivery fails before any visible text was delivered. Providers run after configured and programmatic voice handlers in the priority chain above.
130
129
 
131
130
  ## Voice Markup
132
131
 
@@ -99,8 +99,7 @@ interface TelegramConfig {
99
99
  timeInjection?: "hidden" | "always" | "interval";
100
100
  };
101
101
  voice?: {
102
- replyMode?: "hidden" | "mirror" | "always";
103
- sendTranscript?: boolean;
102
+ replyMode?: "manual" | "mirror" | "always";
104
103
  };
105
104
  time?: {
106
105
  interval?: number;
@@ -409,16 +408,13 @@ const offStt = registerTelegramVoiceTranscriptionProvider(
409
408
 
410
409
  const offTts = registerTelegramVoiceSynthesisProvider(
411
410
  async (text, options) => {
412
- const audioPath = await synthesizeOggOpus(text, options);
413
- return getTelegramVoiceSendTranscript(getCurrentTelegramConfigView())
414
- ? { audioPath, transcriptText: text }
415
- : { audioPath };
411
+ return await synthesizeOggOpus(text, options);
416
412
  },
417
413
  { id: "@scope/my-extension/tts" },
418
414
  );
419
415
  ```
420
416
 
421
- Stable voice-provider registrations pass a durable `id`. Omitting `id` is a compatibility path for older providers and receives a generated session-local id. Providers return `undefined` to pass. TTS providers must return `.ogg` or `.opus` files for native Telegram voice notes. `voice.sendTranscript` is the bridge-owned transcript preference; providers that expose captions should gate `transcriptText` with `getTelegramVoiceSendTranscript(config)` instead of defining a second reply-policy toggle.
417
+ Stable voice-provider registrations pass a durable `id`. Omitting `id` is a compatibility path for older providers and receives a generated session-local id. Providers return `undefined` to pass. TTS providers must return `.ogg` or `.opus` files for native Telegram voice notes.
422
418
 
423
419
  Full behavior: [Voice Integration](./voice.md).
424
420
 
@@ -525,7 +521,6 @@ export default function demoOutbound(pi: ExtensionAPI) {
525
521
  ```ts
526
522
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
527
523
  import {
528
- getTelegramVoiceSendTranscript,
529
524
  registerTelegramVoiceSynthesisProvider,
530
525
  registerTelegramVoiceTranscriptionProvider,
531
526
  } from "@llblab/pi-telegram/voice";
@@ -533,16 +528,12 @@ import {
533
528
  export default function demoVoice(pi: ExtensionAPI) {
534
529
  let unregisterTts: (() => void) | undefined;
535
530
  let unregisterStt: (() => void) | undefined;
536
- let currentConfig: { voice?: { sendTranscript?: boolean } } = {};
537
531
  pi.on("session_start", async () => {
538
532
  unregisterTts?.();
539
533
  unregisterStt?.();
540
534
  unregisterTts = registerTelegramVoiceSynthesisProvider(
541
535
  async (text) => {
542
- const audioPath = await synthesizeDemoOgg(text);
543
- return getTelegramVoiceSendTranscript(currentConfig)
544
- ? { audioPath, transcriptText: text }
545
- : { audioPath };
536
+ return await synthesizeDemoOgg(text);
546
537
  },
547
538
  { id: "demo-voice/tts" },
548
539
  );
package/docs/voice.md CHANGED
@@ -43,12 +43,12 @@ Voice provider extensions can also register STT backends with `registerTelegramV
43
43
 
44
44
  ## Voice Reply Policy
45
45
 
46
- The bridge decides **when** to reply with voice from `voice.replyMode` in `TelegramConfig` (stored in `telegram.json`). Missing, invalid, `hidden`, and legacy `manual` values resolve to the silent `hidden` default.
46
+ The bridge decides **when** to reply with voice from `voice.replyMode` in `TelegramConfig` (stored in `telegram.json`). Missing and invalid values resolve to the `manual` default; the former `hidden` value remains a read-only compatibility alias for `manual`.
47
47
 
48
48
  ### Modes
49
49
 
50
- - **`hidden` (default):** no `voice.replyMode` is stored and no automatic voice context is added; explicit agent-authored `telegram_voice` actions still work.
51
- - **`mirror`:** voice/audio input activates automatic voice delivery. Text input follows `hidden` behavior.
50
+ - **`manual` (default):** no `voice.replyMode` is stored and no automatic voice context is added; explicit agent-authored `telegram_voice` actions still work.
51
+ - **`mirror`:** voice/audio input activates automatic voice delivery. Text input follows `manual` behavior.
52
52
  - **`always`:** every Telegram turn activates automatic voice delivery.
53
53
 
54
54
  **Warning:** In `always` mode, the bridge transparently intercepts ALL text replies and converts them to voice on success. Users will only receive voice messages when voice generation succeeds. If voice generation fails, the bridge falls back to sending the planned text reply.
@@ -70,7 +70,7 @@ A voice extension may combine three public seams:
70
70
 
71
71
  - `registerTelegramVoiceTranscriptionProvider()` for inbound STT fallback on voice/audio files
72
72
  - `registerTelegramVoiceSynthesisProvider()` for outbound TTS/synthesis fallback to Telegram voice messages
73
- - `registerTelegramSection()` for provider-specific Telegram UI such as voice, language, style, transcript, or provider on/off controls
73
+ - `registerTelegramSection()` for provider-specific Telegram UI such as voice, language, style, or provider on/off controls
74
74
 
75
75
  The reply policy itself remains a built-in pi-telegram setting (`voice.replyMode`) rather than a provider-owned menu.
76
76
 
@@ -81,10 +81,8 @@ Voice synthesis provider extensions register themselves through `registerTelegra
81
81
  - Text optimisation / speech-style rewriting
82
82
  - Adding speech tags (when desired)
83
83
  - Running TTS + ffmpeg conversion to OGG/Opus
84
- - Deciding whether to return `transcriptText` at all based on the bridge-owned `voice.sendTranscript` preference when the provider has access to the current Telegram config
85
- - `transcriptText` (when returned) is attached by the bridge as the voice message **caption** only. Separate transcript messages are no longer sent.
86
84
 
87
- The bridge shows a `record_voice` action while delivering and sends the final audio with Telegram `sendVoice`. When a provider returns `transcriptText`, the bridge attaches it as the voice caption.
85
+ The bridge shows a `record_voice` action while delivering and sends the final audio with Telegram `sendVoice`.
88
86
 
89
87
  Providers can implement `getVoicePromptContribution(view)` to inject voice-specific instructions into voice-tagged prompts (for example: "Reply only with the spoken text"). The bridge appends the first non-empty provider contribution when `mirror` or `always` mode tags the turn.
90
88
 
@@ -95,7 +93,6 @@ The provider receives the raw agent text plus optional `{ lang?, rate? }`.
95
93
  It must return one of:
96
94
 
97
95
  - `string` — path to a ready `.ogg` or `.opus` file
98
- - `{ audioPath: string, transcriptText?: string }` — `audioPath` must be OGG/Opus. When `transcriptText` is present it is attached as the voice message **caption**. Providers should treat pi-telegram's `voice.sendTranscript` as the bridge-owned transcript preference instead of inventing a second reply-policy UI.
99
96
  - `undefined` — skip this text block
100
97
 
101
98
  **Important:** Providers are fully responsible for producing a clean, TTS-optimised native voice file. The bridge may also run configured outbound voice command templates for users who prefer process-boundary handlers instead of provider extensions.
@@ -106,7 +103,7 @@ Registration returns a disposer function for cleanup. Stable provider registrati
106
103
 
107
104
  ## Outbound Voice Handlers
108
105
 
109
- Users can also configure `outboundHandlers` with `type: "voice"` in `telegram.json`. This is the command-template path for TTS without a provider extension. Reply modes (`hidden`, `mirror`, `always`) affect these handlers the same way they affect providers: explicit `telegram_voice` blocks and automatic mirror/always interception both produce a voice reply plan, then delivery tries configured outbound voice handlers first and registered synthesis providers as progressive fallbacks.
106
+ Users can also configure `outboundHandlers` with `type: "voice"` in `telegram.json`. This is the command-template path for TTS without a provider extension. Reply modes (`manual`, `mirror`, `always`) affect these handlers the same way they affect providers: explicit `telegram_voice` blocks and automatic mirror/always interception both produce a voice reply plan, then delivery tries configured outbound voice handlers first and registered synthesis providers as progressive fallbacks.
110
107
 
111
108
  Voice handlers receive the text on stdin in composed pipelines and can use `{text}`, `{lang}`, `{rate}`, `{mp3}`, and `{ogg}` placeholders. Set `output` to `"ogg"` or another placeholder name when the template writes to a known path:
112
109
 
@@ -128,31 +125,6 @@ Voice handlers receive the text on stdin in composed pipelines and can use `{tex
128
125
 
129
126
  Priority for outbound voice delivery is: configured `outboundHandlers` with `type: "voice"` in their `telegram.json` order, then programmatic `voice` outbound handlers, then registered voice synthesis providers. Provider extensions are the zero-config tail of the same pipeline: they handle voice when no explicit configured handler succeeds, but they do not override operator-configured handlers. If multiple providers are registered, only one handles a given voice reply: the first provider that returns a valid `.ogg`/`.opus` artifact wins. Providers that return `undefined` explicitly pass to the next provider; providers that throw or return invalid output are recorded and the next fallback is tried.
130
127
 
131
- ### Provider with transcript caption (controlled by user toggle)
132
-
133
- When the user's "Send Transcript" toggle is ON, return the clean spoken text as `transcriptText`. The bridge attaches it as the caption on the voice message. When the toggle is OFF, return only the audio path (no `transcriptText`).
134
-
135
- ```typescript
136
- import {
137
- getTelegramVoiceSendTranscript,
138
- registerTelegramVoiceSynthesisProvider,
139
- } from "@llblab/pi-telegram/voice";
140
-
141
- registerTelegramVoiceSynthesisProvider(
142
- async (text, options) => {
143
- const rewritten = rewriteWithSpeechTags(text);
144
- const audioPath = await myTTS(rewritten, { language: options?.lang });
145
- const sendTranscript = getTelegramVoiceSendTranscript(
146
- getCurrentTelegramConfigView(),
147
- );
148
- return sendTranscript ? { audioPath, transcriptText: text } : { audioPath };
149
- },
150
- { id: "my-voice-provider/tts" },
151
- );
152
- ```
153
-
154
- `getCurrentTelegramConfigView()` represents whatever current `TelegramConfig` view your extension already owns or receives; pi-telegram does not require providers to read config directly. The bridge never sends a separate transcript message. Caption-only is the "ON" behavior.
155
-
156
128
  ### Surfacing provider diagnostics
157
129
 
158
130
  Voice provider extensions can record runtime events that appear in `/telegram-status` alongside pi-telegram's own events:
@@ -170,13 +142,13 @@ recordTelegramRuntimeEvent("voice-provider", new Error("TTS failed"), {
170
142
 
171
143
  ## Voice Extension Section
172
144
 
173
- Voice provider extensions can register a Voice Extension Section (settings UI) via `registerTelegramSection`. The section can expose provider-specific controls such as TTS voice, language, speech style, transcript behavior, or STT/TTS enablement. Reply mode is a core pi-telegram setting and belongs in the built-in Settings menu.
145
+ Voice provider extensions can register a Voice Extension Section (settings UI) via `registerTelegramSection`. The section can expose provider-specific controls such as TTS voice, language, speech style, or STT/TTS enablement. Reply mode is a core pi-telegram setting and belongs in the built-in Settings menu.
174
146
 
175
147
  **Note on resume:** Because the previous automatic persistent re-registration system has been removed, extensions are responsible for re-registering their Voice Extension Section on `session_start` if they want the menu to survive a `pi resume`. See `registerTelegramSection` from `@llblab/pi-telegram/sections`.
176
148
 
177
149
  ## Prompt Guidance
178
150
 
179
- The bridge keeps voice prompt context compact, effective, and policy-owned. `hidden` and text-originated `mirror` turns add no voice line. Voice/audio-originated `mirror` turns and every `always` turn add exactly `[voice] delivery: automatic voice`, describing the current delivery environment without exposing the underlying mode matrix or an instruction list. The marker is appended after `[outputs]` when handler output exists, otherwise after `[attachments]`. Voice inputs also appear in `[attachments]` with their downloaded file names, MIME data, and handler output, so agents can infer concrete voice-file context from attachment metadata.
151
+ The bridge keeps voice prompt context compact, effective, and policy-owned. `manual` and text-originated `mirror` turns add no voice line. Voice/audio-originated `mirror` turns and every `always` turn add exactly `[voice] delivery: automatic voice`, describing the current delivery environment without exposing the underlying mode matrix or an instruction list. The marker is appended after `[outputs]` when handler output exists, otherwise after `[attachments]`. Voice inputs also appear in `[attachments]` with their downloaded file names, MIME data, and handler output, so agents can infer concrete voice-file context from attachment metadata.
180
152
 
181
153
  Voice synthesis providers can supply prompt guidance through `getVoicePromptContribution(view)`, but provider text should stay optional and provider-specific. Reply-mode context belongs to pi-telegram.
182
154
 
@@ -224,4 +196,4 @@ The bridge reads `voice.replyMode` from the config when building a turn.
224
196
 
225
197
  ### Provider config
226
198
 
227
- Provider-specific settings (voice ID, language, speech style, transcript behavior, STT/TTS enablement) are owned by the voice provider extension. Reply mode is owned by pi-telegram's `voice.replyMode` and configured from the built-in pi-telegram Settings menu, not duplicated in provider UIs.
199
+ Provider-specific settings (voice ID, language, speech style, STT/TTS enablement) are owned by the voice provider extension. Reply mode is owned by pi-telegram's `voice.replyMode` and configured from the built-in pi-telegram Settings menu, not duplicated in provider UIs.
package/lib/config.ts CHANGED
@@ -118,9 +118,8 @@ export interface TelegramConfig {
118
118
  /** @deprecated use assistant.rendering */
119
119
  assistantRendering?: TelegramAssistantRenderingMode;
120
120
  voice?: {
121
- replyMode?: "hidden" | "mirror" | "always";
122
- /** Whether to attach the provider's transcriptText as caption on voice messages */
123
- sendTranscript?: boolean;
121
+ /** `hidden` is a read-only compatibility alias for the former manual mode. */
122
+ replyMode?: "manual" | "hidden" | "mirror" | "always";
124
123
  };
125
124
  time?: TelegramTimeConfig;
126
125
  threads?: {
@@ -845,10 +844,10 @@ export function createTelegramActivityVerbositySetter(
845
844
 
846
845
  export function createTelegramVoiceReplyModeGetter(
847
846
  configStore: Pick<TelegramConfigStore, "get">,
848
- ): () => "hidden" | "mirror" | "always" {
847
+ ): () => "manual" | "mirror" | "always" {
849
848
  return () => {
850
849
  const mode = configStore.get().voice?.replyMode;
851
- return mode === "mirror" || mode === "always" ? mode : "hidden";
850
+ return mode === "mirror" || mode === "always" ? mode : "manual";
852
851
  };
853
852
  }
854
853
 
@@ -863,11 +862,15 @@ export function createTelegramVoiceReplyModeConfiguredChecker(
863
862
 
864
863
  export function createTelegramVoiceReplyModeSetter(
865
864
  configStore: TelegramMutableConfigStore,
866
- ): (replyMode: "hidden" | "mirror" | "always" | undefined) => Promise<void> {
865
+ ): (replyMode: "manual" | "hidden" | "mirror" | "always" | undefined) => Promise<void> {
867
866
  return async (replyMode) => {
868
867
  await loadLatestTelegramConfig(configStore);
869
868
  const current = configStore.get();
870
- if (replyMode === undefined || replyMode === "hidden") {
869
+ if (
870
+ replyMode === undefined ||
871
+ replyMode === "manual" ||
872
+ replyMode === "hidden"
873
+ ) {
871
874
  const { replyMode: _replyMode, ...remainingVoice } = current.voice ?? {};
872
875
  const next = { ...current };
873
876
  if (Object.keys(remainingVoice).length > 0) next.voice = remainingVoice;
@@ -149,9 +149,7 @@ export const TIME_INJECTION_MODE_SETTINGS_TITLE =
149
149
  "<b>🕒 Time injection mode:</b>";
150
150
  export const VOICE_REPLY_MODE_SETTINGS_TITLE = "<b>👄 Voice reply mode:</b>";
151
151
 
152
- type TelegramVoiceReplyModeSetting = TelegramVoiceReplyMode | "hidden";
153
-
154
- function getVoiceReplyModeLabel(mode: TelegramVoiceReplyModeSetting): string {
152
+ function getVoiceReplyModeLabel(mode: TelegramVoiceReplyMode): string {
155
153
  return mode;
156
154
  }
157
155
 
@@ -162,8 +160,8 @@ function getTelegramSettingsStateValueLabel(value: string): string {
162
160
  function getVoiceReplyModeSetting(
163
161
  mode: TelegramVoiceReplyMode,
164
162
  configured: boolean,
165
- ): TelegramVoiceReplyModeSetting {
166
- return configured ? mode : "hidden";
163
+ ): TelegramVoiceReplyMode {
164
+ return configured ? mode : "manual";
167
165
  }
168
166
 
169
167
  export function buildTelegramSettingsMenuText(): string {
@@ -246,8 +244,8 @@ export function buildVoiceReplyModeSettingsText(
246
244
  "",
247
245
  "Controls when pi-telegram converts assistant text replies into Telegram voice messages.",
248
246
  "",
249
- "<code>-</code> <code>hidden</code> (default): add no automatic voice context; explicit 'telegram_voice' actions still work.",
250
- "<code>-</code> <code>mirror</code>: voice input activates automatic voice delivery; text input follows 'hidden' behavior.",
247
+ "<code>-</code> <code>manual</code> (default): add no automatic voice context; explicit 'telegram_voice' actions still work.",
248
+ "<code>-</code> <code>mirror</code>: voice input activates automatic voice delivery; text input follows 'manual' behavior.",
251
249
  "<code>-</code> <code>always</code>: activate automatic voice delivery for every reply.",
252
250
  ].join("\n");
253
251
  }
@@ -502,7 +500,7 @@ export function buildVoiceReplyModeSettingsReplyMarkup(
502
500
  configured = true,
503
501
  ): TelegramSettingsMenuReplyMarkup {
504
502
  const activeMode = getVoiceReplyModeSetting(mode, configured);
505
- const modes: TelegramVoiceReplyModeSetting[] = ["hidden", "mirror", "always"];
503
+ const modes: TelegramVoiceReplyMode[] = ["manual", "mirror", "always"];
506
504
  return {
507
505
  inline_keyboard: [
508
506
  [{ text: "⬆️ Back", callback_data: "settings:list" }],
@@ -661,12 +659,18 @@ export async function handleTelegramSettingsMenuCallbackAction(
661
659
  }
662
660
  if (data.startsWith("settings:set:voice-reply:")) {
663
661
  const mode = data.slice("settings:set:voice-reply:".length);
664
- if (mode === "hidden" || mode === "mirror" || mode === "always") {
665
- await deps.setVoiceReplyMode(mode === "hidden" ? undefined : mode);
662
+ if (
663
+ mode === "manual" ||
664
+ mode === "hidden" ||
665
+ mode === "mirror" ||
666
+ mode === "always"
667
+ ) {
668
+ const normalizedMode = mode === "hidden" ? "manual" : mode;
669
+ await deps.setVoiceReplyMode(normalizedMode);
666
670
  await updateVoiceReplyModeSettingsMessage(deps);
667
671
  await deps.answerCallbackQuery(
668
672
  callbackQueryId,
669
- `Voice reply mode: ${mode}`,
673
+ `Voice reply mode: ${normalizedMode}`,
670
674
  );
671
675
  return true;
672
676
  }
@@ -100,17 +100,6 @@ async function ensureTelegramVoiceFileFormat(
100
100
  );
101
101
  }
102
102
 
103
- function extractVoiceResult(result: any): {
104
- filePath: string;
105
- transcriptText?: string;
106
- } {
107
- if (typeof result === "string") return { filePath: result };
108
- return {
109
- filePath: result.audioPath,
110
- transcriptText: result.transcriptText,
111
- };
112
- }
113
-
114
103
  async function sendVoiceChatAction(
115
104
  deps: TelegramVoiceReplySenderDeps,
116
105
  chatId: number,
@@ -132,7 +121,6 @@ export function createTelegramVoiceReplySender<THandler = unknown>(
132
121
  options?: {
133
122
  replyToPrompt?: boolean;
134
123
  replyMarkup?: unknown;
135
- transcriptText?: string;
136
124
  },
137
125
  ): Promise<void> => {
138
126
  const voiceFilePath = await ensureTelegramVoiceFileFormat(filePath);
@@ -148,7 +136,6 @@ export function createTelegramVoiceReplySender<THandler = unknown>(
148
136
  "sendVoice",
149
137
  {
150
138
  chat_id: String(turn.chatId),
151
- ...(options?.transcriptText ? { caption: options.transcriptText } : {}),
152
139
  ...(replyParameters ? { reply_parameters: replyParameters } : {}),
153
140
  ...(turn.target
154
141
  ? Object.fromEntries(
@@ -257,13 +244,11 @@ export function createTelegramVoiceReplySender<THandler = unknown>(
257
244
  continue;
258
245
  }
259
246
 
260
- const { filePath, transcriptText } = extractVoiceResult(providerResult);
261
- voiceFilePath = filePath;
262
- originalFilePath = filePath;
263
- await uploadVoiceFile(turn, filePath, {
247
+ voiceFilePath = providerResult;
248
+ originalFilePath = providerResult;
249
+ await uploadVoiceFile(turn, providerResult, {
264
250
  replyToPrompt: options?.replyToPrompt,
265
251
  replyMarkup: options?.replyMarkup,
266
- transcriptText,
267
252
  });
268
253
  return;
269
254
  } catch (error) {
package/lib/voice.ts CHANGED
@@ -38,15 +38,9 @@ function getNextAvailableProviderId<T>(
38
38
  return id;
39
39
  }
40
40
 
41
- export type TelegramVoiceReplyMode = "hidden" | "mirror" | "always";
41
+ export type TelegramVoiceReplyMode = "manual" | "mirror" | "always";
42
42
 
43
- export type TelegramVoiceSynthesisProviderResult =
44
- | string
45
- | {
46
- audioPath: string;
47
- transcriptText?: string;
48
- }
49
- | undefined;
43
+ export type TelegramVoiceSynthesisProviderResult = string | undefined;
50
44
 
51
45
  export interface TelegramVoiceTurnView {
52
46
  voiceReplyPreferred?: boolean;
@@ -215,7 +209,7 @@ export function clearTelegramVoiceTranscriptionProviders(): void {
215
209
  // --- Voice Reply Modes ---
216
210
 
217
211
  export const TELEGRAM_VOICE_REPLY_MODES = [
218
- "hidden",
212
+ "manual",
219
213
  "mirror",
220
214
  "always",
221
215
  ] as const;
@@ -224,33 +218,15 @@ export const TELEGRAM_VOICE_REPLY_MODES = [
224
218
  * Returns the active voice reply mode for the current session.
225
219
  *
226
220
  * Pi-telegram owns reply-mode policy through telegram.json. If
227
- * config.voice.replyMode is missing, invalid, or legacy `manual`, the effective
228
- * mode is hidden.
221
+ * config.voice.replyMode is missing, invalid, or legacy `hidden`, the effective
222
+ * mode is manual.
229
223
  */
230
224
  export function getTelegramVoiceReplyMode(config?: {
231
225
  voice?: { replyMode?: string };
232
226
  }): TelegramVoiceReplyMode {
233
227
  const configMode = config?.voice?.replyMode;
234
- if (
235
- configMode &&
236
- (TELEGRAM_VOICE_REPLY_MODES as readonly string[]).includes(configMode)
237
- ) {
238
- return configMode as TelegramVoiceReplyMode;
239
- }
240
- return "hidden";
241
- }
242
-
243
- /**
244
- * Returns whether the user wants the voice synthesis provider's transcript attached
245
- * as a caption on the voice message.
246
- *
247
- * Reads from `config.voice.sendTranscript`.
248
- * Default: false (no transcript text sent at all).
249
- */
250
- export function getTelegramVoiceSendTranscript(config?: {
251
- voice?: { sendTranscript?: boolean };
252
- }): boolean {
253
- return !!config?.voice?.sendTranscript;
228
+ if (configMode === "mirror" || configMode === "always") return configMode;
229
+ return "manual";
254
230
  }
255
231
 
256
232
  // --- Voice Turn Helpers ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@llblab/pi-telegram",
3
- "version": "0.37.2",
3
+ "version": "0.38.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -122,7 +122,7 @@ Prefer no-code command-template configuration in `telegram.json` before adding a
122
122
  - `outboundHandlers` transforms final replies.
123
123
  - Voice transcription handlers can match `type: "voice"` or `mime: "audio/*"`; stdout becomes `[outputs]`.
124
124
 
125
- When asked to configure voice rather than merely operate it, follow the provider-neutral contracts in `docs/voice.md`, `docs/inbound.md`, `docs/outbound.md`, and `docs/command-templates.md` from the pi-telegram package or repository. Inspect the available Skill catalog and trusted local executables for STT, TTS, and media conversion capabilities; check only whether required environment variables exist, never reveal their values. Preserve unrelated `telegram.json` fields, order multiple matching inbound handlers as fallbacks, require OGG/Opus output for native voice delivery, and validate each stage before a live Telegram smoke test. Keep `voice.replyMode` at its existing value unless the user requests a policy change: the default `hidden` mode is fully functional because explicit top-level `telegram_voice` actions still use the configured synthesis pipeline.
125
+ When asked to configure voice rather than merely operate it, follow the provider-neutral contracts in `docs/voice.md`, `docs/inbound.md`, `docs/outbound.md`, and `docs/command-templates.md` from the pi-telegram package or repository. Inspect the available Skill catalog and trusted local executables for STT, TTS, and media conversion capabilities; check only whether required environment variables exist, never reveal their values. Preserve unrelated `telegram.json` fields, order multiple matching inbound handlers as fallbacks, require OGG/Opus output for native voice delivery, and validate each stage before a live Telegram smoke test. Keep `voice.replyMode` at its existing value unless the user requests a policy change: the default `manual` mode is fully functional because explicit top-level `telegram_voice` actions still use the configured synthesis pipeline.
126
126
 
127
127
  When configuration is insufficient, use documented `@llblab/pi-telegram/*` public API subpaths. Never import package-private `lib/*`, start another polling loop, or bypass bridge ownership with raw Bot API access.
128
128