Skip to content

Commit b3adde3

Browse files
committed
Feat Reject Message If is not a valid wpp number
1 parent b095465 commit b3adde3

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
@@ -1684,6 +1684,27 @@ export class ChatwootService {
16841684
return null;
16851685
}
16861686

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

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)