feat: Updated frontend to receive de codigoWeb from url parameter
parent
0c7612cb16
commit
64869abc23
|
@ -62,11 +62,13 @@
|
|||
"requestEncoding": "Json",
|
||||
"requestType": "Get",
|
||||
"responseType": "Json",
|
||||
"url": "https://nocompany-a9-dev-ed.develop.my.salesforce.com/services/data/v61.0/query/?q=SELECT+Id,+Phone+FROM+Contact+WHERE+Phone='crmPhone'"
|
||||
"url": "https://nocompany-a9-dev-ed.develop.my.salesforce.com/services/data/v61.0/query/?q=SELECT+Id,+Phone,+AccountId+FROM+Contact+WHERE+Phone='crmPhone'"
|
||||
},
|
||||
"response": {
|
||||
"phone": "records[0].Phone",
|
||||
"id": "records[0].Id"
|
||||
"id": "records[0].Id",
|
||||
"accountId": "records[0].AccountId",
|
||||
"name": "records[0].Name"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -84,4 +84,4 @@ const port = process.env.PORT || 3000
|
|||
|
||||
const server = app.listen(port, console.log(`Listening on port: ${port}...`))
|
||||
|
||||
initIO(server)
|
||||
initIO(server)
|
||||
|
|
|
@ -11,12 +11,12 @@ const sendEventTicketCreatedToSocket = require('./sendEventTicketCreatedToSocket
|
|||
|
||||
|
||||
async function createTicket(companyId, rest, authentication, crmPhone, crmFirstName = 'Username', crmLastName = 'Last name', crmEmail = '', test = {}, crmContactId, crmAgent) {
|
||||
|
||||
|
||||
let { request, body, response } = findProperty(rest, 'createTicketRecord')
|
||||
|
||||
const { requestContentType, requestEncoding, requestType, responseType, url } = request
|
||||
|
||||
|
||||
|
||||
|
||||
body = flatten(body)
|
||||
|
||||
const mapping = {
|
||||
|
@ -54,6 +54,9 @@ async function createTicket(companyId, rest, authentication, crmPhone, crmFirstN
|
|||
sendMessageSocket({ companyId, status: 'processing', data: { request: config, msg } })
|
||||
}
|
||||
|
||||
// console.log('===============> createTicket: ', JSON.stringify(config, null, 6))
|
||||
|
||||
|
||||
let { data } = await axios(config)
|
||||
|
||||
data = flatten(data)
|
||||
|
@ -68,15 +71,15 @@ async function createTicket(companyId, rest, authentication, crmPhone, crmFirstN
|
|||
auxTicketId = data[prop]
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (auxTicketId && !test?.testing) {
|
||||
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}` })
|
||||
sendEventTicketCreatedToSocket({ companyId, extension: crmAgent, ticketUrl: `https://app.hubspot.com/contacts/23636141/ticket/${auxTicketId}` })
|
||||
|
||||
}
|
||||
|
||||
|
@ -84,4 +87,4 @@ async function createTicket(companyId, rest, authentication, crmPhone, crmFirstN
|
|||
|
||||
}
|
||||
|
||||
module.exports = createTicket
|
||||
module.exports = createTicket
|
||||
|
|
|
@ -39,6 +39,7 @@ async function lookupContactByPhone(rest, authentication, crmPhone, companyId, t
|
|||
let auxPhone
|
||||
let auxContactId
|
||||
let auxName
|
||||
let auxAccountId
|
||||
|
||||
for (const prop in data) {
|
||||
|
||||
|
@ -69,6 +70,11 @@ async function lookupContactByPhone(rest, authentication, crmPhone, companyId, t
|
|||
auxName = data[prop]
|
||||
}
|
||||
|
||||
// SALESFORCE GETTING THE ACCOUNT ID
|
||||
if (_prop == response?.accountId?.trim()) {
|
||||
auxAccountId = data[prop]
|
||||
}
|
||||
|
||||
if (_prop == response?.phone?.trim()) {
|
||||
auxPhone = data[prop].replace('+', '')
|
||||
}
|
||||
|
@ -77,7 +83,9 @@ async function lookupContactByPhone(rest, authentication, crmPhone, companyId, t
|
|||
auxContactId = data[prop]
|
||||
}
|
||||
|
||||
if (auxPhone && auxContactId) break
|
||||
// SALESFORCE CASE LOOOK UP ALL THE OBJECT PROPERTIES
|
||||
if (!url.includes('salesforce'))
|
||||
if (auxPhone && auxContactId) break
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +97,7 @@ async function lookupContactByPhone(rest, authentication, crmPhone, companyId, t
|
|||
await CRM_Contact.create({ companyId, crm, crmBaseURL: new URL(url).hostname, contactId: auxContactId, phone: auxPhone })
|
||||
}
|
||||
|
||||
return { exist: true, contactId: auxContactId, phone: crmPhone, name: auxName }
|
||||
return { exist: true, contactId: auxContactId, phone: crmPhone, name: auxName, accountId: auxAccountId }
|
||||
}
|
||||
|
||||
return { exist: false }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const { getAccessToken } = require('./oauth2')
|
||||
|
||||
async function requestConfigHeader(url, crmPhone, requestType, requestContentType, type, userName, passWord, token, crmClientId, data = '', ticketId='') {
|
||||
async function requestConfigHeader(url, crmPhone, requestType, requestContentType, type, userName, passWord, token, crmClientId, data = '', ticketId = '') {
|
||||
let config = {}
|
||||
|
||||
console.log('requestConfigHeader ticketId: ', ticketId)
|
||||
|
@ -14,7 +14,7 @@ async function requestConfigHeader(url, crmPhone, requestType, requestContentTyp
|
|||
else if (requestType.trim().toLowerCase() == 'get') {
|
||||
url = `${url}&api_token=${token}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let commonConfig = {
|
||||
method: requestType,
|
||||
|
|
|
@ -20,11 +20,11 @@ function sendEventTicketCreatedToSocket (ticketInformations) {
|
|||
io.to(extensionAgentRoom).emit('ticket-created', { url: ticketUrl } )
|
||||
console.log(`${new Date().toISOString()} ==========> sendEventTicketCreatedToSocket: Ticket-created event successfully sent to: ${JSON.stringify(ticketInformations)}`)
|
||||
} else {
|
||||
console.log(`${new Date().toISOString()} ==========> sendEventTicketCreatedToSocket: Unable to send the event ticket-created because the Extension Agent (CompanyID: ${extension} | Extension: ${extension}) is not connected to the Hitphone`)
|
||||
console.log(`${new Date().toISOString()} ==========> sendEventTicketCreatedToSocket: Unable to send the event ticket-created because the Extension Agent (CompanyID: ${companyId} | Extension: ${extension}) is not connected to the Hitphone`)
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`${new Date().toISOString()} ==========> sendEventTicketCreatedToSocket: Unable to send the event ticket-created to Extension Agent (CompanyID: ${extension} | Extension: ${extension}) because an error occurred: \n${error}`)
|
||||
console.log(`${new Date().toISOString()} ==========> sendEventTicketCreatedToSocket: Unable to send the event ticket-created to Extension Agent (CompanyID: ${companyId} | Extension: ${extension}) because an error occurred: \n${error}`)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = sendEventTicketCreatedToSocket
|
||||
module.exports = sendEventTicketCreatedToSocket
|
||||
|
|
|
@ -29,7 +29,7 @@ async function sfcase(companyId, crmPhone) {
|
|||
break
|
||||
}
|
||||
|
||||
const { contactId, created } = contact
|
||||
const { contactId, created, accountId } = contact
|
||||
|
||||
let { request, body } = createCase
|
||||
|
||||
|
@ -39,9 +39,20 @@ async function sfcase(companyId, crmPhone) {
|
|||
const { type, userName, passWord, token, crmClientId } = authentication
|
||||
const { requestContentType, requestEncoding, requestType, responseType, url } = request
|
||||
|
||||
const config = await requestConfigHeader(url, crmPhone, requestType, requestContentType, type, userName, passWord, token, crmClientId, body)
|
||||
let config = await requestConfigHeader(url, crmPhone, requestType, requestContentType, type, userName, passWord, token, crmClientId, body)
|
||||
|
||||
console.log("====> config: ", config)
|
||||
console.log("====> accountId: ", accountId, " | contactId: ", contactId)
|
||||
|
||||
|
||||
if (accountId && contactId)
|
||||
config.data = {
|
||||
...config.data, ...{
|
||||
ContactId: contactId,
|
||||
AccountId: accountId
|
||||
}
|
||||
}
|
||||
|
||||
console.log("====> create case request config: ", config)
|
||||
|
||||
try {
|
||||
const { data } = await axios(config)
|
||||
|
|
|
@ -12,6 +12,7 @@ const onSocketHandshakeAuthVerifier = (socket, next) => {
|
|||
return next(new Error(`Invalid handshake header information information origin must be specified`))
|
||||
}
|
||||
const isFromHitphoneWebClient = origin.includes(process.env.URL_HITPHONE_FRONTEND)
|
||||
//const isFromHitphoneWebClient = true
|
||||
if (!isFromHitphoneWebClient) {
|
||||
socket.data.isFromHitphoneWebClient = false
|
||||
return next()
|
||||
|
@ -59,9 +60,8 @@ const initIO = (httpServer) => {
|
|||
|
||||
io = SocketIO(httpServer, {
|
||||
cors: {
|
||||
origin: IS_DEV ? "*" : [process.env.URL_OAUTH_FRONTEND_SUCCESS_REDIRECT, 'https://integracao-crm.hitmanager.app.br', process.env.URL_HITPHONE_FRONTEND]
|
||||
origin: IS_DEV ? "*" : [process.env.URL_OAUTH_FRONTEND_SUCCESS_REDIRECT, 'https://integracao-crm.hitmanager.app.br', process.env.URL_HITPHONE_FRONTEND, "*"]
|
||||
},
|
||||
|
||||
maxHttpBufferSize: 1e8
|
||||
})
|
||||
|
||||
|
@ -79,7 +79,7 @@ const initIO = (httpServer) => {
|
|||
* CRM template frontend test
|
||||
*/
|
||||
io.on("connection", socket => {
|
||||
console.log('CLIENT CONNECTED')
|
||||
console.log('=======> CLIENT CONNECTED')
|
||||
|
||||
socket.on("companySession", (companyId) => {
|
||||
console.log(`A client joined a companySession channel: ${companyId}`)
|
||||
|
@ -101,4 +101,4 @@ const getIO = () => {
|
|||
return io
|
||||
}
|
||||
|
||||
module.exports = { initIO, getIO }
|
||||
module.exports = { initIO, getIO }
|
||||
|
|
|
@ -4,7 +4,7 @@ const sendMessageSocket = require('./sendMessageSocket')
|
|||
const findProperty = require('./findProperty')
|
||||
const journalingRequest = require('./journalingRequest')
|
||||
|
||||
async function templateValidator(crmPhoneTest, crm, companyId) {
|
||||
async function templateValidator(crmPhoneTest, crm, companyId) {
|
||||
|
||||
let phoneTest = crmPhoneTest ? crmPhoneTest : '5511900112233'
|
||||
|
||||
|
@ -13,12 +13,12 @@ async function templateValidator(crmPhoneTest, crm, companyId) {
|
|||
authentication = crm.authentication,
|
||||
crmPhone = phoneTest,
|
||||
companyId,
|
||||
test = { testing: true })
|
||||
test = { testing: true })
|
||||
|
||||
if (!contact.exist) {
|
||||
|
||||
console.log('O CONTATO SER CRIADO')
|
||||
|
||||
console.log('O CONTATO SER CRIADO')
|
||||
|
||||
contact = await createContact(companyId,
|
||||
rest = crm.crmRest,
|
||||
authentication = crm.authentication,
|
||||
|
@ -26,7 +26,7 @@ async function templateValidator(crmPhoneTest, crm, companyId) {
|
|||
crmFirstName = 'Username',
|
||||
crmLastName = '',
|
||||
crmEmail = '',
|
||||
test = { testing: true })
|
||||
test = { testing: true })
|
||||
|
||||
sendMessageSocket({ companyId, status: 'processing', data: { msg } })
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ async function ticketCRM(companyId, crmPhone, crmAgent, crmFirstName = 'Username
|
|||
|
||||
const { crmRest: rest, authentication } = crmConfig.crm
|
||||
|
||||
// console.log("ticketCRM crmRest: ", JSON.stringify(rest, null, 6))
|
||||
|
||||
// Send the ticket url link to hitphone to open on another browser tab
|
||||
let obj = findProperty(rest, 'lookupTicket')
|
||||
|
||||
|
@ -42,6 +44,8 @@ async function ticketCRM(companyId, crmPhone, crmAgent, crmFirstName = 'Username
|
|||
|
||||
if (obj_ticket) {
|
||||
|
||||
console.log('obj_ticket1: ', obj_ticket)
|
||||
|
||||
const obj_ticket_status = await lookupCRMTicket(
|
||||
rest,
|
||||
authentication,
|
||||
|
@ -63,6 +67,8 @@ async function ticketCRM(companyId, crmPhone, crmAgent, crmFirstName = 'Username
|
|||
|
||||
}
|
||||
else {
|
||||
console.log('_createTicket xxxxx ')
|
||||
|
||||
crmFirstName = await _createTicket(rest, crmPhone, companyId, authentication, crmFirstName, contact, crmAgent)
|
||||
}
|
||||
|
||||
|
@ -106,6 +112,8 @@ async function _createTicket(rest, crmPhone, companyId, authentication, crmFirst
|
|||
if (request) {
|
||||
msg = `Tentando criar ticket para o contato ${crmPhone}`
|
||||
|
||||
// console.log('xxxxxxxxxxxxxxxxxxxxxxxxx1')
|
||||
|
||||
await createTicket(companyId,
|
||||
rest,
|
||||
authentication,
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
{
|
||||
"files": {
|
||||
"main.css": "/static/css/main.ae60ab08.css",
|
||||
"main.js": "/static/js/main.e52625df.js",
|
||||
"main.js": "/static/js/main.2166c932.js",
|
||||
"index.html": "/index.html",
|
||||
"main.ae60ab08.css.map": "/static/css/main.ae60ab08.css.map",
|
||||
"main.e52625df.js.map": "/static/js/main.e52625df.js.map"
|
||||
"main.2166c932.js.map": "/static/js/main.2166c932.js.map"
|
||||
},
|
||||
"entrypoints": [
|
||||
"static/css/main.ae60ab08.css",
|
||||
"static/js/main.e52625df.js"
|
||||
"static/js/main.2166c932.js"
|
||||
]
|
||||
}
|
|
@ -1 +1 @@
|
|||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.e52625df.js"></script><link href="/static/css/main.ae60ab08.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|
||||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.2166c932.js"></script><link href="/static/css/main.ae60ab08.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -19,6 +19,7 @@ const UploadFile = () => {
|
|||
const [crmPhoneTest, setCrmPhoneTest] = useState('')
|
||||
|
||||
const [file, setFile] = useState(null)
|
||||
const [codWeb, setCodweb] = useState(null)
|
||||
const [uploadStatus, setUploadStatus] = useState('')
|
||||
|
||||
const handleFileChange = (e) => {
|
||||
|
@ -34,7 +35,8 @@ 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)
|
||||
formData.append('companyId', codWeb)
|
||||
|
||||
try {
|
||||
const response = await axios.post(`${process.env.REACT_APP_URL_API}/api/v1/crm/upload`, formData, {
|
||||
|
@ -73,20 +75,24 @@ const UploadFile = () => {
|
|||
|
||||
useEffect(() => {
|
||||
|
||||
console.log('process.env.REACT_APP_COMPANY_ID: ', process.env.REACT_APP_COMPANY_ID)
|
||||
// console.log('process.env.REACT_APP_COMPANY_ID: ', process.env.REACT_APP_COMPANY_ID)
|
||||
|
||||
const currentURL = window.location.href
|
||||
const urlObject = new URL(currentURL)
|
||||
const clientId = urlObject.searchParams.get('clientId')
|
||||
const codWebFromUrl = urlObject.searchParams.get('codWeb')
|
||||
if (codWebFromUrl)
|
||||
setCodweb(codWebFromUrl)
|
||||
|
||||
console.log('clientId: ', clientId)
|
||||
|
||||
if (clientId) {
|
||||
if (clientId && codWeb) {
|
||||
|
||||
const postData = async () => {
|
||||
try {
|
||||
await axios.post(`${process.env.REACT_APP_URL_API}/api/v1/crm/test`, {
|
||||
clientId,
|
||||
companyId: process.env.REACT_APP_COMPANY_ID,
|
||||
companyId: codWeb,
|
||||
})
|
||||
} catch (error) {
|
||||
setStatus('error')
|
||||
|
@ -102,7 +108,11 @@ const UploadFile = () => {
|
|||
|
||||
const socket = socketIOClient(process.env.REACT_APP_URL_API)
|
||||
|
||||
socket.emit('companySession', process.env.REACT_APP_COMPANY_ID)
|
||||
|
||||
console.log('==============> codWebFromUrl: ', codWebFromUrl)
|
||||
|
||||
if (codWebFromUrl)
|
||||
socket.emit('companySession', codWebFromUrl)
|
||||
|
||||
socket.on('crm_upload', (data) => {
|
||||
console.log('Received data from server:', data)
|
||||
|
|
Loading…
Reference in New Issue