Skip to content

Commit bea3985

Browse files
committed
fix: version to generate the QR code
1 parent 1b1544c commit bea3985

3 files changed

Lines changed: 32 additions & 26 deletions

File tree

.env.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ INSTANCE_EXPIRATION_TIME=false
6565
CONFIG_SESSION_PHONE_CLIENT=CodeChat_V1
6666
CONFIG_SESSION_PHONE_NAME=Edge
6767

68-
WA_VERSION=[ 2, 3000, 1025257277 ]
68+
WA_VERSION=[ 2, 3000, 1036021366 ]
6969

7070
# Set qrcode display limit
7171
QRCODE_LIMIT=5

src/utils/wa-version.ts

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
11
import { WAVersion } from '@whiskeysockets/baileys';
22
import axios from 'axios';
33

4-
export const fetchLatestBaileysVersionV2 = async () => {
5-
try {
6-
const resp = await axios.get<string>('https://web.whatsapp.com/sw.js');
7-
const re = /JSON\.parse\(\s*(?:\/\*[^]*?\*\/\s*)?("(?:(?:\\.|[^"\\])*)")\s*\)/;
8-
const data = resp.data;
9-
const m = re.exec(data);
10-
if (!m) {
11-
return undefined;
12-
}
4+
const v = {
5+
version: [] as unknown as WAVersion,
6+
isLatest: false,
7+
};
8+
9+
(async () => {
10+
const resp = await axios.get<string>(
11+
'https://raw.githubusercontent.com/code-chat-br/whatsapp-api/main/_v/version',
12+
);
13+
v.isLatest = true;
14+
v.version = [2, 3000, +resp.data];
1315

14-
const escaped = m[1];
15-
const jsonText = JSON.parse(escaped);
16-
const obj = JSON.parse(jsonText);
16+
setInterval(
17+
async () => {
18+
const resp = await axios.get<string>(
19+
'https://raw.githubusercontent.com/code-chat-br/whatsapp-api/main/_v/version',
20+
);
1721

18-
const v = obj?.dynamic_data?.dynamic_modules?.SiteData?.client_revision as number;
19-
if (v) {
20-
return {
21-
version: [2, 3000, v] as WAVersion,
22-
isLatest: true,
23-
error: null as unknown,
24-
};
25-
} else {
26-
throw new Error('Could not parse version from Defaults/index.ts');
27-
}
22+
v.isLatest = true;
23+
v.version = [2, 3000, +resp.data];
24+
25+
console.log('VERSION: ', v);
26+
},
27+
60 * 60 * 1000 * 27 * 3,
28+
);
29+
})();
30+
31+
export const fetchLatestBaileysVersionV2 = () => {
32+
try {
33+
return v;
2834
} catch (error) {
29-
const waVersion = JSON.parse(process.env?.WA_VERSION || '[]') as number[];
3035
return {
31-
version: [2, 3000, waVersion?.[2] ?? 1029707447] as WAVersion,
36+
version: JSON.parse(process.env.WA_VERSION ?? '[]') as WAVersion,
3237
isLatest: false,
3338
error,
3439
};

src/whatsapp/services/whatsapp.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,8 @@ export class WAStartupService {
560560

561561
this.authState = await this.defineAuthState();
562562

563-
const { version } = await fetchLatestBaileysVersionV2();
563+
const { version } = fetchLatestBaileysVersionV2();
564+
console.log({ version });
564565
const session = this.configService.get<ConfigSessionPhone>('CONFIG_SESSION_PHONE');
565566
const browser: WABrowserDescription = !this.phoneNumber
566567
? [session.CLIENT, session.NAME, release()]

0 commit comments

Comments
 (0)