feat(telegram): use grammyjs/runner for concurrent update processing

Previously, grammY's default bot.start() processed updates sequentially,
blocking all Telegram messages while one was being handled. This made
maxConcurrent settings ineffective for Telegram.

Now uses @grammyjs/runner which processes updates concurrently, matching
the behavior of Discord (Promise.all) and WhatsApp (fire-and-forget).

Benefits:
- Ack reactions (👀) appear immediately, not after queue clears
- Multiple chats can be processed in parallel
- maxConcurrent setting now works correctly for Telegram
- Long-running tool calls no longer block other conversations
This commit is contained in:
Muhammed Mukhthar CM
2026-01-07 05:34:37 +00:00
committed by Peter Steinberger
parent febd2010af
commit 1a41fecf67
3 changed files with 32 additions and 3 deletions

View File

@@ -1,3 +1,4 @@
import { run } from "@grammyjs/runner";
import { loadConfig } from "../config/config.js";
import type { RuntimeEnv } from "../runtime.js";
import { createTelegramBot } from "./bot.js";
@@ -53,13 +54,26 @@ export async function monitorTelegramProvider(opts: MonitorTelegramOpts = {}) {
return;
}
// Long polling
// Use grammyjs/runner for concurrent update processing
const runner = run(bot, {
runner: {
fetch: {
// Match grammY defaults
timeout: 30,
},
},
});
const stopOnAbort = () => {
if (opts.abortSignal?.aborted) void bot.stop();
if (opts.abortSignal?.aborted) {
runner.stop();
}
};
opts.abortSignal?.addEventListener("abort", stopOnAbort, { once: true });
try {
await bot.start();
// runner.task() returns a promise that resolves when the runner stops
await runner.task();
} finally {
opts.abortSignal?.removeEventListener("abort", stopOnAbort);
}