mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-18 11:22:21 -06:00
- Introduced a flag to prevent reconnection during instance deletion. - Improved logging for connection updates and errors during logout. - Added a delay before reconnection attempts to avoid rapid loops. - Enhanced webhook headers for better tracking and debugging. - Updated configuration to support manual Baileys version setting.
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import axios, { AxiosRequestConfig } from 'axios';
|
|
import { fetchLatestBaileysVersion, WAVersion } from 'baileys';
|
|
|
|
import { Baileys, configService } from '../config/env.config';
|
|
|
|
export const fetchLatestWaWebVersion = async (options: AxiosRequestConfig<{}>) => {
|
|
// Check if manual version is set via configuration
|
|
const baileysConfig = configService.get<Baileys>('BAILEYS');
|
|
const manualVersion = baileysConfig?.VERSION;
|
|
|
|
if (manualVersion) {
|
|
const versionParts = manualVersion.split('.').map(Number);
|
|
if (versionParts.length === 3 && !versionParts.some(isNaN)) {
|
|
return {
|
|
version: versionParts as WAVersion,
|
|
isLatest: false,
|
|
isManual: true,
|
|
};
|
|
}
|
|
}
|
|
|
|
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,
|
|
};
|
|
}
|
|
};
|