feat: implement ticket data sending via socket
parent
e45e9872b2
commit
0524aef1b0
|
@ -74,7 +74,7 @@ const callJournaling = async (req, res) => {
|
|||
|
||||
if (operationStatus == "hangup")
|
||||
await journaling(companyId, operation, crmPhone, crmAgent, crmCallDuration, crmFirstName)
|
||||
else if (operationStatus == "answered") {
|
||||
else if (operationStatus == "update-answer") {
|
||||
await ticketCRM(companyId, crmPhone, crmAgent, crmFirstName)
|
||||
}
|
||||
|
||||
|
|
|
@ -7,9 +7,10 @@ const { URL } = require('url')
|
|||
const findProperty = require('./findProperty')
|
||||
const CRM = require('../models/CRM')
|
||||
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')
|
||||
|
||||
|
@ -73,7 +74,10 @@ async function createTicket(companyId, rest, authentication, crmPhone, crmFirstN
|
|||
const contact = await CRM_Contact.findOne({ companyId, crmBaseURL: new URL(url).hostname, phone: crmPhone })
|
||||
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 }
|
||||
|
|
|
@ -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
|
||||
if ((auxTicketStatus && auxTicketStatus != '1') || (error && error == 404)) {
|
||||
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 {
|
||||
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
|
||||
|
||||
|
||||
async function _createTicket(rest, crmPhone, companyId, authentication, crmFirstName, contact) {
|
||||
async function _createTicket(rest, crmPhone, companyId, authentication, crmFirstName, contact, crmAgent) {
|
||||
let obj = findProperty(rest, 'createTicketRecord')
|
||||
|
||||
if (obj) {
|
||||
|
@ -91,7 +91,8 @@ async function _createTicket(rest, crmPhone, companyId, authentication, crmFirst
|
|||
crmLastName = '',
|
||||
crmEmail = '',
|
||||
test = { testing: false },
|
||||
crmContactId = contact.contactId
|
||||
crmContactId = contact.contactId,
|
||||
crmAgent
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ const UploadFile = () => {
|
|||
|
||||
const formData = new FormData()
|
||||
formData.append('crm', file)
|
||||
formData.append('companyId', process.env.REACT_APP_COMPANY_ID)
|
||||
formData.append('companyId', process.env.REACT_APP_COMPANY_ID)
|
||||
|
||||
try {
|
||||
const response = await axios.post(`${process.env.REACT_APP_URL_API}/api/v1/crm/upload`, formData, {
|
||||
|
@ -42,7 +42,7 @@ const UploadFile = () => {
|
|||
'Content-Type': 'multipart/form-data',
|
||||
'Authorization': 'Bearer 2ivck10D3o9qAZi0pkKudVDl9bdEVXY2s8gdxZ0jYgL1DZWTgDz6wDiIjlWgYmJtVOoqf0b42ZTLBRrfo8WoAaScRsujz3jQUNXdchSg0o43YilZGmVhheGJNAeIQRknHEll4nRJ7avcFgmDGoYbEey7TSC8EHS4Z3gzeufYYSfnKNDBwwzBURIQrTOxYFe3tBHsGOzwnuD2lU5tnEx7tr2XRO4zRNYeNY4lMBOFM0mRuyAe4kuqTrKXmJ8As200'
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
if (response.status === 200) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue