Files
openclaw/extensions/telegram/src/webhook-status.ts
2026-04-29 15:40:44 +01:00

46 lines
1.2 KiB
TypeScript

import type { ChannelAccountSnapshot } from "openclaw/plugin-sdk/channel-contract";
import { createConnectedChannelStatusPatch } 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?.({
...createConnectedChannelStatusPatch(at),
mode: "webhook",
lastError: null,
});
},
noteWebhookUpdateReceived(at = Date.now()) {
setStatus?.({
...createConnectedChannelStatusPatch(at),
mode: "webhook",
lastError: null,
});
},
noteWebhookRegistrationFailure(error: string) {
setStatus?.({
mode: "webhook",
connected: false,
lastError: error,
});
},
noteWebhookStop() {
setStatus?.({
mode: "webhook",
connected: false,
});
},
};
}