Merge pull request #986 from deivisonrpg/refactor-onSendMessageError

refactor: Remove unnecessary code for handling contact not in WhatsApp and onSendMessageError
This commit is contained in:
Davidson Gomes
2024-10-17 10:17:32 -03:00
committed by GitHub
5 changed files with 22 additions and 38 deletions

View File

@@ -1137,19 +1137,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,
@@ -1393,7 +1409,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;
}
@@ -1853,27 +1869,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;