mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-13 15:14:49 -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:
parent
22c379aa36
commit
ae99ec7a0e
@ -80,6 +80,7 @@ import { Boom } from '@hapi/boom';
|
|||||||
import { createId as cuid } from '@paralleldrive/cuid2';
|
import { createId as cuid } from '@paralleldrive/cuid2';
|
||||||
import { Instance, Message } from '@prisma/client';
|
import { Instance, Message } from '@prisma/client';
|
||||||
import { createJid } from '@utils/createJid';
|
import { createJid } from '@utils/createJid';
|
||||||
|
import { fetchLatestWaWebVersion } from '@utils/fetchLatestWaWebVersion';
|
||||||
import { makeProxyAgent } from '@utils/makeProxyAgent';
|
import { makeProxyAgent } from '@utils/makeProxyAgent';
|
||||||
import { getOnWhatsappCache, saveOnWhatsappCache } from '@utils/onWhatsappCache';
|
import { getOnWhatsappCache, saveOnWhatsappCache } from '@utils/onWhatsappCache';
|
||||||
import { status } from '@utils/renderStatus';
|
import { status } from '@utils/renderStatus';
|
||||||
@ -99,7 +100,6 @@ import makeWASocket, {
|
|||||||
delay,
|
delay,
|
||||||
DisconnectReason,
|
DisconnectReason,
|
||||||
downloadMediaMessage,
|
downloadMediaMessage,
|
||||||
fetchLatestBaileysVersion,
|
|
||||||
generateWAMessageFromContent,
|
generateWAMessageFromContent,
|
||||||
getAggregateVotesInPollMessage,
|
getAggregateVotesInPollMessage,
|
||||||
GetCatalogOptions,
|
GetCatalogOptions,
|
||||||
@ -548,7 +548,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
version = session.VERSION.split('.');
|
version = session.VERSION.split('.');
|
||||||
log = `Baileys version env: ${version}`;
|
log = `Baileys version env: ${version}`;
|
||||||
} else {
|
} else {
|
||||||
const baileysVersion = await fetchLatestBaileysVersion();
|
const baileysVersion = await fetchLatestWaWebVersion({});
|
||||||
version = baileysVersion.version;
|
version = baileysVersion.version;
|
||||||
log = `Baileys version: ${version}`;
|
log = `Baileys version: ${version}`;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import { ChatbotRouter } from '@api/integrations/chatbot/chatbot.router';
|
|||||||
import { EventRouter } from '@api/integrations/event/event.router';
|
import { EventRouter } from '@api/integrations/event/event.router';
|
||||||
import { StorageRouter } from '@api/integrations/storage/storage.router';
|
import { StorageRouter } from '@api/integrations/storage/storage.router';
|
||||||
import { configService } from '@config/env.config';
|
import { configService } from '@config/env.config';
|
||||||
import { fetchLatestBaileysVersion } from 'baileys';
|
import { fetchLatestWaWebVersion } from '@utils/fetchLatestWaWebVersion';
|
||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import mimeTypes from 'mime-types';
|
import mimeTypes from 'mime-types';
|
||||||
@ -70,7 +70,7 @@ router
|
|||||||
manager: !serverConfig.DISABLE_MANAGER ? `${req.protocol}://${req.get('host')}/manager` : undefined,
|
manager: !serverConfig.DISABLE_MANAGER ? `${req.protocol}://${req.get('host')}/manager` : undefined,
|
||||||
documentation: `https://doc.evolution-api.com`,
|
documentation: `https://doc.evolution-api.com`,
|
||||||
whatsappWebVersion:
|
whatsappWebVersion:
|
||||||
process.env.CONFIG_SESSION_PHONE_VERSION || (await fetchLatestBaileysVersion()).version.join('.'),
|
process.env.CONFIG_SESSION_PHONE_VERSION || (await fetchLatestWaWebVersion({})).version.join('.'),
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.post('/verify-creds', authGuard['apikey'], async (req, res) => {
|
.post('/verify-creds', authGuard['apikey'], async (req, res) => {
|
||||||
|
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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user