generics: update the fetch function to work, keep old for backwards comp

This commit is contained in:
Rajeh Taher
2025-09-08 22:59:04 +03:00
parent 5b6eae4523
commit b0c3486ab0
2 changed files with 25 additions and 6 deletions
+22 -6
View File
@@ -245,15 +245,31 @@ export const bindWaitForConnectionUpdate = (ev: BaileysEventEmitter) => bindWait
* Use to ensure your WA connection is always on the latest version
*/
export const fetchLatestBaileysVersion = async (options: AxiosRequestConfig<{}> = {}) => {
const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/baileys-version.json'
const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/index.ts'
try {
const result = await axios.get<{ version: WAVersion }>(URL, {
const result = await axios.get<string>(URL, {
...options,
responseType: 'json'
responseType: 'text'
})
return {
version: result.data.version,
isLatest: true
// Extract version from line 7 (const version = [...])
const lines = result.data.split('\n')
const versionLine = lines[6] // Line 7 (0-indexed)
const versionMatch = versionLine!.match(/const version = \[(\d+),\s*(\d+),\s*(\d+)\]/)
if (versionMatch) {
const version = [
parseInt(versionMatch[1]!),
parseInt(versionMatch[2]!),
parseInt(versionMatch[3]!)
] as WAVersion
return {
version,
isLatest: true
}
} else {
throw new Error('Could not parse version from Defaults/index.ts')
}
} catch (error) {
return {