Skip to content

Commit

Permalink
fix: Resolve generation of pairing code
Browse files Browse the repository at this point in the history
In this commit, we have fixed an issue related to the generation of the pairing code. The changes include modifying the `whatsapp.baileys.service.ts` file, where we have updated the `connectToWhatsapp` method to accept a phone number parameter. Additionally, we have made changes to the `browser` variable to handle phone number and browser options. These changes improve the reliability of the pairing code generation.
  • Loading branch information
dgcode-tec committed Jun 26, 2024
1 parent 47d6fd5 commit d0eee79
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/api/services/channels/whatsapp.baileys.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ export class BaileysStartupService extends ChannelStartupService {
if (connection === 'close') {
const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut;
if (shouldReconnect) {
await this.connectToWhatsapp();
await this.connectToWhatsapp(this.phoneNumber);
} else {
this.sendDataWebhook(Events.STATUS_INSTANCE, {
instance: this.instance.name,
Expand Down Expand Up @@ -512,7 +512,19 @@ export class BaileysStartupService extends ChannelStartupService {
this.instance.authState = await this.defineAuthState();

const session = this.configService.get<ConfigSessionPhone>('CONFIG_SESSION_PHONE');
const browser: WABrowserDescription = [session.CLIENT, session.NAME, release()];

let browserOptions = {};

if (number || this.phoneNumber) {
this.phoneNumber = number;

this.logger.info(`Phone number: ${number}`);
} else {
const browser: WABrowserDescription = [session.CLIENT, session.NAME, release()];
browserOptions = { browser };

this.logger.info(`Browser: ${browser}`);
}

let version;
let log;
Expand Down Expand Up @@ -575,7 +587,7 @@ export class BaileysStartupService extends ChannelStartupService {
},
logger: P({ level: this.logBaileys }),
printQRInTerminal: false,
browser: number ? ['Chrome (Linux)', session.NAME, release()] : browser,
...browserOptions,
version,
markOnlineOnConnect: this.localSettings.alwaysOnline,
retryRequestDelayMs: 350,
Expand Down Expand Up @@ -643,7 +655,17 @@ export class BaileysStartupService extends ChannelStartupService {
this.instance.authState = await this.defineAuthState();

const session = this.configService.get<ConfigSessionPhone>('CONFIG_SESSION_PHONE');
const browser: WABrowserDescription = [session.CLIENT, session.NAME, release()];

let browserOptions = {};

if (this.phoneNumber) {
this.logger.info(`Phone number: ${this.phoneNumber}`);
} else {
const browser: WABrowserDescription = [session.CLIENT, session.NAME, release()];
browserOptions = { browser };

this.logger.info(`Browser: ${browser}`);
}

let version;
let log;
Expand Down Expand Up @@ -706,7 +728,7 @@ export class BaileysStartupService extends ChannelStartupService {
},
logger: P({ level: this.logBaileys }),
printQRInTerminal: false,
browser: this.phoneNumber ? ['Chrome (Linux)', session.NAME, release()] : browser,
...browserOptions,
version,
markOnlineOnConnect: this.localSettings.alwaysOnline,
retryRequestDelayMs: 350,
Expand Down

0 comments on commit d0eee79

Please sign in to comment.