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

@@ -85,6 +85,7 @@
"dependencies": {
"@buape/carbon": "0.0.0-beta-20260107085330",
"@clack/prompts": "^0.11.0",
"@grammyjs/runner": "^2.0.3",
"@grammyjs/transformer-throttler": "^1.2.1",
"@homebridge/ciao": "^1.3.4",
"@mariozechner/pi-agent-core": "^0.37.2",

14
pnpm-lock.yaml generated
View File

@@ -28,6 +28,9 @@ importers:
'@clack/prompts':
specifier: ^0.11.0
version: 0.11.0
'@grammyjs/runner':
specifier: ^2.0.3
version: 2.0.3(grammy@1.39.2)
'@grammyjs/transformer-throttler':
specifier: ^1.2.1
version: 1.2.1(grammy@1.39.2)
@@ -591,6 +594,12 @@ packages:
'@modelcontextprotocol/sdk':
optional: true
'@grammyjs/runner@2.0.3':
resolution: {integrity: sha512-nckmTs1dPWfVQteK9cxqxzE+0m1VRvluLWB8UgFzsjg62w3qthPJt0TYtJBEdG7OedvfQq4vnFAyE6iaMkR42A==}
engines: {node: '>=12.20.0 || >=14.13.1'}
peerDependencies:
grammy: ^1.13.1
'@grammyjs/transformer-throttler@1.2.1':
resolution: {integrity: sha512-CpWB0F3rJdUiKsq7826QhQsxbZi4wqfz1ccKX+fr+AOC+o8K7ZvS+wqX0suSu1QCsyUq2MDpNiKhyL2ZOJUS4w==}
engines: {node: ^12.20.0 || >=14.13.1}
@@ -3411,6 +3420,11 @@ snapshots:
- supports-color
- utf-8-validate
'@grammyjs/runner@2.0.3(grammy@1.39.2)':
dependencies:
abort-controller: 3.0.0
grammy: 1.39.2
'@grammyjs/transformer-throttler@1.2.1(grammy@1.39.2)':
dependencies:
bottleneck: 2.19.5

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);
}