mirror of https://github.com/openclaw/openclaw.git
refactor(whatsapp): move legacy group session detection into contract surface
This commit is contained in:
parent
098abd484d
commit
f25f147fc3
|
|
@ -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[] {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue