Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat Chatwoot - Reject Message If is not a valid wpp number #394

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/utils/translations/en.json
Original file line number Diff line number Diff line change
@@ -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."
}
3 changes: 2 additions & 1 deletion src/utils/translations/pt-BR.json
Original file line number Diff line number Diff line change
@@ -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."
}
21 changes: 21 additions & 0 deletions src/whatsapp/services/chatwoot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: 'outgoing',
private: true,
},
});

return;
}

if (event === 'messages.upsert' || event === 'send.message') {
this.logger.verbose('event messages.upsert');

Expand Down
8 changes: 8 additions & 0 deletions src/whatsapp/services/whatsapp.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down