Telegram: share thread binding runtime state

This commit is contained in:
Vincent Koc
2026-03-12 01:27:34 -04:00
parent 21a024e4f8
commit f1e03eafee

View File

@@ -62,8 +62,24 @@ export type TelegramThreadBindingManager = {
stop: () => void;
};
const MANAGERS_BY_ACCOUNT_ID = new Map<string, TelegramThreadBindingManager>();
const BINDINGS_BY_ACCOUNT_CONVERSATION = new Map<string, TelegramThreadBindingRecord>();
type TelegramThreadBindingsState = {
managersByAccountId: Map<string, TelegramThreadBindingManager>;
bindingsByAccountConversation: Map<string, TelegramThreadBindingRecord>;
};
/**
* Keep Telegram thread binding state shared across bundled chunks so routing,
* binding lookups, and binding mutations all observe the same live registry.
*/
const _g = globalThis as typeof globalThis & {
__openclaw_telegram_thread_bindings_state__?: TelegramThreadBindingsState;
};
const threadBindingsState = (_g.__openclaw_telegram_thread_bindings_state__ ??= {
managersByAccountId: new Map<string, TelegramThreadBindingManager>(),
bindingsByAccountConversation: new Map<string, TelegramThreadBindingRecord>(),
});
const MANAGERS_BY_ACCOUNT_ID = threadBindingsState.managersByAccountId;
const BINDINGS_BY_ACCOUNT_CONVERSATION = threadBindingsState.bindingsByAccountConversation;
function normalizeDurationMs(raw: unknown, fallback: number): number {
if (typeof raw !== "number" || !Number.isFinite(raw)) {