diff --git a/src/bridge.ts b/src/bridge.ts index fdf7389..f338244 100644 --- a/src/bridge.ts +++ b/src/bridge.ts @@ -17,6 +17,7 @@ export interface TelegramBridgeOptions { provider?: string model?: string maxMessageLength?: number + pollingTimeoutSec?: number cwd?: string } @@ -63,7 +64,9 @@ export class TelegramBridge { this.token = options.token this.allowedUserIds = options.allowedUserIds this.allowAllUsers = options.allowAllUsers - this.client = options.client ?? new TelegramClient(options.token) + this.client = options.client ?? new TelegramClient(options.token, { + pollingTimeoutSec: options.pollingTimeoutSec ?? 30, + }) this.sleep = options.sleep ?? defaultSleep this.provider = options.provider ?? 'deepseek-official' this.model = options.model ?? 'deepseek-v4-flash' diff --git a/src/index.ts b/src/index.ts index 6b2b5a7..742d971 100644 --- a/src/index.ts +++ b/src/index.ts @@ -44,6 +44,7 @@ export function apply(ctx: Context, config: TelegramChannelConfig): void { provider: config.provider ?? 'deepseek-official', model: config.model ?? 'deepseek-v4-flash', maxMessageLength: config.maxMessageLength ?? 4096, + pollingTimeoutSec: config.pollingTimeoutSec ?? 30, cwd: config.cwd ?? process.cwd(), }) ctx.effect(() => { diff --git a/tests/bridge.test.ts b/tests/bridge.test.ts index dd7934f..0409b44 100644 --- a/tests/bridge.test.ts +++ b/tests/bridge.test.ts @@ -315,3 +315,32 @@ test('stop disposes all chat handles', async () => { await bridge.stop() assert.equal(track.disposeCount, 2) }) + +test('default client uses pollingTimeoutSec from bridge options', async () => { + const calls: Array<{ body: unknown }> = [] + const originalFetch = globalThis.fetch + globalThis.fetch = async (_input, init) => { + calls.push({ body: JSON.parse(String(init?.body)) }) + return new Response(JSON.stringify({ ok: true, result: [] }), { status: 200 }) + } + try { + const bridge = new TelegramBridge(bridgeCtx(fakeAgents({ + createCount: 0, + disposeCount: 0, + sessionIds: [], + followups: [], + })) as never, { + token: 'SECRET-TOKEN', + allowedUserIds: [1], + allowAllUsers: false, + pollingTimeoutSec: 15, + sleep: async () => {}, + }) + bridge.start() + await new Promise((resolve) => setTimeout(resolve, 80)) + await bridge.stop() + assert.ok(calls.some((call) => (call.body as { timeout?: number }).timeout === 15)) + } finally { + globalThis.fetch = originalFetch + } +})