diff --git a/CHANGELOG.md b/CHANGELOG.md index 80613150..9a6f1781 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Feature * Added AWS SQS Integration * Added compatibility with typebot v2 +* Added endpoint sendPresence ### Fixed @@ -16,6 +17,8 @@ * Removed await from webhook when sending a message * Update typebot.service.ts - element.underline change ~ for * * Adjusts in proxy +* Removed api restart on receiving an error +* Fixes in mongodb and chatwoot # 1.5.4 (2023-10-09 20:43) diff --git a/src/config/error.config.ts b/src/config/error.config.ts index 7a6717da..dbba0d6a 100644 --- a/src/config/error.config.ts +++ b/src/config/error.config.ts @@ -8,7 +8,7 @@ export function onUnexpectedError() { stderr: process.stderr.fd, error, }); - process.exit(1); + // process.exit(1); }); process.on('unhandledRejection', (error, origin) => { @@ -18,6 +18,6 @@ export function onUnexpectedError() { stderr: process.stderr.fd, error, }); - process.exit(1); + // process.exit(1); }); } diff --git a/src/utils/use-multi-file-auth-state-db.ts b/src/utils/use-multi-file-auth-state-db.ts index fc6c3e8f..ac25f21e 100644 --- a/src/utils/use-multi-file-auth-state-db.ts +++ b/src/utils/use-multi-file-auth-state-db.ts @@ -106,7 +106,7 @@ export async function useMultiFileAuthStateDb( }, }, saveCreds: async () => { - return writeData(creds, 'creds'); + return await writeData(creds, 'creds'); }, }; } diff --git a/src/whatsapp/services/chatwoot.service.ts b/src/whatsapp/services/chatwoot.service.ts index 51c77453..5026669a 100644 --- a/src/whatsapp/services/chatwoot.service.ts +++ b/src/whatsapp/services/chatwoot.service.ts @@ -1023,6 +1023,10 @@ export class ChatwootService { const state = waInstance?.connectionStatus?.state; if (state !== 'open') { + if (state === 'close') { + this.logger.verbose('request cleaning up instance: ' + instance.instanceName); + await this.waMonitor.cleaningUp(instance.instanceName); + } this.logger.verbose('connect to whatsapp'); const number = command.split(':')[1]; await waInstance.connectToWhatsapp(number); @@ -1331,13 +1335,6 @@ export class ChatwootService { public async eventWhatsapp(event: string, instance: InstanceDto, body: any) { this.logger.verbose('event whatsapp to instance: ' + instance.instanceName); try { - const client = await this.clientCw(instance); - - if (!client) { - this.logger.warn('client not found'); - return null; - } - const waInstance = this.waMonitor.waInstances[instance.instanceName]; if (!waInstance) { @@ -1345,6 +1342,13 @@ export class ChatwootService { return null; } + const client = await this.clientCw(instance); + + if (!client) { + this.logger.warn('client not found'); + return null; + } + if (event === 'messages.upsert' || event === 'send.message') { this.logger.verbose('event messages.upsert'); @@ -1600,16 +1604,18 @@ export class ChatwootService { await this.createBotMessage(instance, msgStatus, 'incoming'); } - // if (event === 'connection.update') { - // this.logger.verbose('event connection.update'); + if (event === 'connection.update') { + this.logger.verbose('event connection.update'); - // if (body.status === 'open') { - // const msgConnection = `🚀 Connection successfully established!`; - - // this.logger.verbose('send message to chatwoot'); - // await this.createBotMessage(instance, msgConnection, 'incoming'); - // } - // } + if (body.status === 'open') { + // if we have qrcode count then we understand that a new connection was established + if (this.waMonitor.waInstances[instance.instanceName].qrCode.count > 0) { + const msgConnection = `🚀 Connection successfully established!`; + this.logger.verbose('send message to chatwoot'); + await this.createBotMessage(instance, msgConnection, 'incoming'); + } + } + } if (event === 'qrcode.updated') { this.logger.verbose('event qrcode.updated'); diff --git a/src/whatsapp/services/typebot.service.ts b/src/whatsapp/services/typebot.service.ts index a272115a..00eb9639 100644 --- a/src/whatsapp/services/typebot.service.ts +++ b/src/whatsapp/services/typebot.service.ts @@ -263,7 +263,7 @@ export class TypebotService { prefilledVariables: { ...data.prefilledVariables, remoteJid: data.remoteJid, - pushName: data.pushName || '', + pushName: data.pushName || data.prefilledVariables?.pushName || '', instanceName: instance.instanceName, }, },