From 12189e8ae5f7c45024a4c064b47f7753774e4223 Mon Sep 17 00:00:00 2001 From: Claudemir Todo Bom Date: Thu, 22 Aug 2024 20:08:50 -0300 Subject: [PATCH] include new whatsapp version --- backend/src/libs/wbot.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/backend/src/libs/wbot.ts b/backend/src/libs/wbot.ts index 1803c3c..496e066 100644 --- a/backend/src/libs/wbot.ts +++ b/backend/src/libs/wbot.ts @@ -68,6 +68,22 @@ export const removeWbot = async ( } }; +function getGreaterVersion(a, b) { + for (let i = 0; i < Math.max(a.length, b.length); i += 1) { + const numA = a[i] || 0; + const numB = b[i] || 0; + + if (numA > numB) { + return a; + } + if (numA < numB) { + return b; + } + } + + return a; +} + export const initWASocket = async (whatsapp: Whatsapp): Promise => { return new Promise((resolve, reject) => { try { @@ -82,9 +98,12 @@ export const initWASocket = async (whatsapp: Whatsapp): Promise => { const { id, name, provider } = whatsappUpdate; - const { version, isLatest } = await fetchLatestBaileysVersion(); + const { version: autoVersion, isLatest } = + await fetchLatestBaileysVersion(); const isLegacy = provider === "stable"; + const version = getGreaterVersion(autoVersion, [2, 3000, 1015891883]); + logger.info(`using WA v${version.join(".")}, isLatest: ${isLatest}`); logger.info(`isLegacy: ${isLegacy}`); logger.info(`Starting session ${name}`);