From f25f147fc3ee519dbc27dbdce1388a7b027bab1d Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 4 Apr 2026 03:57:51 +0100 Subject: [PATCH] refactor(whatsapp): move legacy group session detection into contract surface --- extensions/whatsapp/contract-surfaces.ts | 2 ++ src/config/sessions/group.ts | 20 -------------------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/extensions/whatsapp/contract-surfaces.ts b/extensions/whatsapp/contract-surfaces.ts index 421fd8d6ac4..8ae1451fb40 100644 --- a/extensions/whatsapp/contract-surfaces.ts +++ b/extensions/whatsapp/contract-surfaces.ts @@ -12,6 +12,8 @@ export const unsupportedSecretRefSurfacePatterns = [ "channels.whatsapp.accounts.*.creds.json", ] as const; +export { resolveLegacyGroupSessionKey } from "./src/group-session-contract.js"; + export function collectUnsupportedSecretRefConfigCandidates( raw: unknown, ): UnsupportedSecretRefConfigCandidate[] { diff --git a/src/config/sessions/group.ts b/src/config/sessions/group.ts index 478525ff7e4..d0fc59fbc93 100644 --- a/src/config/sessions/group.ts +++ b/src/config/sessions/group.ts @@ -10,15 +10,6 @@ type LegacyGroupSessionSurface = { resolveLegacyGroupSessionKey?: (ctx: MsgContext) => GroupKeyResolution | null; }; -function resolveLegacyWhatsAppGroupId(from: string): string | null { - const candidate = from.trim().replace(/^whatsapp:/i, ""); - if (!candidate.toLowerCase().endsWith("@g.us")) { - return null; - } - const localPart = candidate.slice(0, candidate.length - "@g.us".length); - return /^[0-9]+(-[0-9]+)*$/i.test(localPart) ? `${localPart}@g.us` : null; -} - function resolveLegacyGroupSessionKey(ctx: MsgContext): GroupKeyResolution | null { for (const surface of getBundledChannelContractSurfaces() as LegacyGroupSessionSurface[]) { const resolved = surface.resolveLegacyGroupSessionKey?.(ctx); @@ -80,7 +71,6 @@ export function resolveGroupSessionKey(ctx: MsgContext): GroupKeyResolution | nu const chatType = ctx.ChatType?.trim().toLowerCase(); const normalizedChatType = chatType === "channel" ? "channel" : chatType === "group" ? "group" : undefined; - const legacyWhatsAppGroupId = resolveLegacyWhatsAppGroupId(from); const legacyResolution = resolveLegacyGroupSessionKey(ctx); const looksLikeGroup = @@ -88,7 +78,6 @@ export function resolveGroupSessionKey(ctx: MsgContext): GroupKeyResolution | nu normalizedChatType === "channel" || from.includes(":group:") || from.includes(":channel:") || - legacyWhatsAppGroupId !== null || legacyResolution !== null; if (!looksLikeGroup) { return null; @@ -104,15 +93,6 @@ export function resolveGroupSessionKey(ctx: MsgContext): GroupKeyResolution | nu return legacyResolution; } - if (!headIsSurface && legacyWhatsAppGroupId) { - return { - key: `whatsapp:group:${legacyWhatsAppGroupId}`, - channel: "whatsapp", - id: legacyWhatsAppGroupId, - chatType: "group", - }; - } - const provider = headIsSurface ? head : (providerHint ?? legacyResolution?.channel); if (!provider) { return null;