diff --git a/CHANGELOG.md b/CHANGELOG.md index 07697d138..fceb6f4ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Group chat activation modes: per-group `/activation mention|always` command with status visibility. ### Fixes +- WhatsApp send now preserves existing JIDs (including group `@g.us`) instead of coercing to `@s.whatsapp.net`. (Thanks @arun-8687.) - Telegram/WhatsApp: native replies now target the original inbound message; reply context is appended to `Body` and captured in `ReplyTo*` fields. (Thanks @joshp123 for the PR and follow-up question.) - WhatsApp web creds persistence hardened; credentials are restored before auth checks and QR login auto-restarts if it stalls. - Canvas defaults/A2UI auto-nav aligned; debug status overlay centered; redundant await removed in `CanvasManager`. diff --git a/src/index.test.ts b/src/index.test.ts index 79ac604d4..246f46e1c 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -15,6 +15,12 @@ describe("toWhatsappJid", () => { it("converts E164 to jid", () => { expect(toWhatsappJid("+1 555 555 0123")).toBe("15555550123@s.whatsapp.net"); }); + + it("keeps group JIDs intact", () => { + expect(toWhatsappJid("123456789-987654321@g.us")).toBe( + "123456789-987654321@g.us", + ); + }); }); describe("assertProvider", () => { diff --git a/src/utils.test.ts b/src/utils.test.ts index deacb1c5e..fdd232fdd 100644 --- a/src/utils.test.ts +++ b/src/utils.test.ts @@ -69,6 +69,18 @@ describe("normalizeE164 & toWhatsappJid", () => { "5551234567@s.whatsapp.net", ); }); + + it("preserves existing JIDs", () => { + expect(toWhatsappJid("123456789-987654321@g.us")).toBe( + "123456789-987654321@g.us", + ); + expect(toWhatsappJid("whatsapp:123456789-987654321@g.us")).toBe( + "123456789-987654321@g.us", + ); + expect(toWhatsappJid("1555123@s.whatsapp.net")).toBe( + "1555123@s.whatsapp.net", + ); + }); }); describe("jidToE164", () => { diff --git a/src/utils.ts b/src/utils.ts index c629c00a1..21a7a2bdc 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -54,7 +54,9 @@ export function isSelfChatMode( } export function toWhatsappJid(number: string): string { - const e164 = normalizeE164(number); + const withoutPrefix = number.replace(/^whatsapp:/, "").trim(); + if (withoutPrefix.includes("@")) return withoutPrefix; + const e164 = normalizeE164(withoutPrefix); const digits = e164.replace(/\D/g, ""); return `${digits}@s.whatsapp.net`; } diff --git a/src/web/inbound.ts b/src/web/inbound.ts index 239cb1f93..71010684c 100644 --- a/src/web/inbound.ts +++ b/src/web/inbound.ts @@ -13,7 +13,12 @@ import { loadConfig } from "../config/config.js"; import { isVerbose, logVerbose } from "../globals.js"; import { createSubsystemLogger, getChildLogger } from "../logging.js"; import { saveMediaBuffer } from "../media/store.js"; -import { isSelfChatMode, jidToE164, normalizeE164 } from "../utils.js"; +import { + isSelfChatMode, + jidToE164, + normalizeE164, + toWhatsappJid, +} from "../utils.js"; import { createWaSocket, getStatusCode, @@ -336,7 +341,7 @@ export async function monitorWebInbox(options: { mediaBuffer?: Buffer, mediaType?: string, ): Promise<{ messageId: string }> => { - const jid = `${to.replace(/^\+/, "")}@s.whatsapp.net`; + const jid = toWhatsappJid(to); let payload: AnyMessageContent; if (mediaBuffer && mediaType) { if (mediaType.startsWith("image/")) { @@ -376,7 +381,7 @@ export async function monitorWebInbox(options: { * Used after IPC send to show more messages are coming. */ sendComposingTo: async (to: string): Promise => { - const jid = `${to.replace(/^\+/, "")}@s.whatsapp.net`; + const jid = toWhatsappJid(to); await sock.sendPresenceUpdate("composing", jid); }, } as const;