From 9705157bddc4d86e8c989740ba1c835f5816d818 Mon Sep 17 00:00:00 2001 From: adriano Date: Fri, 11 Apr 2025 12:58:35 -0300 Subject: [PATCH] feat(integration/omnihit): update config to allow ticket creation without assigned queue --- backend/controllers/crmController.js | 23 +++++++++++++++-------- backend/data/omihitV2IntegrationCRM.json | 3 +-- backend/utils/lookupCRMContactByPhone.js | 2 +- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/backend/controllers/crmController.js b/backend/controllers/crmController.js index 96eb2a5..28dc349 100644 --- a/backend/controllers/crmController.js +++ b/backend/controllers/crmController.js @@ -273,7 +273,7 @@ const testTemplate = async (req, res) => { crmOauth = crmOauth.toObject() const { crmPhoneTest } = crmOauth.crm.authentication - + await templateValidator(crmPhoneTest, crmOauth.crm, companyId) crmOauth = await CRM.findOne({ 'crm.authentication.crmClientId': clientId, 'companyId': companyId }) @@ -411,12 +411,19 @@ const webhook = async (req, res) => { if (!req.body?.meta) return res.status(StatusCodes.OK).send() - let { name, phone_number } = req.body.meta.sender + let { name, phone_number } = req.body.meta.sender + + const {id: ticketId, account_id: accountId} = req.body - const ticketId = req.body?.id + //channel: 'Channel::FacebookPage' + console.log("2 =============> ticketId id: ", ticketId, " | accountId account_id: ",accountId) - // const accountId = req.body.account_id - const accountId = "15" + if (!phone_number) { + + console.log("=============> Ignored process phone_number: ", phone_number, " | 'Channel::FacebookPage'") + + return res.send() + } let crmPhone = phone_number.replace('+', '') @@ -496,9 +503,9 @@ const webhook_crm = async (req, res) => { }) console.log('==========> crm whoId: ', whoId) - console.log('==========> crm contact: ', contact) - - if(!contact) return res.send() + console.log('==========> crm contact: ', contact) + + if (!contact) return res.send() const { phone } = contact diff --git a/backend/data/omihitV2IntegrationCRM.json b/backend/data/omihitV2IntegrationCRM.json index c0dd0f7..2645cf3 100644 --- a/backend/data/omihitV2IntegrationCRM.json +++ b/backend/data/omihitV2IntegrationCRM.json @@ -10,8 +10,7 @@ }, "createConversation":{ "inbox_id": "2", - "status":"pending", - "team_id": "1" + "status":"pending" } } diff --git a/backend/utils/lookupCRMContactByPhone.js b/backend/utils/lookupCRMContactByPhone.js index 184a871..78fbbd7 100644 --- a/backend/utils/lookupCRMContactByPhone.js +++ b/backend/utils/lookupCRMContactByPhone.js @@ -153,7 +153,7 @@ async function lookupContactByPhone(rest, authentication, crmPhone, companyId, t } } - console.log('---------> auxPhone: ', auxPhone, ' | auxContactId: ', auxContactId) + console.log('---------> auxPhone: ', auxPhone, ' | auxContactId: ', auxContactId, ' | auxAccountId: ', auxAccountId) if (auxPhone) {