Skip to content

Commit ad1dedc

Browse files
committed
Revert "Merge branch 'pr-135' into feat/hebrew-i18n"
This reverts commit 5c9b6bd, reversing changes made to e9090ac.
1 parent 11bb24b commit ad1dedc

11 files changed

Lines changed: 115 additions & 278 deletions

File tree

src/bot/handlers/stt-confirm.ts

Lines changed: 0 additions & 183 deletions
This file was deleted.

src/bot/handlers/voice.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import http from "node:http";
22
import https from "node:https";
33
import { URL } from "node:url";
44
import type { Context } from "grammy";
5+
import type { FilePartInput } from "@opencode-ai/sdk/v2";
56
import { HttpsProxyAgent } from "https-proxy-agent";
67
import { SocksProxyAgent } from "socks-proxy-agent";
78
import { config } from "../../config.js";
89
import { isSttConfigured, transcribeAudio, type SttResult } from "../../stt/client.js";
9-
import type { ProcessPromptDeps } from "./prompt.js";
10-
import { showSttConfirmation } from "./stt-confirm.js";
10+
import { processUserPrompt, type ProcessPromptDeps } from "./prompt.js";
1111
import { logger } from "../../utils/logger.js";
1212
import { t } from "../../i18n/index.js";
1313
import { buildTelegramFileUrl } from "../utils/telegram-file-url.js";
@@ -102,6 +102,13 @@ export interface VoiceMessageDeps extends ProcessPromptDeps {
102102
fileId: string,
103103
) => Promise<{ buffer: Buffer; filename: string } | null>;
104104
transcribeAudio?: (audioBuffer: Buffer, filename: string) => Promise<SttResult>;
105+
processPrompt?: (
106+
ctx: Context,
107+
text: string,
108+
deps: ProcessPromptDeps,
109+
fileParts?: FilePartInput[],
110+
options?: { responseMode?: "text_only" | "text_and_tts" },
111+
) => Promise<boolean>;
105112
}
106113

