diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 2053b7a5..83b08b4a 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -1898,17 +1898,6 @@ export class BaileysStartupService extends ChannelStartupService { const isWA = (await this.whatsappNumber({ numbers: [number] }))?.shift(); if (!isWA.exists && !isJidGroup(isWA.jid) && !isWA.jid.includes('@broadcast')) { - if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled) { - const body = { - key: { remoteJid: isWA.jid }, - }; - - this.chatwootService.eventWhatsapp( - 'contact.is_not_in_wpp', - { instanceName: this.instance.name, instanceId: this.instance.id }, - body, - ); - } throw new BadRequestException(isWA); } diff --git a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts index 5e0d01e5..b0556fe9 100644 --- a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts +++ b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts @@ -1136,19 +1136,35 @@ export class ChatwootService { } } - public async onSendMessageError(instance: InstanceDto, conversation: number, error?: string) { + public async onSendMessageError(instance: InstanceDto, conversation: number, error?: any) { + this.logger.verbose(`onSendMessageError ${JSON.stringify(error)}`); + const client = await this.clientCw(instance); if (!client) { return; } + if (error && error?.status === 400 && error?.message[0]?.exists === false) { + client.messages.create({ + accountId: this.provider.accountId, + conversationId: conversation, + data: { + content: `${i18next.t('cw.message.numbernotinwhatsapp')}`, + message_type: 'outgoing', + private: true, + }, + }); + + return; + } + client.messages.create({ accountId: this.provider.accountId, conversationId: conversation, data: { content: i18next.t('cw.message.notsent', { - error: error?.length > 0 ? `_${error}_` : '', + error: error ? `_${error.toString()}_` : '', }), message_type: 'outgoing', private: true, @@ -1392,7 +1408,7 @@ export class ChatwootService { ); } catch (error) { if (!messageSent && body.conversation?.id) { - this.onSendMessageError(instance, body.conversation?.id, error.toString()); + this.onSendMessageError(instance, body.conversation?.id, error); } throw error; } @@ -1852,27 +1868,6 @@ export class ChatwootService { } } - if (event === 'contact.is_not_in_wpp') { - const getConversation = await this.createConversation(instance, body); - - if (!getConversation) { - this.logger.warn('conversation not found'); - return; - } - - client.messages.create({ - accountId: this.provider.accountId, - conversationId: getConversation, - data: { - content: `🚨 ${i18next.t('numbernotinwhatsapp')}`, - message_type: 'outgoing', - private: true, - }, - }); - - return; - } - if (event === 'messages.upsert' || event === 'send.message') { if (body.key.remoteJid === 'status@broadcast') { return; diff --git a/src/utils/translations/pt-BR.json b/src/utils/translations/pt-BR.json index 85ed293b..31bf468a 100644 --- a/src/utils/translations/pt-BR.json +++ b/src/utils/translations/pt-BR.json @@ -2,7 +2,6 @@ "qrgeneratedsuccesfully": "QRCode gerado com sucesso!", "scanqr": "Escaneie o QRCode com o WhatsApp nos próximos 40 segundos.", "qrlimitreached": "Limite de geração de QRCode atingido! Para gerar um novo QRCode, envie o texto 'init' nesta conversa.", - "numbernotinwhatsapp": "A mensagem não foi enviada, pois o contato não é um número válido do WhatsApp.", "cw.inbox.connected": "🚀 Conectado com sucesso!", "cw.inbox.disconnect": "🚨 Instância *{{inboxName}}* desconectada do WhatsApp.", "cw.inbox.alreadyConnected": "🚨 Instância *{{inboxName}}* já está conectada.", @@ -23,5 +22,6 @@ "cw.contactMessage.name": "Nome", "cw.contactMessage.number": "Número", "cw.message.notsent": "🚨 Não foi possível enviar a mensagem. Verifique sua conexão. {{error}}", + "cw.message.numbernotinwhatsapp": "🚨 A mensagem não foi enviada, pois o contato não é um número válido do WhatsApp.", "cw.message.edited": "Mensagem editada" } \ No newline at end of file