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