mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 20:40:20 +00:00
fix(telegram): keep webhook monitor alive until abort
Co-authored-by: Evgeny Zislis <7056+kesor@users.noreply.github.com>
This commit is contained in:
@@ -286,6 +286,25 @@ describe("monitorTelegramProvider (grammY)", () => {
|
||||
expect(runSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("webhook mode waits for abort signal before returning", async () => {
|
||||
const abort = new AbortController();
|
||||
const settled = vi.fn();
|
||||
const monitor = monitorTelegramProvider({
|
||||
token: "tok",
|
||||
useWebhook: true,
|
||||
webhookUrl: "https://example.test/telegram",
|
||||
webhookSecret: "secret",
|
||||
abortSignal: abort.signal,
|
||||
}).then(settled);
|
||||
|
||||
await Promise.resolve();
|
||||
expect(settled).not.toHaveBeenCalled();
|
||||
|
||||
abort.abort();
|
||||
await monitor;
|
||||
expect(settled).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("falls back to configured webhookSecret when not passed explicitly", async () => {
|
||||
await monitorTelegramProvider({
|
||||
token: "tok",
|
||||
|
||||
@@ -178,6 +178,15 @@ export async function monitorTelegramProvider(opts: MonitorTelegramOpts = {}) {
|
||||
abortSignal: opts.abortSignal,
|
||||
publicUrl: opts.webhookUrl,
|
||||
});
|
||||
if (opts.abortSignal && !opts.abortSignal.aborted) {
|
||||
await new Promise<void>((resolve) => {
|
||||
const onAbort = () => {
|
||||
opts.abortSignal?.removeEventListener("abort", onAbort);
|
||||
resolve();
|
||||
};
|
||||
opts.abortSignal.addEventListener("abort", onAbort, { once: true });
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user