Skip to content

Commit

Permalink
whatsapp version definition
Browse files Browse the repository at this point in the history
  • Loading branch information
jrCleber committed Aug 28, 2024
1 parent c731db8 commit 19cdac0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/config/env.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* └──────────────────────────────────────────────────────────────────────────────┘
*/

import { isBooleanString } from 'class-validator';
import { isBooleanString, isEmpty } from 'class-validator';
import { config } from 'dotenv';

config();
Expand Down Expand Up @@ -126,6 +126,7 @@ export interface Env {
PRODUCTION?: boolean;
SESSION_SECRET: string;
S3?: Bucket;
WA_VERSION: string;
}

export type Key = keyof Env;
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
};
}
}
3 changes: 2 additions & 1 deletion src/whatsapp/services/whatsapp.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import makeWASocket, {
WAMediaUpload,
WAMessageUpdate,
WASocket,
WAVersion,
} from '@whiskeysockets/baileys/';
import {
ConfigService,
Expand Down Expand Up @@ -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<string>('WA_VERSION')) as WAVersion;
const session = this.configService.get<ConfigSessionPhone>('CONFIG_SESSION_PHONE');
const browser: WABrowserDescription = [session.CLIENT, session.NAME, release()];

Expand Down

0 comments on commit 19cdac0

Please sign in to comment.