Skip to content

Commit faed3f4

Browse files
committed
fix: improve error handling for existing contacts and simplify remoteJid processing
1 parent baff4e8 commit faed3f4

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,8 @@ export class ChatwootService {
346346

347347
return contact;
348348
} catch (error) {
349-
if (
350-
(error.status === 422 || error.response?.status === 422) &&
351-
(error.message?.includes('taken') || error.response?.data?.message?.includes('taken')) &&
352-
jid
353-
) {
354-
this.logger.warn(`Contact with identifier ${jid} already exists, trying to find it...`);
349+
if ((error.status === 422 || error.response?.status === 422) && jid) {
350+
this.logger.warn(`Contact with identifier ${jid} creation failed (422). Checking if it already exists...`);
355351
const existingContact = await this.findContactByIdentifier(instance, jid);
356352
if (existingContact) {
357353
const contactId = existingContact.id;
@@ -2535,7 +2531,7 @@ export class ChatwootService {
25352531
if (!remoteJid) {
25362532
return '';
25372533
}
2538-
return remoteJid.replace(/:\d+/, '').replace('@s.whatsapp.net', '').replace('@g.us', '').replace('@lid', '');
2534+
return remoteJid.replace(/:\d+/, '').split('@')[0];
25392535
}
25402536

25412537
public startImportHistoryMessages(instance: InstanceDto) {

0 commit comments

Comments
 (0)