feat: unify directory across channels

This commit is contained in:
Peter Steinberger
2026-01-16 22:05:53 +00:00
parent 929b86e302
commit e44f28bd4f
7 changed files with 372 additions and 18 deletions

View File

@@ -215,6 +215,45 @@ export const whatsappPlugin: ChannelPlugin<ResolvedWhatsAppAccount> = {
messaging: {
normalizeTarget: normalizeWhatsAppMessagingTarget,
},
directory: {
self: async ({ cfg, accountId }) => {
const account = resolveWhatsAppAccount({ cfg, accountId });
const { e164, jid } = readWebSelfId(account.authDir);
const id = e164 ?? jid;
if (!id) return null;
return {
kind: "user",
id,
name: account.name,
raw: { e164, jid },
};
},
listPeers: async ({ cfg, accountId, query, limit }) => {
const account = resolveWhatsAppAccount({ cfg, accountId });
const q = query?.trim().toLowerCase() || "";
const peers = (account.allowFrom ?? [])
.map((entry) => String(entry).trim())
.filter((entry) => Boolean(entry) && entry !== "*")
.map((entry) => normalizeWhatsAppTarget(entry) ?? "")
.filter(Boolean)
.filter((id) => !isWhatsAppGroupJid(id))
.filter((id) => (q ? id.toLowerCase().includes(q) : true))
.slice(0, limit && limit > 0 ? limit : undefined)
.map((id) => ({ kind: "user", id }) as const);
return peers;
},
listGroups: async ({ cfg, accountId, query, limit }) => {
const account = resolveWhatsAppAccount({ cfg, accountId });
const q = query?.trim().toLowerCase() || "";
const groups = Object.keys(account.groups ?? {})
.map((id) => id.trim())
.filter((id) => Boolean(id) && id !== "*")
.filter((id) => (q ? id.toLowerCase().includes(q) : true))
.slice(0, limit && limit > 0 ? limit : undefined)
.map((id) => ({ kind: "group", id }) as const);
return groups;
},
},
actions: {
listActions: ({ cfg }) => {
if (!cfg.channels?.whatsapp) return [];