feat(chatwoot): send private message on error message sent from chatwoot

This commit is contained in:
jaison-x 2024-04-23 17:14:41 -03:00
parent 84ad8e0d6e
commit 96fdb210be

View File

@ -1119,7 +1119,7 @@ export class ChatwootService {
conversationId: conversation,
data: {
content: i18next.t('cw.message.notsent', {
error: error.length > 0 ? `_${error}_` : '',
error: error?.length > 0 ? `_${error}_` : '',
}),
message_type: 'outgoing',
private: true,
@ -1295,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) {
@ -1370,6 +1375,9 @@ export class ChatwootService {
let messageSent: MessageRaw | proto.WebMessageInfo;
try {
messageSent = await waInstance?.textMessage(data, true);
if (!messageSent) {
throw new Error('Message not sent');
}
this.updateChatwootMessageId(
{