feat(whatsapp): implement fetchLatestWaWebVersion utility and update version fetching logic

- Added a new utility function `fetchLatestWaWebVersion` to retrieve the latest WhatsApp Web version.
- Updated the Baileys service and router to utilize the new function instead of the deprecated `fetchLatestBaileysVersion`, ensuring accurate version information is fetched for WhatsApp integration.
- This change enhances the reliability of version management in the application.
This commit is contained in:
Davidson Gomes
2025-06-13 13:14:35 -03:00
parent 22c379aa36
commit ae99ec7a0e
3 changed files with 41 additions and 4 deletions

View File

@@ -0,0 +1,37 @@
import axios, { AxiosRequestConfig } from 'axios';
import { fetchLatestBaileysVersion, WAVersion } from 'baileys';
export const fetchLatestWaWebVersion = async (options: AxiosRequestConfig<{}>) => {
try {
const { data } = await axios.get('https://web.whatsapp.com/sw.js', {
...options,
responseType: 'json',
});
const regex = /\\?"client_revision\\?":\s*(\d+)/;
const match = data.match(regex);
if (!match?.[1]) {
return {
version: (await fetchLatestBaileysVersion()).version as WAVersion,
isLatest: false,
error: {
message: 'Could not find client revision in the fetched content',
},
};
}
const clientRevision = match[1];
return {
version: [2, 3000, +clientRevision] as WAVersion,
isLatest: true,
};
} catch (error) {
return {
version: (await fetchLatestBaileysVersion()).version as WAVersion,
isLatest: false,
error,
};
}
};