Skip to content

Commit 96fdb21

Browse files
committed
feat(chatwoot): send private message on error message sent from chatwoot
1 parent 84ad8e0 commit 96fdb21

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/api/integrations/chatwoot/services/chatwoot.service.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ export class ChatwootService {
11191119
conversationId: conversation,
11201120
data: {
11211121
content: i18next.t('cw.message.notsent', {
1122-
error: error.length > 0 ? `_${error}_` : '',
1122+
error: error?.length > 0 ? `_${error}_` : '',
11231123
}),
11241124
message_type: 'outgoing',
11251125
private: true,
@@ -1295,6 +1295,11 @@ export class ChatwootService {
12951295
return { message: 'bot' };
12961296
}
12971297

1298+
if (!waInstance && body.conversation?.id) {
1299+
this.onSendMessageError(instance, body.conversation?.id, 'Instance not found');
1300+
return { message: 'bot' };
1301+
}
1302+
12981303
this.logger.verbose('Format message to send');
12991304
let formatText: string;
13001305
if (senderName === null || senderName === undefined) {
@@ -1370,6 +1375,9 @@ export class ChatwootService {
13701375
let messageSent: MessageRaw | proto.WebMessageInfo;
13711376
try {
13721377
messageSent = await waInstance?.textMessage(data, true);
1378+
if (!messageSent) {
1379+
throw new Error('Message not sent');
1380+
}
13731381

13741382
this.updateChatwootMessageId(
13751383
{

0 commit comments

Comments
 (0)