From 19cdac0c99a999b912310145a6ee14f7c2c165fa Mon Sep 17 00:00:00 2001 From: Cleber Wilson Date: Wed, 28 Aug 2024 15:12:20 -0300 Subject: [PATCH] whatsapp version definition --- src/config/env.config.ts | 10 +++++++++- src/whatsapp/services/whatsapp.service.ts | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/config/env.config.ts b/src/config/env.config.ts index 372b3446..8305eed0 100644 --- a/src/config/env.config.ts +++ b/src/config/env.config.ts @@ -40,7 +40,7 @@ * └──────────────────────────────────────────────────────────────────────────────┘ */ -import { isBooleanString } from 'class-validator'; +import { isBooleanString, isEmpty } from 'class-validator'; import { config } from 'dotenv'; config(); @@ -126,6 +126,7 @@ export interface Env { PRODUCTION?: boolean; SESSION_SECRET: string; S3?: Bucket; + WA_VERSION: string; } export type Key = keyof Env; @@ -152,6 +153,12 @@ export class ConfigService { ); } } + + if (isEmpty(this.env.WA_VERSION)) { + throw new Error( + 'The WhatsApp version must be specified in the environment variables.\n\nDefault variable [file: .env]: WA_VERSION=[ 2, 3000, 1015901307 ]\n', + ); + } } private envProcess(): Env { @@ -237,6 +244,7 @@ export class ConfigService { PORT: Number.parseInt(process.env?.S3_PORT || '9000'), USE_SSL: process.env?.S3_USE_SSL === 'true', }, + WA_VERSION: process.env?.WA_VERSION, }; } } diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index f229bc3e..f87c06ba 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -67,6 +67,7 @@ import makeWASocket, { WAMediaUpload, WAMessageUpdate, WASocket, + WAVersion, } from '@whiskeysockets/baileys/'; import { ConfigService, @@ -504,7 +505,7 @@ export class WAStartupService { this.authState = (await this.defineAuthState()) as AuthState; - const { version } = await fetchLatestBaileysVersion(); + const version = JSON.parse(this.configService.get('WA_VERSION')) as WAVersion; const session = this.configService.get('CONFIG_SESSION_PHONE'); const browser: WABrowserDescription = [session.CLIENT, session.NAME, release()];