fix: parse invite code without query params

This commit is contained in:
devlikepro committed 2026-09-16 10:54:18 +07:00
1 parent 4f0b255b96
commit d86ea302cb
2 files changed
+35 -5

No files matched your search

+26 -1
View File
@@ -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);
});
});
+9 -4
View File
@@ -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) {