mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-18 19:32:21 -06:00
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:
37
src/utils/fetchLatestWaWebVersion.ts
Normal file
37
src/utils/fetchLatestWaWebVersion.ts
Normal 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,
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user