oex2003/evolution-api
0
1import axios, { AxiosRequestConfig } from 'axios';2import { fetchLatestBaileysVersion, WAVersion } from 'baileys';3 4export const fetchLatestWaWebVersion = async (options: AxiosRequestConfig<{}>) => {5 try {6 const { data } = await axios.get('https://web.whatsapp.com/sw.js', {7 ...options,8 responseType: 'json',9 });10 11 const regex = /\\?"client_revision\\?":\s*(\d+)/;12 const match = data.match(regex);13 14 if (!match?.[1]) {15 return {16 version: (await fetchLatestBaileysVersion()).version as WAVersion,17 isLatest: false,18 error: {19 message: 'Could not find client revision in the fetched content',20 },21 };22 }23 24 const clientRevision = match[1];25 26 return {27 version: [2, 3000, +clientRevision] as WAVersion,28 isLatest: true,29 };30 } catch (error) {31 return {32 version: (await fetchLatestBaileysVersion()).version as WAVersion,33 isLatest: false,34 error,35 };36 }37};38 