diff --git a/src/whatsapp/services/whatsapp.baileys.service.ts b/src/whatsapp/services/whatsapp.baileys.service.ts index e9e7147aa..f99e074d1 100644 --- a/src/whatsapp/services/whatsapp.baileys.service.ts +++ b/src/whatsapp/services/whatsapp.baileys.service.ts @@ -472,7 +472,7 @@ export class BaileysStartupService extends WAStartupService { if (this.localProxy.enabled) { this.logger.info('Proxy enabled: ' + this.localProxy.proxy); - if (this.localProxy.proxy.host.includes('proxyscrape')) { + if (this.localProxy?.proxy?.host?.includes('proxyscrape')) { try { const response = await axios.get(this.localProxy.proxy.host); const text = response.data; diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index 29c58f6c6..030285b81 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -663,6 +663,18 @@ export class WAStartupService { }; } + private assertExchangeAsync = (channel, exchangeName, exchangeType, options) => { + return new Promise((resolve, reject) => { + channel.assertExchange(exchangeName, exchangeType, options, (error, ok) => { + if (error) { + reject(error); + } else { + resolve(ok); + } + }); + }); + }; + public async sendDataWebhook(event: Events, data: T, local = true) { const webhookGlobal = this.configService.get('WEBHOOK'); const webhookLocal = this.localWebhook.events; @@ -687,14 +699,19 @@ export class WAStartupService { if (Array.isArray(rabbitmqLocal) && rabbitmqLocal.includes(we)) { const exchangeName = this.instanceName ?? 'evolution_exchange'; - amqp.assertExchange(exchangeName, 'topic', { + // await amqp.assertExchange(exchangeName, 'topic', { + // durable: true, + // autoDelete: false, + // }); + + await this.assertExchangeAsync(amqp, exchangeName, 'topic', { durable: true, autoDelete: false, }); const queueName = `${this.instanceName}.${event}`; - amqp.assertQueue(queueName, { + await amqp.assertQueue(queueName, { durable: true, autoDelete: false, arguments: { @@ -702,7 +719,7 @@ export class WAStartupService { }, }); - amqp.bindQueue(queueName, exchangeName, event); + await amqp.bindQueue(queueName, exchangeName, event); const message = { event, @@ -717,7 +734,7 @@ export class WAStartupService { message['apikey'] = instanceApikey; } - amqp.publish(exchangeName, event, Buffer.from(JSON.stringify(message))); + await amqp.publish(exchangeName, event, Buffer.from(JSON.stringify(message))); if (this.configService.get('LOG').LEVEL.includes('WEBHOOKS')) { const logData = {