fix: preserve whatsapp group JIDs

This commit is contained in:
Peter Steinberger
2025-12-23 03:05:59 +01:00
parent fc4a395c88
commit 4af08b1606
5 changed files with 30 additions and 4 deletions

View File

@@ -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`.

View File

@@ -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", () => {

View File

@@ -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", () => {

View File

@@ -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`;
}

View File

@@ -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<void> => {
const jid = `${to.replace(/^\+/, "")}@s.whatsapp.net`;
const jid = toWhatsappJid(to);
await sock.sendPresenceUpdate("composing", jid);
},
} as const;