refactor(telegram): extract runner config and key helper

This commit is contained in:
Peter Steinberger
2026-01-07 22:16:49 +01:00
parent 98d4e8034d
commit 322c5dd936
4 changed files with 56 additions and 47 deletions

View File

@@ -1,4 +1,5 @@
import { run } from "@grammyjs/runner";
import { type RunOptions, run } from "@grammyjs/runner";
import type { ClawdbotConfig } from "../config/config.js";
import { loadConfig } from "../config/config.js";
import type { RuntimeEnv } from "../runtime.js";
import { createTelegramBot } from "./bot.js";
@@ -18,6 +19,22 @@ export type MonitorTelegramOpts = {
webhookUrl?: string;
};
export function createTelegramRunnerOptions(
cfg: ClawdbotConfig,
): RunOptions<unknown> {
return {
sink: {
concurrency: cfg.agent?.maxConcurrent ?? 1,
},
runner: {
fetch: {
// Match grammY defaults
timeout: 30,
},
},
};
}
export async function monitorTelegramProvider(opts: MonitorTelegramOpts = {}) {
const cfg = loadConfig();
const { token } = resolveTelegramToken(cfg, {
@@ -39,6 +56,7 @@ export async function monitorTelegramProvider(opts: MonitorTelegramOpts = {}) {
token,
runtime: opts.runtime,
proxyFetch,
config: cfg,
});
if (opts.useWebhook) {
@@ -56,17 +74,7 @@ export async function monitorTelegramProvider(opts: MonitorTelegramOpts = {}) {
}
// Use grammyjs/runner for concurrent update processing
const runner = run(bot, {
sink: {
concurrency: cfg.agent?.maxConcurrent ?? 1,
},
runner: {
fetch: {
// Match grammY defaults
timeout: 30,
},
},
});
const runner = run(bot, createTelegramRunnerOptions(cfg));
const stopOnAbort = () => {
if (opts.abortSignal?.aborted) {