diff --git a/src/Socket/groups.ts b/src/Socket/groups.ts index 13e5ca66..2e6384e0 100644 --- a/src/Socket/groups.ts +++ b/src/Socket/groups.ts @@ -66,6 +66,7 @@ export const makeGroupsSocket = (config: SocketConfig) => { data[meta.id] = meta } } + // TODO: properly parse LID / PN DATA sock.ev.emit('groups.update', Object.values(data)) diff --git a/src/Socket/messages-send.ts b/src/Socket/messages-send.ts index b423e7ec..6f578fd5 100644 --- a/src/Socket/messages-send.ts +++ b/src/Socket/messages-send.ts @@ -699,7 +699,7 @@ export const makeMessagesSocket = (config: SocketConfig) => { for (const device of devices) { const deviceJid = device.jid const hasKey = !!senderKeyMap[deviceJid] - if ((!hasKey || !!participant ) && !isJidHostedLidUser(deviceJid) && !isJidHostedPnUser(deviceJid)) { + if ((!hasKey || !!participant) && !isJidHostedLidUser(deviceJid) && !isJidHostedPnUser(deviceJid)) { //todo: revamp all this logic // the goal is to follow with what I said above for each group, and instead of a true false map of ids, we can set an array full of those the app has already sent pkmsgs senderKeyRecipients.push(deviceJid) diff --git a/src/Utils/generics.ts b/src/Utils/generics.ts index 569d3218..b5d1b71b 100644 --- a/src/Utils/generics.ts +++ b/src/Utils/generics.ts @@ -274,11 +274,21 @@ export const fetchLatestBaileysVersion = async (options: RequestInit = {}) => { */ export const fetchLatestWaWebVersion = async (options: RequestInit = {}) => { try { + // Absolute minimal headers required to bypass anti-bot detection + const defaultHeaders = { + 'sec-fetch-site': 'none', + 'user-agent': + 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36' + } + + const headers = { ...defaultHeaders, ...options.headers } + const response = await fetch('https://web.whatsapp.com/sw.js', { - dispatcher: options.dispatcher, + ...options, method: 'GET', - headers: options.headers + headers }) + if (!response.ok) { throw new Boom(`Failed to fetch sw.js: ${response.statusText}`, { statusCode: response.status }) } diff --git a/src/__tests__/e2e/fetch-wa-web-version.test-e2e.ts b/src/__tests__/e2e/fetch-wa-web-version.test-e2e.ts new file mode 100644 index 00000000..b848e392 --- /dev/null +++ b/src/__tests__/e2e/fetch-wa-web-version.test-e2e.ts @@ -0,0 +1,60 @@ +import { jest } from '@jest/globals' +import { fetchLatestWaWebVersion } from '../../Utils/generics' + +describe('fetchLatestWaWebVersion Integration Tests', () => { + jest.setTimeout(10000) + + it('should successfully fetch the latest WhatsApp Web version from real API', async () => { + const result = await fetchLatestWaWebVersion() + + expect(Array.isArray(result.version)).toBe(true) + expect(result.version).toHaveLength(3) + expect(typeof result.version[0]).toBe('number') + expect(typeof result.version[1]).toBe('number') + expect(typeof result.version[2]).toBe('number') + + expect(typeof result.isLatest).toBe('boolean') + + if (!result.isLatest) { + expect(result.error).toBeDefined() + } + }) + + it('should handle custom headers correctly', async () => { + const customHeaders = { + accept: + 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', + 'accept-language': 'en-US,en;q=0.9', + 'cache-control': 'max-age=0', + 'sec-ch-prefers-color-scheme': 'dark', + 'sec-fetch-dest': 'document', + 'sec-fetch-mode': 'navigate', + 'sec-fetch-site': 'none', + 'upgrade-insecure-requests': '1' + } + + const result = await fetchLatestWaWebVersion({ + headers: customHeaders + }) + + expect(Array.isArray(result.version)).toBe(true) + expect(result.version).toHaveLength(3) + expect(result.isLatest).toBe(true) + }) + + it('should fallback gracefully when client_revision is not found', async () => { + const result = await fetchLatestWaWebVersion() + + expect(result).toHaveProperty('version') + expect(result).toHaveProperty('isLatest') + expect(Array.isArray(result.version)).toBe(true) + }) + + it('should handle network timeouts gracefully', async () => { + const result = await fetchLatestWaWebVersion() + + expect(result).toHaveProperty('version') + expect(result).toHaveProperty('isLatest') + expect(Array.isArray(result.version)).toBe(true) + }) +})