refactor: Remove unnecessary code for handling contact not in WhatsApp

The code changes in `whatsapp.baileys.service.ts` remove the unnecessary code that handles the case when a contact is not in WhatsApp. The code was previously sending a notification to Chatwoot, but it is no longer needed. This change improves the code by removing unnecessary complexity.
This commit is contained in:
Deivison Lincoln
2024-10-16 15:31:54 -03:00
parent ec2b7f94f8
commit a6fb8cbd30
3 changed files with 20 additions and 36 deletions

View File

@@ -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>('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);
}

View File

@@ -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;