feat: implement ticket data sending via socket

master
adriano 2024-07-19 17:23:25 -03:00
parent e45e9872b2
commit 0524aef1b0
4 changed files with 15 additions and 10 deletions

View File

@ -74,7 +74,7 @@ const callJournaling = async (req, res) => {
if (operationStatus == "hangup") if (operationStatus == "hangup")
await journaling(companyId, operation, crmPhone, crmAgent, crmCallDuration, crmFirstName) await journaling(companyId, operation, crmPhone, crmAgent, crmCallDuration, crmFirstName)
else if (operationStatus == "answered") { else if (operationStatus == "update-answer") {
await ticketCRM(companyId, crmPhone, crmAgent, crmFirstName) await ticketCRM(companyId, crmPhone, crmAgent, crmFirstName)
} }

View File

@ -7,9 +7,10 @@ const { URL } = require('url')
const findProperty = require('./findProperty') const findProperty = require('./findProperty')
const CRM = require('../models/CRM') const CRM = require('../models/CRM')
const requestConfigHeader = require('./requestConfigHeader') const requestConfigHeader = require('./requestConfigHeader')
const sendMessageSocket = require('./sendMessageSocket') const sendEventTicketCreatedToSocket = require('./sendEventTicketCreatedToSocket')
async function createTicket(companyId, rest, authentication, crmPhone, crmFirstName = 'unnamed', crmLastName = 'no surname', crmEmail = '', test = {}, crmContactId) {
async function createTicket(companyId, rest, authentication, crmPhone, crmFirstName = 'unnamed', crmLastName = 'no surname', crmEmail = '', test = {}, crmContactId, crmAgent) {
let { request, body, response } = findProperty(rest, 'createTicketRecord') let { request, body, response } = findProperty(rest, 'createTicketRecord')
@ -74,6 +75,9 @@ async function createTicket(companyId, rest, authentication, crmPhone, crmFirstN
const crm = await CRM.findOne({ companyId, crmBaseURL: new URL(url).hostname }) const crm = await CRM.findOne({ companyId, crmBaseURL: new URL(url).hostname })
await CRM_Ticket.create({ companyId, contact, ticketId: auxTicketId, crm}) await CRM_Ticket.create({ companyId, contact, ticketId: auxTicketId, crm})
sendEventTicketCreatedToSocket({ companyId, extension: crmAgent, ticketUrl: `https://app.hubspot.com/contacts/44357029/ticket/${auxTicketId}` })
} }
return { exist: true, ticketId: auxTicketId, phone: crmPhone } return { exist: true, ticketId: auxTicketId, phone: crmPhone }

View File

@ -56,13 +56,13 @@ async function ticketCRM(companyId, crmPhone, crmAgent, crmFirstName = 'unnamed'
// refactor this for production. For now only working with hubspot where status new is equal 1 // refactor this for production. For now only working with hubspot where status new is equal 1
if ((auxTicketStatus && auxTicketStatus != '1') || (error && error == 404)) { if ((auxTicketStatus && auxTicketStatus != '1') || (error && error == 404)) {
await CRM_Ticket.deleteMany({ contact: obj_contact }) await CRM_Ticket.deleteMany({ contact: obj_contact })
crmFirstName = await _createTicket(rest, crmPhone, companyId, authentication, crmFirstName, contact) crmFirstName = await _createTicket(rest, crmPhone, companyId, authentication, crmFirstName, contact, crmAgent)
} }
} }
} }
else { else {
crmFirstName = await _createTicket(rest, crmPhone, companyId, authentication, crmFirstName, contact) crmFirstName = await _createTicket(rest, crmPhone, companyId, authentication, crmFirstName, contact, crmAgent)
} }
} }
@ -74,7 +74,7 @@ async function ticketCRM(companyId, crmPhone, crmAgent, crmFirstName = 'unnamed'
module.exports = ticketCRM module.exports = ticketCRM
async function _createTicket(rest, crmPhone, companyId, authentication, crmFirstName, contact) { async function _createTicket(rest, crmPhone, companyId, authentication, crmFirstName, contact, crmAgent) {
let obj = findProperty(rest, 'createTicketRecord') let obj = findProperty(rest, 'createTicketRecord')
if (obj) { if (obj) {
@ -91,7 +91,8 @@ async function _createTicket(rest, crmPhone, companyId, authentication, crmFirst
crmLastName = '', crmLastName = '',
crmEmail = '', crmEmail = '',
test = { testing: false }, test = { testing: false },
crmContactId = contact.contactId crmContactId = contact.contactId,
crmAgent
) )
} }
} }