Skip to content

Commit cc17d61

Browse files
Merge pull request #394 from deivisonrpg/feat/chatwoot-reject-message-wpp-not-exists
Feat Chatwoot - Reject Message If is not a valid wpp number
2 parents 0547ff7 + c130846 commit cc17d61

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

src/utils/translations/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"qrgeneratedsuccesfully": "QRCode successfully generated!",
33
"scanqr": "Scan this QR code within the next 40 seconds.",
4-
"qrlimitreached": "QRCode generation limit reached, to generate a new QRCode, send the 'init' message again."
4+
"qrlimitreached": "QRCode generation limit reached, to generate a new QRCode, send the 'init' message again.",
5+
"numbernotinwhatsapp": "The message was not sent as the contact is not a valid Whatsapp number."
56
}

src/utils/translations/pt-BR.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"qrgeneratedsuccesfully": "QRCode gerado com sucesso!",
33
"scanqr": "Escanei o QRCode com o Whatsapp nos próximos 40 segundos.",
4-
"qrlimitreached": "Limite de geração de QRCode atingido! Para gerar um novo QRCode, envie o texto 'init' nesta conversa."
4+
"qrlimitreached": "Limite de geração de QRCode atingido! Para gerar um novo QRCode, envie o texto 'init' nesta conversa.",
5+
"numbernotinwhatsapp": "A mensagem não foi enviada, pois o contato não é um número válido do Whatsapp."
56
}

src/whatsapp/services/chatwoot.service.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,27 @@ export class ChatwootService {
16861686
return null;
16871687
}
16881688

1689+
if (event === 'contact.is_not_in_wpp') {
1690+
const getConversation = await this.createConversation(instance, body);
1691+
1692+
if (!getConversation) {
1693+
this.logger.warn('conversation not found');
1694+
return;
1695+
}
1696+
1697+
client.messages.create({
1698+
accountId: this.provider.account_id,
1699+
conversationId: getConversation,
1700+
data: {
1701+
content: `🚨 ${i18next.t('numbernotinwhatsapp')}`,
1702+
message_type: 'outgoing',
1703+
private: true,
1704+
},
1705+
});
1706+
1707+
return;
1708+
}
1709+
16891710
if (event === 'messages.upsert' || event === 'send.message') {
16901711
this.logger.verbose('event messages.upsert');
16911712

src/whatsapp/services/whatsapp.service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,7 +2357,15 @@ export class WAStartupService {
23572357
const isWA = (await this.whatsappNumber({ numbers: [number] }))?.shift();
23582358

23592359
this.logger.verbose(`Exists: "${isWA.exists}" | jid: ${isWA.jid}`);
2360+
23602361
if (!isWA.exists && !isJidGroup(isWA.jid) && !isWA.jid.includes('@broadcast')) {
2362+
if (this.localChatwoot.enabled) {
2363+
const body = {
2364+
key: { remoteJid: isWA.jid },
2365+
};
2366+
2367+
this.chatwootService.eventWhatsapp('contact.is_not_in_wpp', { instanceName: this.instance.name }, body);
2368+
}
23612369
throw new BadRequestException(isWA);
23622370
}
23632371

0 commit comments

Comments
 (0)