feat: Updated frontend to receive de codigoWeb from url parameter
parent
0c7612cb16
commit
64869abc23
|
@ -62,11 +62,13 @@
|
||||||
"requestEncoding": "Json",
|
"requestEncoding": "Json",
|
||||||
"requestType": "Get",
|
"requestType": "Get",
|
||||||
"responseType": "Json",
|
"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": {
|
"response": {
|
||||||
"phone": "records[0].Phone",
|
"phone": "records[0].Phone",
|
||||||
"id": "records[0].Id"
|
"id": "records[0].Id",
|
||||||
|
"accountId": "records[0].AccountId",
|
||||||
|
"name": "records[0].Name"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -54,6 +54,9 @@ async function createTicket(companyId, rest, authentication, crmPhone, crmFirstN
|
||||||
sendMessageSocket({ companyId, status: 'processing', data: { request: config, msg } })
|
sendMessageSocket({ companyId, status: 'processing', data: { request: config, msg } })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// console.log('===============> createTicket: ', JSON.stringify(config, null, 6))
|
||||||
|
|
||||||
|
|
||||||
let { data } = await axios(config)
|
let { data } = await axios(config)
|
||||||
|
|
||||||
data = flatten(data)
|
data = flatten(data)
|
||||||
|
@ -74,9 +77,9 @@ async function createTicket(companyId, rest, authentication, crmPhone, crmFirstN
|
||||||
const contact = await CRM_Contact.findOne({ companyId, crmBaseURL: new URL(url).hostname, phone: crmPhone })
|
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 })
|
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}` })
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ async function lookupContactByPhone(rest, authentication, crmPhone, companyId, t
|
||||||
let auxPhone
|
let auxPhone
|
||||||
let auxContactId
|
let auxContactId
|
||||||
let auxName
|
let auxName
|
||||||
|
let auxAccountId
|
||||||
|
|
||||||
for (const prop in data) {
|
for (const prop in data) {
|
||||||
|
|
||||||
|
@ -69,6 +70,11 @@ async function lookupContactByPhone(rest, authentication, crmPhone, companyId, t
|
||||||
auxName = data[prop]
|
auxName = data[prop]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SALESFORCE GETTING THE ACCOUNT ID
|
||||||
|
if (_prop == response?.accountId?.trim()) {
|
||||||
|
auxAccountId = data[prop]
|
||||||
|
}
|
||||||
|
|
||||||
if (_prop == response?.phone?.trim()) {
|
if (_prop == response?.phone?.trim()) {
|
||||||
auxPhone = data[prop].replace('+', '')
|
auxPhone = data[prop].replace('+', '')
|
||||||
}
|
}
|
||||||
|
@ -77,6 +83,8 @@ async function lookupContactByPhone(rest, authentication, crmPhone, companyId, t
|
||||||
auxContactId = data[prop]
|
auxContactId = data[prop]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SALESFORCE CASE LOOOK UP ALL THE OBJECT PROPERTIES
|
||||||
|
if (!url.includes('salesforce'))
|
||||||
if (auxPhone && auxContactId) break
|
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 })
|
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 }
|
return { exist: false }
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const { getAccessToken } = require('./oauth2')
|
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 = {}
|
let config = {}
|
||||||
|
|
||||||
console.log('requestConfigHeader ticketId: ', ticketId)
|
console.log('requestConfigHeader ticketId: ', ticketId)
|
||||||
|
|
|
@ -20,10 +20,10 @@ function sendEventTicketCreatedToSocket (ticketInformations) {
|
||||||
io.to(extensionAgentRoom).emit('ticket-created', { url: ticketUrl } )
|
io.to(extensionAgentRoom).emit('ticket-created', { url: ticketUrl } )
|
||||||
console.log(`${new Date().toISOString()} ==========> sendEventTicketCreatedToSocket: Ticket-created event successfully sent to: ${JSON.stringify(ticketInformations)}`)
|
console.log(`${new Date().toISOString()} ==========> sendEventTicketCreatedToSocket: Ticket-created event successfully sent to: ${JSON.stringify(ticketInformations)}`)
|
||||||
} else {
|
} 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) {
|
} 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}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ async function sfcase(companyId, crmPhone) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
const { contactId, created } = contact
|
const { contactId, created, accountId } = contact
|
||||||
|
|
||||||
let { request, body } = createCase
|
let { request, body } = createCase
|
||||||
|
|
||||||
|
@ -39,9 +39,20 @@ async function sfcase(companyId, crmPhone) {
|
||||||
const { type, userName, passWord, token, crmClientId } = authentication
|
const { type, userName, passWord, token, crmClientId } = authentication
|
||||||
const { requestContentType, requestEncoding, requestType, responseType, url } = request
|
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 {
|
try {
|
||||||
const { data } = await axios(config)
|
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`))
|
return next(new Error(`Invalid handshake header information information origin must be specified`))
|
||||||
}
|
}
|
||||||
const isFromHitphoneWebClient = origin.includes(process.env.URL_HITPHONE_FRONTEND)
|
const isFromHitphoneWebClient = origin.includes(process.env.URL_HITPHONE_FRONTEND)
|
||||||
|
//const isFromHitphoneWebClient = true
|
||||||
if (!isFromHitphoneWebClient) {
|
if (!isFromHitphoneWebClient) {
|
||||||
socket.data.isFromHitphoneWebClient = false
|
socket.data.isFromHitphoneWebClient = false
|
||||||
return next()
|
return next()
|
||||||
|
@ -59,9 +60,8 @@ const initIO = (httpServer) => {
|
||||||
|
|
||||||
io = SocketIO(httpServer, {
|
io = SocketIO(httpServer, {
|
||||||
cors: {
|
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
|
maxHttpBufferSize: 1e8
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ const initIO = (httpServer) => {
|
||||||
* CRM template frontend test
|
* CRM template frontend test
|
||||||
*/
|
*/
|
||||||
io.on("connection", socket => {
|
io.on("connection", socket => {
|
||||||
console.log('CLIENT CONNECTED')
|
console.log('=======> CLIENT CONNECTED')
|
||||||
|
|
||||||
socket.on("companySession", (companyId) => {
|
socket.on("companySession", (companyId) => {
|
||||||
console.log(`A client joined a companySession channel: ${companyId}`)
|
console.log(`A client joined a companySession channel: ${companyId}`)
|
||||||
|
|
|
@ -22,6 +22,8 @@ async function ticketCRM(companyId, crmPhone, crmAgent, crmFirstName = 'Username
|
||||||
|
|
||||||
const { crmRest: rest, authentication } = crmConfig.crm
|
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
|
// Send the ticket url link to hitphone to open on another browser tab
|
||||||
let obj = findProperty(rest, 'lookupTicket')
|
let obj = findProperty(rest, 'lookupTicket')
|
||||||
|
|
||||||
|
@ -42,6 +44,8 @@ async function ticketCRM(companyId, crmPhone, crmAgent, crmFirstName = 'Username
|
||||||
|
|
||||||
if (obj_ticket) {
|
if (obj_ticket) {
|
||||||
|
|
||||||
|
console.log('obj_ticket1: ', obj_ticket)
|
||||||
|
|
||||||
const obj_ticket_status = await lookupCRMTicket(
|
const obj_ticket_status = await lookupCRMTicket(
|
||||||
rest,
|
rest,
|
||||||
authentication,
|
authentication,
|
||||||
|
@ -63,6 +67,8 @@ async function ticketCRM(companyId, crmPhone, crmAgent, crmFirstName = 'Username
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
console.log('_createTicket xxxxx ')
|
||||||
|
|
||||||
crmFirstName = await _createTicket(rest, crmPhone, companyId, authentication, crmFirstName, contact, crmAgent)
|
crmFirstName = await _createTicket(rest, crmPhone, companyId, authentication, crmFirstName, contact, crmAgent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,6 +112,8 @@ async function _createTicket(rest, crmPhone, companyId, authentication, crmFirst
|
||||||
if (request) {
|
if (request) {
|
||||||
msg = `Tentando criar ticket para o contato ${crmPhone}`
|
msg = `Tentando criar ticket para o contato ${crmPhone}`
|
||||||
|
|
||||||
|
// console.log('xxxxxxxxxxxxxxxxxxxxxxxxx1')
|
||||||
|
|
||||||
await createTicket(companyId,
|
await createTicket(companyId,
|
||||||
rest,
|
rest,
|
||||||
authentication,
|
authentication,
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
{
|
{
|
||||||
"files": {
|
"files": {
|
||||||
"main.css": "/static/css/main.ae60ab08.css",
|
"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",
|
"index.html": "/index.html",
|
||||||
"main.ae60ab08.css.map": "/static/css/main.ae60ab08.css.map",
|
"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": [
|
"entrypoints": [
|
||||||
"static/css/main.ae60ab08.css",
|
"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 [crmPhoneTest, setCrmPhoneTest] = useState('')
|
||||||
|
|
||||||
const [file, setFile] = useState(null)
|
const [file, setFile] = useState(null)
|
||||||
|
const [codWeb, setCodweb] = useState(null)
|
||||||
const [uploadStatus, setUploadStatus] = useState('')
|
const [uploadStatus, setUploadStatus] = useState('')
|
||||||
|
|
||||||
const handleFileChange = (e) => {
|
const handleFileChange = (e) => {
|
||||||
|
@ -34,7 +35,8 @@ const UploadFile = () => {
|
||||||
|
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
formData.append('crm', file)
|
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 {
|
try {
|
||||||
const response = await axios.post(`${process.env.REACT_APP_URL_API}/api/v1/crm/upload`, formData, {
|
const response = await axios.post(`${process.env.REACT_APP_URL_API}/api/v1/crm/upload`, formData, {
|
||||||
|
@ -73,20 +75,24 @@ const UploadFile = () => {
|
||||||
|
|
||||||
useEffect(() => {
|
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 currentURL = window.location.href
|
||||||
const urlObject = new URL(currentURL)
|
const urlObject = new URL(currentURL)
|
||||||
const clientId = urlObject.searchParams.get('clientId')
|
const clientId = urlObject.searchParams.get('clientId')
|
||||||
|
const codWebFromUrl = urlObject.searchParams.get('codWeb')
|
||||||
|
if (codWebFromUrl)
|
||||||
|
setCodweb(codWebFromUrl)
|
||||||
|
|
||||||
console.log('clientId: ', clientId)
|
console.log('clientId: ', clientId)
|
||||||
|
|
||||||
if (clientId) {
|
if (clientId && codWeb) {
|
||||||
|
|
||||||
const postData = async () => {
|
const postData = async () => {
|
||||||
try {
|
try {
|
||||||
await axios.post(`${process.env.REACT_APP_URL_API}/api/v1/crm/test`, {
|
await axios.post(`${process.env.REACT_APP_URL_API}/api/v1/crm/test`, {
|
||||||
clientId,
|
clientId,
|
||||||
companyId: process.env.REACT_APP_COMPANY_ID,
|
companyId: codWeb,
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setStatus('error')
|
setStatus('error')
|
||||||
|
@ -102,7 +108,11 @@ const UploadFile = () => {
|
||||||
|
|
||||||
const socket = socketIOClient(process.env.REACT_APP_URL_API)
|
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) => {
|
socket.on('crm_upload', (data) => {
|
||||||
console.log('Received data from server:', data)
|
console.log('Received data from server:', data)
|
||||||
|
|
Loading…
Reference in New Issue