mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-18 19:32:21 -06:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user