diff --git a/src/Utils/generics.ts b/src/Utils/generics.ts index 9fb0c3b..8f735e0 100644 --- a/src/Utils/generics.ts +++ b/src/Utils/generics.ts @@ -288,16 +288,31 @@ export const fetchLatestBaileysVersion = async(options: AxiosRequestConfig<{}> = */ export const fetchLatestWaWebVersion = async(options: AxiosRequestConfig<{}>) => { try { - const result = await axios.get( - 'https://web.whatsapp.com/check-update?version=1&platform=web', + const { data } = await axios.get( + 'https://web.whatsapp.com/sw.js', { ...options, responseType: 'json' } ) - const version = result.data.currentVersion.split('.') + + const regex = /\\?"client_revision\\?":\s*(\d+)/ + const match = data.match(regex) + + if(!match?.[1]) { + return { + version: baileysVersion as WAVersion, + isLatest: false, + error: { + message: 'Could not find client revision in the fetched content' + } + } + } + + const clientRevision = match[1] + return { - version: [+version[0], +version[1], +version[2]] as WAVersion, + version: [2, 3000, +clientRevision] as WAVersion, isLatest: true } } catch(error) {