107114
/**
@@ -167,6 +174,7 @@ export async function handleVoiceMessage(ctx: Context, deps: VoiceMessageDeps):
167174
const sttConfigured = deps.isSttConfigured ?? isSttConfigured;
168175
const downloadFile = deps.downloadTelegramFile ?? downloadTelegramFile;
169176
const transcribe = deps.transcribeAudio ?? transcribeAudio;
177+
const processPrompt = deps.processPrompt ?? processUserPrompt;
170178

171179
// Determine file_id from voice or audio message
172180
const voice = ctx.message?.voice;
@@ -208,9 +216,32 @@ export async function handleVoiceMessage(ctx: Context, deps: VoiceMessageDeps):
208216
return;
209217
}
210218

219+
// Show the recognized text by editing the status message.
220+
// IMPORTANT: even if this edit fails (e.g. Telegram message length limits),
221+
// we still send the recognized text to OpenCode as a prompt.
222+
try {
223+
await ctx.api.editMessageText(
224+
ctx.chat!.id,
225+
statusMessage.message_id,
226+
t("stt.recognized", { text: recognizedText }),
227+
);
228+
} catch (editError) {
229+
logger.warn("[Voice] Failed to edit status message with recognized text:", editError);
230+
}
231+
211232
logger.info(`[Voice] Transcribed audio: ${recognizedText.length} chars`);
212233

213-
await showSttConfirmation(ctx, statusMessage.message_id, recognizedText);
234+
let textForLLM = recognizedText;
235+
const notePrompt = config.stt.notePrompt.trim();
236+
237+
if (notePrompt && notePrompt.toLowerCase() !== "false" && notePrompt !== "0") {
238+
const llmNote = `[Note: ${notePrompt}]`;
239+
logger.debug(`[Voice] Added STT note to LLM prompt: ${llmNote}`);
240+
textForLLM = `${llmNote}\n${recognizedText}`;
241+
}
242+
243+
// Process the recognized text as a prompt
244+
await processPrompt(ctx, textForLLM, deps);
214245
} catch (err) {
215246
const errorMessage = err instanceof Error ? err.message : "unknown error";
216247
logger.error("[Voice] Error processing voice message:", err);

src/bot/index.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ import { getCurrentProject } from "../settings/manager.js";
8484
import { createTelegramBotOptions } from "./telegram-client-options.js";
8585
import { clearPromptResponseMode, processUserPrompt } from "./handlers/prompt.js";
8686
import { handleVoiceMessage } from "./handlers/voice.js";
87-
import {
88-
handleSttConfirmCallback,
89-
handleSttEditText,
90-
} from "./handlers/stt-confirm.js";
9187
import { handleDocumentMessage } from "./handlers/document.js";
9288
import { createMediaGroupAttachmentMiddleware } from "./handlers/media-group.js";
9389
import { downloadTelegramFile, toDataUri } from "./utils/file-download.js";
@@ -1235,10 +1231,9 @@ export function createBot(): Bot<Context> {
12351231
const handledMessages = await handleMessagesCallback(ctx, { bot, ensureEventSubscription });
12361232
const handledSkills = await handleSkillsCallback(ctx, { bot, ensureEventSubscription });
12371233
const handledMcps = await handleMcpsCallback(ctx);
1238-
const handledStt = await handleSttConfirmCallback(ctx, { bot, ensureEventSubscription });
12391234

12401235
logger.debug(
1241-
`[Bot] Callback handled: backgroundSession=${handledBackgroundSession}, inlineCancel=${handledInlineCancel}, session=${handledSession}, project=${handledProject}, worktree=${handledWorktree}, open=${handledOpen}, ls=${handledLs}, question=${handledQuestion}, permission=${handledPermission}, agent=${handledAgent}, modelSearch=${handledModelSearch}, modelSearchResults=${handledModelSearchResults}, model=${handledModel}, variant=${handledVariant}, compactConfirm=${handledCompactConfirm}, task=${handledTask}, taskList=${handledTaskList}, rename=${handledRenameCancel}, commands=${handledCommands}, messages=${handledMessages}, skills=${handledSkills}, mcps=${handledMcps}, stt=${handledStt}`,
1236+
`[Bot] Callback handled: backgroundSession=${handledBackgroundSession}, inlineCancel=${handledInlineCancel}, session=${handledSession}, project=${handledProject}, worktree=${handledWorktree}, open=${handledOpen}, ls=${handledLs}, question=${handledQuestion}, permission=${handledPermission}, agent=${handledAgent}, modelSearch=${handledModelSearch}, modelSearchResults=${handledModelSearchResults}, model=${handledModel}, variant=${handledVariant}, compactConfirm=${handledCompactConfirm}, task=${handledTask}, taskList=${handledTaskList}, rename=${handledRenameCancel}, commands=${handledCommands}, messages=${handledMessages}, skills=${handledSkills}, mcps=${handledMcps}`,
12421237
);
12431238

12441239
if (
@@ -1263,8 +1258,7 @@ export function createBot(): Bot<Context> {
12631258
!handledCommands &&
12641259
!handledMessages &&
12651260
!handledSkills &&
1266-
!handledMcps &&
1267-
!handledStt
1261+
!handledMcps
12681262
) {
12691263
logger.debug("Unknown callback query:", ctx.callbackQuery?.data);
12701264
await ctx.answerCallbackQuery({ text: t("callback.unknown_command") });
@@ -1513,11 +1507,6 @@ export function createBot(): Bot<Context> {
15131507
return;
15141508
}
15151509

1516-
const handledSttEdit = await handleSttEditText(ctx, promptDeps);
1517-
if (handledSttEdit) {
1518-
return;
1519-
}
1520-
15211510
await processUserPrompt(ctx, text, promptDeps);
15221511

15231512
logger.debug("[Bot] message:text handler completed (prompt sent in background)");

src/i18n/de.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -585,18 +585,9 @@ export const de: I18nDictionary = {
585585
"stt.recognizing": "🎤 Erkenne Audio...",
586586
"stt.recognized": "🎤 Erkannt:\n{text}",
587587
"stt.not_configured":
588-
"🎤 Spracherkennung ist nicht konfiguriert.\n\nSetze STT_API_URL und STT_API_KEY in der .env-Datei.",
588+
"🎤 Spracherkennung ist nicht konfiguriert.\n\nSetze STT_API_URL und STT_API_KEY in .env, um sie zu aktivieren.",
589589
"stt.error": "🔴 Audio konnte nicht erkannt werden: {error}",
590590
"stt.empty_result": "🎤 Keine Sprache in der Audionachricht erkannt.",
591-
"stt.confirm_message": "🎤 Erkannter Text:\n{text}\n\nSenden, bearbeiten oder abbrechen?",
592-
"stt.confirm_send": "✅ Senden",
593-
"stt.confirm_edit": "✏️ Bearbeiten",
594-
"stt.confirm_cancel": "❌ Abbrechen",
595-
"stt.confirm_sending": "✅ Sende erkannten Text als Prompt...",
596-
"stt.confirm_edit_prompt": "✏️ Sende den korrigierten Text:",
597-
"stt.confirm_edit_sending": "✅ Sende bearbeiteten Text als Prompt...",
598-
"stt.confirm_cancelled": "❌ Sprachnachricht abgebrochen.",
599-
"stt.confirm_inactive": "Diese Sprachnachricht ist nicht mehr aktiv.",
600591

601592
"cmd.description.open": "Projekt durch Ordner-Auswahl hinzufügen",
602593
"worktree.branch_detached": "detached HEAD",

src/i18n/en.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -565,15 +565,6 @@ export const en = {
565565
"🎤 Voice recognition is not configured.\n\nSet STT_API_URL and STT_API_KEY in .env to enable it.",
566566
"stt.error": "🔴 Failed to recognize audio: {error}",
567567
"stt.empty_result": "🎤 No speech detected in the audio message.",
568-
"stt.confirm_message": "🎤 Recognized text:\n{text}\n\nSend, edit, or cancel?",
569-
"stt.confirm_send": "✅ Send",
570-
"stt.confirm_edit": "✏️ Edit",
571-
"stt.confirm_cancel": "❌ Cancel",
572-
"stt.confirm_sending": "✅ Sending recognized text as prompt...",
573-
"stt.confirm_edit_prompt": "✏️ Send the corrected text:",
574-
"stt.confirm_edit_sending": "✅ Sending edited text as prompt...",
575-
"stt.confirm_cancelled": "❌ Voice message cancelled.",
576-
"stt.confirm_inactive": "This voice message is no longer active.",
577568

578569
"cmd.description.open": "Add a project by browsing directories",
579570
"worktree.branch_detached": "detached HEAD",

src/i18n/es.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -584,18 +584,9 @@ export const es: I18nDictionary = {
584584
"stt.recognizing": "🎤 Reconociendo audio...",
585585
"stt.recognized": "🎤 Reconocido:\n{text}",
586586
"stt.not_configured":
587-
"🎤 El reconocimiento de voz no está configurado.\n\nConfigura STT_API_URL y STT_API_KEY en .env.",
587+
"🎤 El reconocimiento de voz no está configurado.\n\nConfigura STT_API_URL y STT_API_KEY en .env para habilitarlo.",
588588
"stt.error": "🔴 No se pudo reconocer el audio: {error}",
589589
"stt.empty_result": "🎤 No se detectó voz en el mensaje de audio.",
590-
"stt.confirm_message": "🎤 Texto reconocido:\n{text}\n\n¿Enviar, editar o cancelar?",
591-
"stt.confirm_send": "✅ Enviar",
592-
"stt.confirm_edit": "✏️ Editar",
593-
"stt.confirm_cancel": "❌ Cancelar",
594-
"stt.confirm_sending": "✅ Enviando texto reconocido como prompt...",
595-
"stt.confirm_edit_prompt": "✏️ Envía el texto corregido:",
596-
"stt.confirm_edit_sending": "✅ Enviando texto editado como prompt...",
597-
"stt.confirm_cancelled": "❌ Mensaje de voz cancelado.",
598-
"stt.confirm_inactive": "Este mensaje de voz ya no está activo.",
599590

600591
"cmd.description.open": "Añadir proyecto navegando directorios",
601592
"worktree.branch_detached": "detached HEAD",

src/i18n/fr.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -586,18 +586,9 @@ export const fr: I18nDictionary = {
586586
"stt.recognizing": "🎤 Reconnaissance audio en cours...",
587587
"stt.recognized": "🎤 Reconnu :\n{text}",
588588
"stt.not_configured":
589-
"🎤 La reconnaissance vocale n'est pas configurée.\n\nDéfinissez STT_API_URL et STT_API_KEY dans .env.",
589+
"🎤 La reconnaissance vocale n'est pas configurée.\n\nDéfinissez STT_API_URL et STT_API_KEY dans .env pour l'activer.",
590590
"stt.error": "🔴 Impossible de reconnaître l'audio : {error}",
591591
"stt.empty_result": "🎤 Aucune parole détectée dans le message audio.",
592-
"stt.confirm_message": "🎤 Texte reconnu :\n{text}\n\nEnvoyer, modifier ou annuler ?",
593-
"stt.confirm_send": "✅ Envoyer",
594-
"stt.confirm_edit": "✏️ Modifier",
595-
"stt.confirm_cancel": "❌ Annuler",
596-
"stt.confirm_sending": "✅ Envoi du texte reconnu comme prompt...",
597-
"stt.confirm_edit_prompt": "✏️ Envoyez le texte corrigé :",
598-
"stt.confirm_edit_sending": "✅ Envoi du texte modifié comme prompt...",
599-
"stt.confirm_cancelled": "❌ Message vocal annulé.",
600-
"stt.confirm_inactive": "Ce message vocal n'est plus actif.",
601592

602593
"cmd.description.open": "Ajouter un projet en parcourant les dossiers",
603594
"worktree.branch_detached": "detached HEAD",

src/i18n/ru.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -570,18 +570,9 @@ export const ru: I18nDictionary = {
570570
"stt.recognizing": "🎤 Распознаю аудио...",
571571
"stt.recognized": "🎤 Распознано:\n{text}",
572572
"stt.not_configured":
573-
"🎤 Распознавание речи не настроено.\n\nУкажите STT_API_URL и STT_API_KEY в .env.",
573+
"🎤 Распознавание голоса не настроено.\n\nУстановите STT_API_URL и STT_API_KEY в .env для включения.",
574574
"stt.error": "🔴 Не удалось распознать аудио: {error}",
575575
"stt.empty_result": "🎤 В аудиосообщении не обнаружена речь.",
576-
"stt.confirm_message": "🎤 Распознанный текст:\n{text}\n\nОтправить, редактировать или отменить?",
577-
"stt.confirm_send": "✅ Отправить",
578-
"stt.confirm_edit": "✏️ Редактировать",
579-
"stt.confirm_cancel": "❌ Отменить",
580-
"stt.confirm_sending": "✅ Отправка распознанного текста как промпта...",
581-
"stt.confirm_edit_prompt": "✏️ Отправьте исправленный текст:",
582-
"stt.confirm_edit_sending": "✅ Отправка отредактированного текста как промпта...",
583-
"stt.confirm_cancelled": "❌ Голосовое сообщение отменено.",
584-
"stt.confirm_inactive": "Это голосовое сообщение больше не активно.",
585576

586577
"cmd.description.open": "Добавить проект через обзор папок",
587578
"worktree.branch_detached": "detached HEAD",

0 commit comments

Comments
 (0)