openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
170 lines (169 loc) • 5.28 kB
JavaScript
//#region src/channels/ids.ts
const CHAT_CHANNEL_ORDER = [
"telegram",
"whatsapp",
"discord",
"irc",
"googlechat",
"slack",
"signal",
"imessage",
"line"
];
const CHANNEL_IDS = [...CHAT_CHANNEL_ORDER];
//#endregion
//#region src/channels/registry.ts
const WEBSITE_URL = "https://openclaw.ai";
const REGISTRY_STATE = Symbol.for("openclaw.pluginRegistryState");
function listRegisteredChannelPluginEntries() {
return globalThis[REGISTRY_STATE]?.registry?.channels ?? [];
}
function findRegisteredChannelPluginEntry(normalizedKey) {
return listRegisteredChannelPluginEntries().find((entry) => {
const id = String(entry.plugin.id ?? "").trim().toLowerCase();
if (id && id === normalizedKey) return true;
return (entry.plugin.meta?.aliases ?? []).some((alias) => alias.trim().toLowerCase() === normalizedKey);
});
}
const CHAT_CHANNEL_META = {
telegram: {
id: "telegram",
label: "Telegram",
selectionLabel: "Telegram (Bot API)",
detailLabel: "Telegram Bot",
docsPath: "/channels/telegram",
docsLabel: "telegram",
blurb: "simplest way to get started — register a bot with @BotFather and get going.",
systemImage: "paperplane",
selectionDocsPrefix: "",
selectionDocsOmitLabel: true,
selectionExtras: [WEBSITE_URL]
},
whatsapp: {
id: "whatsapp",
label: "WhatsApp",
selectionLabel: "WhatsApp (QR link)",
detailLabel: "WhatsApp Web",
docsPath: "/channels/whatsapp",
docsLabel: "whatsapp",
blurb: "works with your own number; recommend a separate phone + eSIM.",
systemImage: "message"
},
discord: {
id: "discord",
label: "Discord",
selectionLabel: "Discord (Bot API)",
detailLabel: "Discord Bot",
docsPath: "/channels/discord",
docsLabel: "discord",
blurb: "very well supported right now.",
systemImage: "bubble.left.and.bubble.right"
},
irc: {
id: "irc",
label: "IRC",
selectionLabel: "IRC (Server + Nick)",
detailLabel: "IRC",
docsPath: "/channels/irc",
docsLabel: "irc",
blurb: "classic IRC networks with DM/channel routing and pairing controls.",
systemImage: "network"
},
googlechat: {
id: "googlechat",
label: "Google Chat",
selectionLabel: "Google Chat (Chat API)",
detailLabel: "Google Chat",
docsPath: "/channels/googlechat",
docsLabel: "googlechat",
blurb: "Google Workspace Chat app with HTTP webhook.",
systemImage: "message.badge"
},
slack: {
id: "slack",
label: "Slack",
selectionLabel: "Slack (Socket Mode)",
detailLabel: "Slack Bot",
docsPath: "/channels/slack",
docsLabel: "slack",
blurb: "supported (Socket Mode).",
systemImage: "number"
},
signal: {
id: "signal",
label: "Signal",
selectionLabel: "Signal (signal-cli)",
detailLabel: "Signal REST",
docsPath: "/channels/signal",
docsLabel: "signal",
blurb: "signal-cli linked device; more setup (David Reagans: \"Hop on Discord.\").",
systemImage: "antenna.radiowaves.left.and.right"
},
imessage: {
id: "imessage",
label: "iMessage",
selectionLabel: "iMessage (imsg)",
detailLabel: "iMessage",
docsPath: "/channels/imessage",
docsLabel: "imessage",
blurb: "this is still a work in progress.",
systemImage: "message.fill"
},
line: {
id: "line",
label: "LINE",
selectionLabel: "LINE (Messaging API)",
detailLabel: "LINE Bot",
docsPath: "/channels/line",
docsLabel: "line",
blurb: "LINE Messaging API webhook bot.",
systemImage: "message"
}
};
const CHAT_CHANNEL_ALIASES = {
imsg: "imessage",
"internet-relay-chat": "irc",
"google-chat": "googlechat",
gchat: "googlechat"
};
const normalizeChannelKey = (raw) => {
return raw?.trim().toLowerCase() || void 0;
};
function listChatChannels() {
return CHAT_CHANNEL_ORDER.map((id) => CHAT_CHANNEL_META[id]);
}
function getChatChannelMeta(id) {
return CHAT_CHANNEL_META[id];
}
function normalizeChatChannelId(raw) {
const normalized = normalizeChannelKey(raw);
if (!normalized) return null;
const resolved = CHAT_CHANNEL_ALIASES[normalized] ?? normalized;
return CHAT_CHANNEL_ORDER.includes(resolved) ? resolved : null;
}
function normalizeChannelId(raw) {
return normalizeChatChannelId(raw);
}
function normalizeAnyChannelId(raw) {
const key = normalizeChannelKey(raw);
if (!key) return null;
return findRegisteredChannelPluginEntry(key)?.plugin.id ?? null;
}
function listRegisteredChannelPluginIds() {
return listRegisteredChannelPluginEntries().flatMap((entry) => {
const id = entry.plugin.id?.trim();
return id ? [id] : [];
});
}
function formatChannelPrimerLine(meta) {
return `${meta.label}: ${meta.blurb}`;
}
function formatChannelSelectionLine(meta, docsLink) {
const docsPrefix = meta.selectionDocsPrefix ?? "Docs:";
const docsLabel = meta.docsLabel ?? meta.id;
const docs = meta.selectionDocsOmitLabel ? docsLink(meta.docsPath) : docsLink(meta.docsPath, docsLabel);
const extras = (meta.selectionExtras ?? []).filter(Boolean).join(" ");
return `${meta.label} — ${meta.blurb} ${docsPrefix ? `${docsPrefix} ` : ""}${docs}${extras ? ` ${extras}` : ""}`;
}
//#endregion
export { listRegisteredChannelPluginIds as a, normalizeChatChannelId as c, listChatChannels as i, CHANNEL_IDS as l, formatChannelSelectionLine as n, normalizeAnyChannelId as o, getChatChannelMeta as r, normalizeChannelId as s, formatChannelPrimerLine as t, CHAT_CHANNEL_ORDER as u };