Skip to content

Commit

Permalink
include new whatsapp version
Browse files Browse the repository at this point in the history
  • Loading branch information
allgood committed Aug 22, 2024
1 parent 26142ed commit 12189e8
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion backend/src/libs/wbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Session> => {
return new Promise((resolve, reject) => {
try {
Expand All @@ -82,9 +98,12 @@ export const initWASocket = async (whatsapp: Whatsapp): Promise<Session> => {

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}`);
Expand Down

0 comments on commit 12189e8

Please sign in to comment.