Skip to content

Commit

Permalink
use wa version from project site
Browse files Browse the repository at this point in the history
  • Loading branch information
allgood committed Oct 21, 2024
1 parent 90c4d6f commit 0b32f72
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
23 changes: 18 additions & 5 deletions backend/src/libs/wbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as Sentry from "@sentry/node";
import makeWASocket, {
WASocket,
DisconnectReason,
fetchLatestBaileysVersion,
makeCacheableSignalKeyStore,
makeInMemoryStore,
isJidBroadcast,
Expand Down Expand Up @@ -85,6 +84,21 @@ function getGreaterVersion(a, b) {
return a;
}

const waVersion = [2, 3000, 1015891883];

const getProjectWAVersion = async () => {
try {
const res = await fetch(
"https://raw.githubusercontent.com/ticketz-oss/ticketz/refs/heads/main/backend/src/waversion.json"
);
const version = await res.json();
return version;
} catch (error) {
console.warn("Failed to get current WA Version from project repository");
}
return waVersion;
};

export const initWASocket = async (whatsapp: Whatsapp): Promise<Session> => {
return new Promise((resolve, reject) => {
try {
Expand All @@ -99,13 +113,12 @@ export const initWASocket = async (whatsapp: Whatsapp): Promise<Session> => {

const { id, name, provider } = whatsappUpdate;

const { version: autoVersion, isLatest } =
await fetchLatestBaileysVersion();
const autoVersion = await getProjectWAVersion();
const isLegacy = provider === "stable";

const version = getGreaterVersion(autoVersion, [2, 3000, 1015891883]);
const version = getGreaterVersion(autoVersion, waVersion);

logger.info(`using WA v${version.join(".")}, isLatest: ${isLatest}`);
logger.info(`using WA v${version.join(".")}`);
logger.info(`isLegacy: ${isLegacy}`);
logger.info(`Starting session ${name}`);
let retriesQrCode = 0;
Expand Down
1 change: 1 addition & 0 deletions backend/src/waversion.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[2, 3000, 1015891883]

0 comments on commit 0b32f72

Please sign in to comment.