mirror of https://github.com/openclaw/openclaw.git
Runtime: remove dead telegram typing lease
This commit is contained in:
parent
c842ca0166
commit
b33a18e280
|
|
@ -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<unknown>,
|
||||
) {
|
||||
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,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -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<unknown>;
|
||||
};
|
||||
|
||||
export async function createTelegramTypingLease(params: CreateTelegramTypingLeaseParams): Promise<{
|
||||
refresh: () => Promise<void>;
|
||||
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);
|
||||
},
|
||||
};
|
||||
}
|
||||
Loading…
Reference in New Issue