@gonzih/cc-tg 0.9.18 → 0.9.20
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/dist/bot.js +19 -2
- package/package.json +1 -1
package/dist/bot.js
CHANGED
|
@@ -29,6 +29,21 @@ const BOT_COMMANDS = [
|
|
|
29
29
|
{ command: "get_file", description: "Send a file from the server to this chat" },
|
|
30
30
|
{ command: "cost", description: "Show session token usage and cost" },
|
|
31
31
|
];
|
|
32
|
+
async function withRetry(fn, attempts, delays) {
|
|
33
|
+
for (let i = 0; i < attempts; i++) {
|
|
34
|
+
try {
|
|
35
|
+
return await fn();
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
if (i < attempts - 1) {
|
|
39
|
+
await new Promise(r => setTimeout(r, delays[i] ?? 2000));
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
throw e;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
throw new Error('unreachable');
|
|
46
|
+
}
|
|
32
47
|
const FLUSH_DELAY_MS = 800; // debounce streaming chunks into one Telegram message
|
|
33
48
|
const TYPING_INTERVAL_MS = 4000; // re-send typing action before Telegram's 5s expiry
|
|
34
49
|
// Claude Sonnet 4.6 pricing (per 1M tokens)
|
|
@@ -331,8 +346,10 @@ export class CcTgBot {
|
|
|
331
346
|
console.log(`[voice:${chatId}] received voice message, transcribing...`);
|
|
332
347
|
this.bot.sendChatAction(chatId, "typing").catch(() => { });
|
|
333
348
|
try {
|
|
334
|
-
const
|
|
335
|
-
|
|
349
|
+
const transcript = await withRetry(async () => {
|
|
350
|
+
const fileLink = await this.bot.getFileLink(fileId);
|
|
351
|
+
return transcribeVoice(fileLink);
|
|
352
|
+
}, 3, [2000, 5000]);
|
|
336
353
|
console.log(`[voice:${chatId}] transcribed: ${transcript}`);
|
|
337
354
|
if (!transcript || transcript === "[empty transcription]") {
|
|
338
355
|
await this.bot.sendMessage(chatId, "Could not transcribe voice message.");
|