diff --git a/src/plugins/runtime/runtime-telegram-typing.test.ts b/src/plugins/runtime/runtime-telegram-typing.test.ts deleted file mode 100644 index ff0ef32111e..00000000000 --- a/src/plugins/runtime/runtime-telegram-typing.test.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { afterEach, describe, it, vi } from "vitest"; -import { createTelegramTypingLease } from "./runtime-telegram-typing.js"; -import { - expectDefaultTypingLeaseInterval, - registerSharedTypingLeaseTests, -} from "./typing-lease.test-support.js"; - -const TELEGRAM_TYPING_INTERVAL_MS = 2_000; -const TELEGRAM_TYPING_DEFAULT_INTERVAL_MS = 4_000; - -function buildTelegramTypingParams( - pulse: (params: { - to: string; - accountId?: string; - cfg?: unknown; - messageThreadId?: number; - }) => Promise, -) { - return { - to: "telegram:123", - intervalMs: TELEGRAM_TYPING_INTERVAL_MS, - pulse, - }; -} - -describe("createTelegramTypingLease", () => { - afterEach(() => { - vi.useRealTimers(); - }); - - registerSharedTypingLeaseTests({ - createLease: createTelegramTypingLease, - buildParams: buildTelegramTypingParams, - }); - - it("falls back to the default interval for non-finite values", async () => { - await expectDefaultTypingLeaseInterval({ - createLease: createTelegramTypingLease, - buildParams: buildTelegramTypingParams, - defaultIntervalMs: TELEGRAM_TYPING_DEFAULT_INTERVAL_MS, - }); - }); -}); diff --git a/src/plugins/runtime/runtime-telegram-typing.ts b/src/plugins/runtime/runtime-telegram-typing.ts deleted file mode 100644 index 3a10d5f38d1..00000000000 --- a/src/plugins/runtime/runtime-telegram-typing.ts +++ /dev/null @@ -1,60 +0,0 @@ -import type { OpenClawConfig } from "../../config/config.js"; -import { logWarn } from "../../logger.js"; - -export type CreateTelegramTypingLeaseParams = { - to: string; - accountId?: string; - cfg?: OpenClawConfig; - intervalMs?: number; - messageThreadId?: number; - pulse: (params: { - to: string; - accountId?: string; - cfg?: OpenClawConfig; - messageThreadId?: number; - }) => Promise; -}; - -export async function createTelegramTypingLease(params: CreateTelegramTypingLeaseParams): Promise<{ - refresh: () => Promise; - stop: () => void; -}> { - const intervalMs = - typeof params.intervalMs === "number" && Number.isFinite(params.intervalMs) - ? Math.max(1_000, Math.floor(params.intervalMs)) - : 4_000; - let stopped = false; - - const refresh = async () => { - if (stopped) { - return; - } - await params.pulse({ - to: params.to, - accountId: params.accountId, - cfg: params.cfg, - messageThreadId: params.messageThreadId, - }); - }; - - await refresh(); - - const timer = setInterval(() => { - // Background lease refreshes must never escape as unhandled rejections. - void refresh().catch((err) => { - logWarn(`plugins: telegram typing pulse failed: ${String(err)}`); - }); - }, intervalMs); - timer.unref?.(); - - return { - refresh, - stop: () => { - if (stopped) { - return; - } - stopped = true; - clearInterval(timer); - }, - }; -}