Files
openclaw/extensions/telegram/src/webhook-status.ts
Peter Steinberger f9d9d1225a refactor(channels): own the lifecycle status contract in SDK patch factories (#118795)
* refactor(sdk): add channel lifecycle patch factories

* refactor(channels): adopt lifecycle patches in a-m

* refactor(channels): adopt lifecycle patches in n-z

* refactor(runtime): lifecycle-own ambient registries

* test(slack): assert lifecycle factory fields

* fix(sdk): preserve lifecycle patch extras types

* test(zalouser): widen lifecycle status sink

* test(irc): avoid shadowed status patch

* fix(zalo): reuse account-agnostic media route

* fix(gateway): accept explicit channel ready recovery

* test(qa): assert terminal Slack block fact

* test(qa): restore Slack blocked lifecycle scenario

* test(gateway): lock explicit lifecycle recovery contract
2026-08-03 12:39:48 -07:00

56 lines
1.5 KiB
TypeScript

// Telegram plugin module implements webhook status behavior.
import type { ChannelAccountSnapshot } from "openclaw/plugin-sdk/channel-contract";
import { channelReadyPatch } from "openclaw/plugin-sdk/gateway-runtime";
type TelegramWebhookStatusSink = (patch: Omit<ChannelAccountSnapshot, "accountId">) => void;
export function createTelegramWebhookStatusPublisher(setStatus?: TelegramWebhookStatusSink) {
return {
noteWebhookStart() {
setStatus?.({
mode: "webhook",
connected: false,
lastConnectedAt: null,
lastEventAt: null,
lastTransportActivityAt: null,
});
},
noteWebhookAdvertised(at = Date.now()) {
setStatus?.(
channelReadyPatch({
lastConnectedAt: at,
lastEventAt: at,
mode: "webhook",
}),
);
},
noteWebhookUpdateReceived(at = Date.now()) {
setStatus?.(
channelReadyPatch({
lastConnectedAt: at,
lastEventAt: at,
mode: "webhook",
}),
);
},
noteWebhookRecovery() {
setStatus?.({ lifecycle: "recovering" });
},
noteWebhookRegistrationFailure(error: string, lifecycle?: "recovering" | "blocked") {
setStatus?.({
mode: "webhook",
connected: false,
...(lifecycle ? { lifecycle } : {}),
...(lifecycle === "blocked" ? { terminalDisconnect: true } : {}),
lastError: error,
});
},
noteWebhookStop() {
setStatus?.({
mode: "webhook",
connected: false,
});
},
};
}