mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-23 17:08:44 -06:00
feat(chatwoot): send private message on error message sent from chatwoot
This commit is contained in:
parent
53361682f4
commit
84ad8e0d6e
@ -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';
|
||||||
@ -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));
|
||||||
@ -1310,6 +1331,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 +1367,31 @@ export class ChatwootService {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const messageSent = await waInstance?.textMessage(data, true);
|
let messageSent: MessageRaw | proto.WebMessageInfo;
|
||||||
|
try {
|
||||||
|
messageSent = await waInstance?.textMessage(data, true);
|
||||||
|
|
||||||
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