mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-22 03:56:54 -06:00
Merge branch 'develop' of github.com:EvolutionAPI/evolution-api into develop
This commit is contained in:
commit
0ad3acaf07
@ -8,6 +8,7 @@ import ChatwootClient, {
|
||||
inbox,
|
||||
} from '@figuro/chatwoot-sdk';
|
||||
import { request as chatwootRequest } from '@figuro/chatwoot-sdk/dist/core/request';
|
||||
import { proto } from '@whiskeysockets/baileys';
|
||||
import axios from 'axios';
|
||||
import FormData from 'form-data';
|
||||
import { createReadStream, unlinkSync, writeFileSync } from 'fs';
|
||||
@ -628,7 +629,7 @@ export class ChatwootService {
|
||||
id: contactId,
|
||||
})) as any;
|
||||
|
||||
if (contactConversations) {
|
||||
if (contactConversations?.payload?.length) {
|
||||
let conversation: any;
|
||||
if (this.provider.reopen_conversation) {
|
||||
conversation = contactConversations.payload.find((conversation) => conversation.inbox_id == filterInbox.id);
|
||||
@ -1106,6 +1107,26 @@ export class ChatwootService {
|
||||
}
|
||||
}
|
||||
|
||||
public async onSendMessageError(instance: InstanceDto, conversation: number, error?: string) {
|
||||
const client = await this.clientCw(instance);
|
||||
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
|
||||
client.messages.create({
|
||||
accountId: this.provider.account_id,
|
||||
conversationId: conversation,
|
||||
data: {
|
||||
content: i18next.t('cw.message.notsent', {
|
||||
error: error?.length > 0 ? `_${error}_` : '',
|
||||
}),
|
||||
message_type: 'outgoing',
|
||||
private: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
public async receiveWebhook(instance: InstanceDto, body: any) {
|
||||
try {
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
@ -1274,6 +1295,11 @@ export class ChatwootService {
|
||||
return { message: 'bot' };
|
||||
}
|
||||
|
||||
if (!waInstance && body.conversation?.id) {
|
||||
this.onSendMessageError(instance, body.conversation?.id, 'Instance not found');
|
||||
return { message: 'bot' };
|
||||
}
|
||||
|
||||
this.logger.verbose('Format message to send');
|
||||
let formatText: string;
|
||||
if (senderName === null || senderName === undefined) {
|
||||
@ -1310,6 +1336,9 @@ export class ChatwootService {
|
||||
formatText,
|
||||
options,
|
||||
);
|
||||
if (!messageSent && body.conversation?.id) {
|
||||
this.onSendMessageError(instance, body.conversation?.id);
|
||||
}
|
||||
|
||||
this.updateChatwootMessageId(
|
||||
{
|
||||
@ -1343,7 +1372,12 @@ export class ChatwootService {
|
||||
},
|
||||
};
|
||||
|
||||
const messageSent = await waInstance?.textMessage(data, true);
|
||||
let messageSent: MessageRaw | proto.WebMessageInfo;
|
||||
try {
|
||||
messageSent = await waInstance?.textMessage(data, true);
|
||||
if (!messageSent) {
|
||||
throw new Error('Message not sent');
|
||||
}
|
||||
|
||||
this.updateChatwootMessageId(
|
||||
{
|
||||
@ -1360,6 +1394,12 @@ export class ChatwootService {
|
||||
},
|
||||
instance,
|
||||
);
|
||||
} catch (error) {
|
||||
if (!messageSent && body.conversation?.id) {
|
||||
this.onSendMessageError(instance, body.conversation?.id, error.toString());
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,5 +22,6 @@
|
||||
"cw.contactMessage.contact": "Contact",
|
||||
"cw.contactMessage.name": "Name",
|
||||
"cw.contactMessage.number": "Number",
|
||||
"cw.message.notsent": "🚨 The message could not be sent. Please check your connection. {{error}}",
|
||||
"cw.message.edited": "Edited Message"
|
||||
}
|
@ -22,5 +22,6 @@
|
||||
"cw.contactMessage.contact": "Contacto",
|
||||
"cw.contactMessage.name": "Nombre",
|
||||
"cw.contactMessage.number": "Numero",
|
||||
"cw.message.notsent": "🚨 El mensaje no se pudo enviar. Comprueba tu conexión. {{error}}",
|
||||
"cw.message.edited": "Mensaje editado"
|
||||
}
|
@ -22,5 +22,6 @@
|
||||
"cw.contactMessage.contact": "Contato",
|
||||
"cw.contactMessage.name": "Nome",
|
||||
"cw.contactMessage.number": "Número",
|
||||
"cw.message.notsent": "🚨 Não foi possível enviar a mensagem. Verifique sua conexão. {{error}}",
|
||||
"cw.message.edited": "Mensagem editada"
|
||||
}
|
Loading…
Reference in New Issue
Block a user