From d86ea302cb8a6e888a1716e78dd3de5c27ad7126 Mon Sep 17 00:00:00 2001 From: devlikepro Date: Wed, 16 Sep 2026 10:54:18 +0700 Subject: [PATCH] fix: parse invite code without query params --- src/core/abc/session.abc.test.ts | 27 ++++++++++++++++++++++++++- src/core/abc/session.abc.ts | 13 +++++++++---- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/core/abc/session.abc.test.ts b/src/core/abc/session.abc.test.ts index 3fee30c6..b9452038 100644 --- a/src/core/abc/session.abc.test.ts +++ b/src/core/abc/session.abc.test.ts @@ -1,4 +1,8 @@ -import { WhatsappSession } from '@waha/core/abc/session.abc'; +import { + parseChannelInviteLink, + parseGroupInviteLink, + WhatsappSession, +} from '@waha/core/abc/session.abc'; import { WAHAEvents, WAHASessionStatus } from '@waha/structures/enums.dto'; import { MeInfo, @@ -161,3 +165,24 @@ describe('WhatsappSession reachout timelock', () => { } }); }); + +describe('parseGroupInviteLink', () => { + it.each([ + ['AbCdEf123', 'AbCdEf123'], + ['https://chat.whatsapp.com/AbCdEf123', 'AbCdEf123'], + ['https://chat.whatsapp.com/AbCdEf123?s=sw&p=a&mlu=4&ilr=4', 'AbCdEf123'], + ['https://chat.whatsapp.com/AbCdEf123#ref', 'AbCdEf123'], + ['AbCdEf123?s=sw', 'AbCdEf123'], + ])('%s => %s', (link, code) => { + expect(parseGroupInviteLink(link)).toBe(code); + }); +}); + +describe('parseChannelInviteLink', () => { + it.each([ + ['https://whatsapp.com/channel/AbCdEf123', 'AbCdEf123'], + ['https://www.whatsapp.com/channel/AbCdEf123?utm=x', 'AbCdEf123'], + ])('%s => %s', (link, code) => { + expect(parseChannelInviteLink(link)).toBe(code); + }); +}); diff --git a/src/core/abc/session.abc.ts b/src/core/abc/session.abc.ts index 94bea98e..4ac708f3 100644 --- a/src/core/abc/session.abc.ts +++ b/src/core/abc/session.abc.ts @@ -1300,8 +1300,8 @@ export function getGroupInviteLink(code: string) { } export function parseGroupInviteLink(link: string) { - // https://chat.whatsapp.com/123 => 123 - return link.split('/').pop(); + // https://chat.whatsapp.com/123?s=sw&p=a => 123 + return parseInviteCode(link); } export function getChannelInviteLink(code: string) { @@ -1310,8 +1310,13 @@ export function getChannelInviteLink(code: string) { export function parseChannelInviteLink(link: string): string { // https://www.whatsapp.com/channel/123 => 123 - const code = link.split('/').pop(); - return code; + return parseInviteCode(link); +} + +function parseInviteCode(link: string): string { + // last path segment, without share tracking query params and hash + const path = link.split(/[?#]/)[0]; + return path.split('/').pop(); } export function getPublicUrlFromDirectPath(directPath: string) {