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,
|
inbox,
|
||||||
} from '@figuro/chatwoot-sdk';
|
} from '@figuro/chatwoot-sdk';
|
||||||
import { request as chatwootRequest } from '@figuro/chatwoot-sdk/dist/core/request';
|
import { request as chatwootRequest } from '@figuro/chatwoot-sdk/dist/core/request';
|
||||||
|
import { proto } from '@whiskeysockets/baileys';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import FormData from 'form-data';
|
import FormData from 'form-data';
|
||||||
import { createReadStream, unlinkSync, writeFileSync } from 'fs';
|
import { createReadStream, unlinkSync, writeFileSync } from 'fs';
|
||||||
@ -628,7 +629,7 @@ export class ChatwootService {
|
|||||||
id: contactId,
|
id: contactId,
|
||||||
})) as any;
|
})) as any;
|
||||||
|
|
||||||
if (contactConversations) {
|
if (contactConversations?.payload?.length) {
|
||||||
let conversation: any;
|
let conversation: any;
|
||||||
if (this.provider.reopen_conversation) {
|
if (this.provider.reopen_conversation) {
|
||||||
conversation = contactConversations.payload.find((conversation) => conversation.inbox_id == filterInbox.id);
|
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) {
|
public async receiveWebhook(instance: InstanceDto, body: any) {
|
||||||
try {
|
try {
|
||||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||||
@ -1274,6 +1295,11 @@ export class ChatwootService {
|
|||||||
return { message: 'bot' };
|
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');
|
this.logger.verbose('Format message to send');
|
||||||
let formatText: string;
|
let formatText: string;
|
||||||
if (senderName === null || senderName === undefined) {
|
if (senderName === null || senderName === undefined) {
|
||||||
@ -1310,6 +1336,9 @@ export class ChatwootService {
|
|||||||
formatText,
|
formatText,
|
||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
|
if (!messageSent && body.conversation?.id) {
|
||||||
|
this.onSendMessageError(instance, body.conversation?.id);
|
||||||
|
}
|
||||||
|
|
||||||
this.updateChatwootMessageId(
|
this.updateChatwootMessageId(
|
||||||
{
|
{
|
||||||
@ -1343,23 +1372,34 @@ 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(
|
this.updateChatwootMessageId(
|
||||||
{
|
{
|
||||||
...messageSent,
|
...messageSent,
|
||||||
owner: instance.instanceName,
|
owner: instance.instanceName,
|
||||||
},
|
|
||||||
{
|
|
||||||
messageId: body.id,
|
|
||||||
inboxId: body.inbox?.id,
|
|
||||||
conversationId: body.conversation?.id,
|
|
||||||
contactInbox: {
|
|
||||||
sourceId: body.conversation?.contact_inbox?.source_id,
|
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
instance,
|
messageId: body.id,
|
||||||
);
|
inboxId: body.inbox?.id,
|
||||||
|
conversationId: body.conversation?.id,
|
||||||
|
contactInbox: {
|
||||||
|
sourceId: body.conversation?.contact_inbox?.source_id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
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.contact": "Contact",
|
||||||
"cw.contactMessage.name": "Name",
|
"cw.contactMessage.name": "Name",
|
||||||
"cw.contactMessage.number": "Number",
|
"cw.contactMessage.number": "Number",
|
||||||
|
"cw.message.notsent": "🚨 The message could not be sent. Please check your connection. {{error}}",
|
||||||
"cw.message.edited": "Edited Message"
|
"cw.message.edited": "Edited Message"
|
||||||
}
|
}
|
@ -22,5 +22,6 @@
|
|||||||
"cw.contactMessage.contact": "Contacto",
|
"cw.contactMessage.contact": "Contacto",
|
||||||
"cw.contactMessage.name": "Nombre",
|
"cw.contactMessage.name": "Nombre",
|
||||||
"cw.contactMessage.number": "Numero",
|
"cw.contactMessage.number": "Numero",
|
||||||
|
"cw.message.notsent": "🚨 El mensaje no se pudo enviar. Comprueba tu conexión. {{error}}",
|
||||||
"cw.message.edited": "Mensaje editado"
|
"cw.message.edited": "Mensaje editado"
|
||||||
}
|
}
|
@ -22,5 +22,6 @@
|
|||||||
"cw.contactMessage.contact": "Contato",
|
"cw.contactMessage.contact": "Contato",
|
||||||
"cw.contactMessage.name": "Nome",
|
"cw.contactMessage.name": "Nome",
|
||||||
"cw.contactMessage.number": "Número",
|
"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"
|
"cw.message.edited": "Mensagem editada"
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user