openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
35 lines (34 loc) • 1.24 kB
JavaScript
//#region src/infra/channel-activity.ts
const activity = /* @__PURE__ */ new Map();
function keyFor(channel, accountId) {
return `${channel}:${accountId || "default"}`;
}
function ensureEntry(channel, accountId) {
const key = keyFor(channel, accountId);
const existing = activity.get(key);
if (existing) return existing;
const created = {
inboundAt: null,
outboundAt: null
};
activity.set(key, created);
return created;
}
/** Records the latest inbound or outbound activity timestamp for a channel/account. */
function recordChannelActivity(params) {
const at = typeof params.at === "number" ? params.at : Date.now();
const accountId = params.accountId?.trim() || "default";
const entry = ensureEntry(params.channel, accountId);
if (params.direction === "inbound") entry.inboundAt = at;
if (params.direction === "outbound") entry.outboundAt = at;
}
/** Returns the latest known inbound/outbound activity timestamps for a channel/account. */
function getChannelActivity(params) {
const accountId = params.accountId?.trim() || "default";
return activity.get(keyFor(params.channel, accountId)) ?? {
inboundAt: null,
outboundAt: null
};
}
//#endregion
export { recordChannelActivity as n, getChannelActivity as t };