From b3adde3a7a1494672a2591aca494878409abb7ae Mon Sep 17 00:00:00 2001 From: Deivison Lincoln Date: Thu, 1 Feb 2024 23:42:52 -0300 Subject: [PATCH 1/2] Feat Reject Message If is not a valid wpp number --- src/utils/translations/en.json | 3 ++- src/utils/translations/pt-BR.json | 3 ++- src/whatsapp/services/chatwoot.service.ts | 21 +++++++++++++++++++++ src/whatsapp/services/whatsapp.service.ts | 8 ++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/utils/translations/en.json b/src/utils/translations/en.json index f92c4e083..d8566c72b 100644 --- a/src/utils/translations/en.json +++ b/src/utils/translations/en.json @@ -1,5 +1,6 @@ { "qrgeneratedsuccesfully": "QRCode successfully generated!", "scanqr": "Scan this QR code within the next 40 seconds.", - "qrlimitreached": "QRCode generation limit reached, to generate a new QRCode, send the 'init' message again." + "qrlimitreached": "QRCode generation limit reached, to generate a new QRCode, send the 'init' message again.", + "numbernotinwhatsapp": "The message was not sent as the contact is not a valid Whatsapp number." } \ No newline at end of file diff --git a/src/utils/translations/pt-BR.json b/src/utils/translations/pt-BR.json index d48ff1484..a96688489 100644 --- a/src/utils/translations/pt-BR.json +++ b/src/utils/translations/pt-BR.json @@ -1,5 +1,6 @@ { "qrgeneratedsuccesfully": "QRCode gerado com sucesso!", "scanqr": "Escanei 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." + "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." } \ No newline at end of file diff --git a/src/whatsapp/services/chatwoot.service.ts b/src/whatsapp/services/chatwoot.service.ts index 0bc74ecdc..1ceeb2ddb 100644 --- a/src/whatsapp/services/chatwoot.service.ts +++ b/src/whatsapp/services/chatwoot.service.ts @@ -1684,6 +1684,27 @@ export class ChatwootService { return null; } + 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.account_id, + conversationId: getConversation, + data: { + content: `🚨 ${i18next.t('numbernotinwhatsapp')}`, + message_type: 'incoming', + private: true, + }, + }); + + return; + } + if (event === 'messages.upsert' || event === 'send.message') { this.logger.verbose('event messages.upsert'); diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index 71ca431eb..5c562b3c3 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -2357,7 +2357,15 @@ export class WAStartupService { const isWA = (await this.whatsappNumber({ numbers: [number] }))?.shift(); this.logger.verbose(`Exists: "${isWA.exists}" | jid: ${isWA.jid}`); + if (!isWA.exists && !isJidGroup(isWA.jid) && !isWA.jid.includes('@broadcast')) { + if (this.localChatwoot.enabled) { + const body = { + key: { remoteJid: isWA.jid }, + }; + + this.chatwootService.eventWhatsapp('contact.is_not_in_wpp', { instanceName: this.instance.name }, body); + } throw new BadRequestException(isWA); } From c130846fe83ad2e55bc4d6230927e717e026565a Mon Sep 17 00:00:00 2001 From: Deivison Lincoln Date: Fri, 2 Feb 2024 08:57:44 -0300 Subject: [PATCH 2/2] Change message_type Change message_type to 'outgoing' --- src/whatsapp/services/chatwoot.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/whatsapp/services/chatwoot.service.ts b/src/whatsapp/services/chatwoot.service.ts index 1ceeb2ddb..bc7d44713 100644 --- a/src/whatsapp/services/chatwoot.service.ts +++ b/src/whatsapp/services/chatwoot.service.ts @@ -1697,7 +1697,7 @@ export class ChatwootService { conversationId: getConversation, data: { content: `🚨 ${i18next.t('numbernotinwhatsapp')}`, - message_type: 'incoming', + message_type: 'outgoing', private: true, }, });