feat(integration): add crmAccountId field to allow dynamic CRM account ID in integration template

master
adriano 2025-04-11 16:32:24 -03:00
parent 9705157bdd
commit a7763a5e56
10 changed files with 935 additions and 16 deletions

View File

@ -0,0 +1,236 @@
{
"authentication":{
"type":"bearer",
"token":"pat-na1-e83c1bfa-1a58-498b-8027-f6fdbb9f237d",
"crmPhoneTest":"5514987659932",
"crmAccountId":"23636141"
},
"crmRest":[
{
"createContactRecord":{
"request":{
"requestContentType":"application/json",
"requestEncoding":"Json",
"requestType":"Post",
"responseType":"Json",
"url":"https://api.hubapi.com/contacts/v1/contact"
},
"body":{
"properties":[
{
"property":"phone",
"value":"crmPhone"
}
]
},
"response":{
"id":"vid"
}
}
},
{
"lookupContactByPhone":{
"request":{
"requestContentType":"application/json",
"requestEncoding":"Json",
"requestType":"Get",
"responseType":"Json",
"url":"https://api.hubapi.com/contacts/v1/search/query?q=crmPhone"
},
"response":{
"phone":"contacts.properties.phone.value",
"id":"contacts.vid"
}
}
},
{
"callJournaling":{
"request":{
"requestContentType":"application/json",
"requestEncoding":"Json",
"requestType":"Post",
"responseType":"Json",
"url":"https://api.hubapi.com/engagements/v1/engagements"
},
"calls":[
{
"inboundAnsweredCall":{
"engagement":{
"active":true,
"type":"CALL"
},
"associations":{
"contactIds":[
{
"_prop":"crmContactId",
"_type":"number"
}
]
},
"metadata":{
"toNumber":{
"_prop":"crmAgent",
"_type":"string"
},
"fromNumber":{
"_prop":"crmPhone",
"_type":"string"
},
"status":"COMPLETED",
"durationMilliseconds":{
"_prop":"crmCallDuration",
"_type":"number",
"_format":"milliseconds"
},
"body":"Ligação recebida - Chamada entrante",
"disposition":"f240bbac-87c9-4f6e-bf70-924b57d47db7"
}
}
},
{
"inboundMissedCall":{
"engagement":{
"active":true,
"type":"CALL"
},
"associations":{
"contactIds":[
{
"_prop":"crmContactId",
"_type":"number"
}
]
},
"metadata":{
"toNumber":{
"_prop":"crmAgent",
"_type":"string"
},
"fromNumber":{
"_prop":"crmPhone",
"_type":"string"
},
"status":"COMPLETED",
"body":"Ligação perdida - Chamada entrante",
"disposition":"f240bbac-87c9-4f6e-bf70-924b57d47db7"
}
}
},
{
"outboundAnsweredCall":{
"engagement":{
"active":true,
"type":"CALL"
},
"associations":{
"contactIds":[
{
"_prop":"crmContactId",
"_type":"number"
}
]
},
"metadata":{
"fromNumber":{
"_prop":"crmPhone",
"_type":"string"
},
"toNumber":{
"_prop":"crmAgent",
"_type":"string"
},
"status":"COMPLETED",
"durationMilliseconds":{
"_prop":"crmCallDuration",
"_type":"number",
"_format":"milliseconds"
},
"body":"Ligação atendida - outbound call",
"disposition":"f240bbac-87c9-4f6e-bf70-924b57d47db7"
}
}
},
{
"outboundUnansweredCall":{
"engagement":{
"active":true,
"type":"CALL"
},
"associations":{
"contactIds":[
{
"_prop":"crmContactId",
"_type":"number"
}
]
},
"metadata":{
"fromNumber":{
"_prop":"crmAgent",
"_type":"string"
},
"toNumber":{
"_prop":"crmPhone",
"_type":"string"
},
"status":"COMPLETED",
"body":"Ligação perdida - oubound call",
"disposition":"f240bbac-87c9-4f6e-bf70-924b57d47db7"
}
}
}
]
}
},
{
"createTicketRecord":{
"request":{
"requestContentType":"application/json",
"requestEncoding":"Json",
"requestType":"Post",
"responseType":"Json",
"url":"https://api.hubapi.com/crm/v3/objects/tickets"
},
"body":{
"properties":{
"hs_pipeline":"24955700",
"hs_pipeline_stage":"57851009",
"hs_ticket_priority":"HIGH",
"subject":"Ticket criado a partir da URA"
},
"associations":[
{
"to":{
"id":"crmContactId"
},
"types":[
{
"associationCategory":"HUBSPOT_DEFINED",
"associationTypeId":16
}
]
}
]
},
"response":{
"id":"id"
}
}
},
{
"lookupTicket":{
"request":{
"requestContentType":"application/json",
"requestEncoding":"Json",
"requestType":"Get",
"responseType":"Json",
"url":"https://api.hubapi.com/crm/v3/objects/tickets/ticketId"
},
"response":{
"status":"properties.hs_pipeline_stage",
"id":"id"
}
}
}
]
}

View File

@ -0,0 +1,235 @@
{
"authentication":{
"type":"bearer",
"token":"pat-na1-37da6668-e0b1-44cb-bd2d-596f5f65634a",
"crmPhoneTest":"5514987659932"
},
"crmRest":[
{
"createContactRecord":{
"request":{
"requestContentType":"application/json",
"requestEncoding":"Json",
"requestType":"Post",
"responseType":"Json",
"url":"https://api.hubapi.com/contacts/v1/contact"
},
"body":{
"properties":[
{
"property":"phone",
"value":"crmPhone"
}
]
},
"response":{
"id":"vid"
}
}
},
{
"lookupContactByPhone":{
"request":{
"requestContentType":"application/json",
"requestEncoding":"Json",
"requestType":"Get",
"responseType":"Json",
"url":"https://api.hubapi.com/contacts/v1/search/query?q=crmPhone"
},
"response":{
"phone":"contacts.properties.phone.value",
"id":"contacts.vid"
}
}
},
{
"callJournaling":{
"request":{
"requestContentType":"application/json",
"requestEncoding":"Json",
"requestType":"Post",
"responseType":"Json",
"url":"https://api.hubapi.com/engagements/v1/engagements"
},
"calls":[
{
"inboundAnsweredCall":{
"engagement":{
"active":true,
"type":"CALL"
},
"associations":{
"contactIds":[
{
"_prop":"crmContactId",
"_type":"number"
}
]
},
"metadata":{
"toNumber":{
"_prop":"crmAgent",
"_type":"string"
},
"fromNumber":{
"_prop":"crmPhone",
"_type":"string"
},
"status":"COMPLETED",
"durationMilliseconds":{
"_prop":"crmCallDuration",
"_type":"number",
"_format":"milliseconds"
},
"body":"Ligação recebida - inbound call",
"disposition":"f240bbac-87c9-4f6e-bf70-924b57d47db7"
}
}
},
{
"inboundMissedCall":{
"engagement":{
"active":true,
"type":"CALL"
},
"associations":{
"contactIds":[
{
"_prop":"crmContactId",
"_type":"number"
}
]
},
"metadata":{
"toNumber":{
"_prop":"crmAgent",
"_type":"string"
},
"fromNumber":{
"_prop":"crmPhone",
"_type":"string"
},
"status":"COMPLETED",
"body":"Ligação perdida - inbound call",
"disposition":"f240bbac-87c9-4f6e-bf70-924b57d47db7"
}
}
},
{
"outboundAnsweredCall":{
"engagement":{
"active":true,
"type":"CALL"
},
"associations":{
"contactIds":[
{
"_prop":"crmContactId",
"_type":"number"
}
]
},
"metadata":{
"fromNumber":{
"_prop":"crmPhone",
"_type":"string"
},
"toNumber":{
"_prop":"crmAgent",
"_type":"string"
},
"status":"COMPLETED",
"durationMilliseconds":{
"_prop":"crmCallDuration",
"_type":"number",
"_format":"milliseconds"
},
"body":"Ligação atendida - outbound call",
"disposition":"f240bbac-87c9-4f6e-bf70-924b57d47db7"
}
}
},
{
"outboundUnansweredCall":{
"engagement":{
"active":true,
"type":"CALL"
},
"associations":{
"contactIds":[
{
"_prop":"crmContactId",
"_type":"number"
}
]
},
"metadata":{
"fromNumber":{
"_prop":"crmAgent",
"_type":"string"
},
"toNumber":{
"_prop":"crmPhone",
"_type":"string"
},
"status":"COMPLETED",
"body":"Ligação perdida - oubound call",
"disposition":"f240bbac-87c9-4f6e-bf70-924b57d47db7"
}
}
}
]
}
},
{
"createTicketRecord":{
"request":{
"requestContentType":"application/json",
"requestEncoding":"Json",
"requestType":"Post",
"responseType":"Json",
"url":"https://api.hubapi.com/crm/v3/objects/tickets"
},
"body":{
"properties":{
"hs_pipeline":"0",
"hs_pipeline_stage":"1",
"hs_ticket_priority":"HIGH",
"subject":"Teste"
},
"associations":[
{
"to":{
"id":"crmContactId"
},
"types":[
{
"associationCategory":"HUBSPOT_DEFINED",
"associationTypeId":16
}
]
}
]
},
"response":{
"id":"id"
}
}
},
{
"lookupTicket":{
"request":{
"requestContentType":"application/json",
"requestEncoding":"Json",
"requestType":"Get",
"responseType":"Json",
"url":"https://api.hubapi.com/crm/v3/objects/tickets/ticketId"
},
"response":{
"status":"properties.hs_pipeline_stage",
"id":"id"
}
}
}
]
}

View File

@ -4,7 +4,8 @@
"crmClientId":"3MVG9JJwBBbcN47Kv0Z7EuNd19INI1Bhe7uX_Wz6M0VlMyWJD4xPKTtn_b39bGn6LmdSkKJ.aLNGdV1brj16C",
"crmClientSecret":"870E8D51A1CA06896D966A3D92ABD885346DAD4428926E965776C479055969E7",
"crmScopes":"full refresh_token",
"crmPhoneTest":"5514983253326"
"crmPhoneTest":"5514983253326",
"crmAccountId":"001ak00000e27uPAAQ"
},
"crmRest":[
{
@ -176,6 +177,29 @@
"url":"https://nocompany-a9-dev-ed.develop.lightning.force.com/lightning/r/Lead/crmContactId/edit?count=1&backgroundContext=%2Flightning%2Fr%2FLead%2F00Qak0000098YFhEAM%2Fview"
}
}
}
},
{
"createCase": {
"request": {
"requestContentType": "application/json",
"requestEncoding": "Json",
"requestType": "Post",
"responseType": "Json",
"url": "https://nocompany-a9-dev-ed.develop.my.salesforce.com/services/data/v61.0/sobjects/Case"
},
"body": {
"Subject": "Assunto do Caso teste",
"Description": "Descrição detalhada do caso test",
"Status": "Novo",
"Priority": "Alta",
"Departamento__c": "Financeiro"
},
"response": {
"id": "id"
}
}
}
]
}

View File

@ -0,0 +1,205 @@
{
"authentication":{
"type":"oauth2",
"crmClientId":"3MVG9_I_oWkIqLrkzfDaK8hlNFdHqjRWZ62.9A6C8bCCuZsTmzJVokEhC.xFZq8LjH8aacBs8CNb_lQSHcfMw",
"crmClientSecret":"7AEBE0AE0AE6386D34348A7D83D56234CCA1406998DF804F1AD0DE6AB1E55E75",
"crmScopes":"full refresh_token",
"crmPhoneTest":"5514983253326",
"crmOAuthRefreshToken":"5Aep861dGfrsDEfsAziKaAP7kJIZ_jtDR9PknPzivGHe39mGzePJXl6LwYfSJGnAe9F_oZ0AalhUk2tdLidlCg_",
"crmOAuthToken":"00DHa000001uwdZ!AQEAQFf9mSrBHKgnPNWwjQ.P0ybkWVk7BaHJ2Y1UmEvktnQlJ8Mjcxx9NZaSp7nvuXC_J7AVPHa7MRMyX8ZI0aXHNR.kwhl3"
},
"crmRest":[
{
"authorizationEndpoint":{
"request":{
"requestContentType":"empty",
"requestEncoding":"empty",
"requestType":"Get",
"responseType":"empty",
"url":"https://portoitapoa--qaporto.sandbox.my.salesforce.com/services/oauth2/authorize?response_type=code&client_id=crmClientId&code_challenge=bDXEJ0wxr0s369lGxHwewLULiOuyl6Y3W7QZABmn2S4&redirect_uri=crmRedirectURI&scope=crmScopes&code_challenge_method=S256"
}
}
},
{
"tokenEndpoint":{
"request":{
"requestContentType":"none",
"requestEncoding":"Json",
"requestType":"Post",
"responseType":"Json",
"url":"https://portoitapoa--qaporto.sandbox.my.salesforce.com/services/oauth2/token"
}
}
},
{
"createContactRecord":{
"request":{
"requestContentType":"application/json",
"requestEncoding":"Json",
"requestType":"Post",
"responseType":"Json",
"url":"https://portoitapoa--qaporto.sandbox.my.salesforce.com/services/data/v61.0/sobjects/Contact"
},
"body":{
"Phone":"crmPhone",
"LastName":"crmLastName",
"FirstName":"crmFirstName"
},
"response":{
"id":"id"
}
}
},
{
"lookupContactByPhone":{
"request":{
"requestContentType":"application/json",
"requestEncoding":"Json",
"requestType":"Get",
"responseType":"Json",
"url":"https://portoitapoa--qaporto.sandbox.my.salesforce.com/services/data/v61.0/query/?q=SELECT+Id,+Name,+Phone,+AccountId+FROM+Contact+WHERE+Phone='crmPhone'"
},
"response":{
"phone":"records[0].Phone",
"id":"records[0].Id",
"name":"records[0].Name",
"accountId":"records[0].AccountId"
}
}
},
{
"callJournaling":{
"request":{
"requestContentType":"application/json",
"requestEncoding":"Json",
"requestType":"Post",
"responseType":"Json",
"url":"https://portoitapoa--qaporto.sandbox.my.salesforce.com/services/data/v61.0/sobjects/Task"
},
"calls":[
{
"inboundAnsweredCall":{
"Subject":"Call Journal",
"WhoId":"crmContactId",
"Description":"Ligação recebida",
"Status":"Completed",
"Priority":"Normal",
"CallType":"Outbound",
"CallDurationInSeconds":{
"_prop":"crmCallDuration",
"_type":"number",
"_format":"seconds"
},
"ActivityDate":"YYYY-MM-DD",
"TaskSubtype":"Call"
}
},
{
"inboundMissedCall":{
"Subject":"Call Journal",
"WhoId":"crmContactId",
"Description":"Ligação recebida perdida",
"Status":"Completed",
"Priority":"Normal",
"CallType":"Outbound",
"CallDurationInSeconds":{
"_prop":"crmCallDuration",
"_type":"number",
"_format":"seconds"
},
"ActivityDate":"YYYY-MM-DD",
"TaskSubtype":"Call"
}
},
{
"outboundAnsweredCall":{
"Subject":"Call Journal",
"WhoId":"crmContactId",
"Description":"Ligação realizada",
"Status":"Completed",
"Priority":"Normal",
"CallType":"Outbound",
"CallDurationInSeconds":{
"_prop":"crmCallDuration",
"_type":"number",
"_format":"seconds"
},
"ActivityDate":"YYYY-MM-DD",
"TaskSubtype":"Call"
}
},
{
"outboundUnansweredCall":{
"Subject":"Call Journal",
"WhoId":"crmContactId",
"Description":"Ligação realizada nao atendida",
"Status":"Completed",
"Priority":"Normal",
"CallType":"Outbound",
"CallDurationInSeconds":{
"_prop":"crmCallDuration",
"_type":"number",
"_format":"seconds"
},
"ActivityDate":"YYYY-MM-DD",
"TaskSubtype":"Call"
}
}
]
}
},
{
"chatJournaling":{
"request":{
"requestContentType":"application/json",
"requestEncoding":"Json",
"requestType":"Post",
"responseType":"Json",
"url":"https://portoitapoa--qaporto.sandbox.my.salesforce.com/services/data/v61.0/sobjects/Task"
},
"chats":[
{
"chatDone":{
"WhoId":"crmContactId",
"Subject":"WhatsApp Chat",
"Description":"Conversation started via WhatsApp. Conversation link: chatLink",
"ActivityDate":"YYYY-MM-DD",
"Status":"Completed",
"Priority":"Normal"
}
}
]
}
},
{
"redirectLink":{
"request":{
"url":"https://portoitapoa--qaporto.sandbox.my.salesforce.com/lightning/r/Lead/crmContactId/edit?count=1&backgroundContext=%2Flightning%2Fr%2FLead%2F00Qak0000098YFhEAM%2Fview"
}
}
},
{
"createCase":{
"request":{
"requestContentType":"application/json",
"requestEncoding":"Json",
"requestType":"Post",
"responseType":"Json",
"url":"https://portoitapoa--qaporto.sandbox.my.salesforce.com/services/data/v61.0/sobjects/Case"
},
"body":{
"Subject":"Caso criado na URA",
"Status":"Aberto",
"ContactId":"0038800000LVXFfAAP",
"AccountId":"0018800000fuRajAAE",
"Origin":"Telefone",
"Priority":"Médio",
"Reason":"Informação"
},
"response":{
"id":"id"
}
}
}
]
}

View File

@ -0,0 +1,206 @@
{
"authentication":{
"type":"oauth2",
"crmClientId":"3MVG9_I_oWkIqLrkzfDaK8hlNFdHqjRWZ62.9A6C8bCCuZsTmzJVokEhC.xFZq8LjH8aacBs8CNb_lQSHcfMw",
"crmClientSecret":"7AEBE0AE0AE6386D34348A7D83D56234CCA1406998DF804F1AD0DE6AB1E55E75",
"crmScopes":"full refresh_token",
"crmPhoneTest":"551498325332",
"crmOAuthRefreshToken":"5Aep8618yVsldz6rZP_nN5Ob0S3VSbO5DsHksJseMuG7dYHJQuUnAR.0muSjn_VlVM9YeARnacAGg5s0QsZWxKA",
"crmOAuthToken":"00D4P000000iyUc!AQEAQPdYbZ9PsW7dEAFfFK2jzVzntHAkJjF5xDPK1bdZPsbFLHH.5Aw1th_DFJrS6XcJeGfRjQmhSBS36i6dIJuFDKjbAl67"
},
"crmRest":[
{
"authorizationEndpoint":{
"request":{
"requestContentType":"empty",
"requestEncoding":"empty",
"requestType":"Get",
"responseType":"empty",
"url":"https://restoque.my.salesforce.com/services/oauth2/authorize?response_type=code&client_id=crmClientId&code_challenge=bDXEJ0wxr0s369lGxHwewLULiOuyl6Y3W7QZABmn2S4&redirect_uri=crmRedirectURI&scope=crmScopes&code_challenge_method=S256"
}
}
},
{
"tokenEndpoint":{
"request":{
"requestContentType":"none",
"requestEncoding":"Json",
"requestType":"Post",
"responseType":"Json",
"url":"https://restoque.my.salesforce.com/services/oauth2/token"
}
}
},
{
"createContactRecord":{
"request":{
"requestContentType":"application/json",
"requestEncoding":"Json",
"requestType":"Post",
"responseType":"Json",
"url":"https://restoque.my.salesforce.com/services/data/v61.0/sobjects/Contact"
},
"body":{
"Phone":"crmPhone",
"LastName":"crmLastName",
"FirstName":"crmFirstName"
},
"response":{
"id":"id"
}
}
},
{
"lookupContactByPhone":{
"request":{
"requestContentType":"application/json",
"requestEncoding":"Json",
"requestType":"Get",
"responseType":"Json",
"url":"https://restoque.my.salesforce.com/services/data/v61.0/query/?q=SELECT+Id,+Name,+PersonMobilePhone+FROM+Account+WHERE+PersonMobilePhone='crmPhone'"
},
"response":{
"phone":"records[0].PersonMobilePhone",
"id":"records[0].Id",
"name":"records[0].Name",
"accountId":"records[0].Id"
}
}
},
{
"callJournaling":{
"request":{
"requestContentType":"application/json",
"requestEncoding":"Json",
"requestType":"Post",
"responseType":"Json",
"url":"https://restoque.my.salesforce.com/services/data/v61.0/sobjects/Task"
},
"calls":[
{
"inboundAnsweredCall":{
"Subject":"Call Journal",
"WhoId":"crmContactId",
"Description":"Ligação recebida",
"Status":"Completed",
"Priority":"Normal",
"CallType":"Outbound",
"CallDurationInSeconds":{
"_prop":"crmCallDuration",
"_type":"number",
"_format":"seconds"
},
"ActivityDate":"YYYY-MM-DD",
"TaskSubtype":"Call"
}
},
{
"inboundMissedCall":{
"Subject":"Call Journal",
"WhoId":"crmContactId",
"Description":"Ligação recebida perdida",
"Status":"Completed",
"Priority":"Normal",
"CallType":"Outbound",
"CallDurationInSeconds":{
"_prop":"crmCallDuration",
"_type":"number",
"_format":"seconds"
},
"ActivityDate":"YYYY-MM-DD",
"TaskSubtype":"Call"
}
},
{
"outboundAnsweredCall":{
"Subject":"Call Journal",
"WhoId":"crmContactId",
"Description":"Ligação realizada",
"Status":"Completed",
"Priority":"Normal",
"CallType":"Outbound",
"CallDurationInSeconds":{
"_prop":"crmCallDuration",
"_type":"number",
"_format":"seconds"
},
"ActivityDate":"YYYY-MM-DD",
"TaskSubtype":"Call"
}
},
{
"outboundUnansweredCall":{
"Subject":"Call Journal",
"WhoId":"crmContactId",
"Description":"Ligação realizada nao atendida",
"Status":"Completed",
"Priority":"Normal",
"CallType":"Outbound",
"CallDurationInSeconds":{
"_prop":"crmCallDuration",
"_type":"number",
"_format":"seconds"
},
"ActivityDate":"YYYY-MM-DD",
"TaskSubtype":"Call"
}
}
]
}
},
{
"chatJournaling":{
"request":{
"requestContentType":"application/json",
"requestEncoding":"Json",
"requestType":"Post",
"responseType":"Json",
"url":"https://restoque.my.salesforce.com/services/data/v61.0/sobjects/Task"
},
"chats":[
{
"chatDone":{
"WhoId":"crmContactId",
"Subject":"WhatsApp Chat",
"Description":"Conversation started via WhatsApp. Conversation link: chatLink",
"ActivityDate":"YYYY-MM-DD",
"Status":"Completed",
"Priority":"Normal"
}
}
]
}
},
{
"redirectLink":{
"request":{
"url":"https://restoque.my.salesforce.com/lightning/r/Lead/crmContactId/edit?count=1&backgroundContext=%2Flightning%2Fr%2FLead%2F00Qak0000098YFhEAM%2Fview"
}
}
},
{
"createCase":{
"request":{
"requestContentType":"application/json",
"requestEncoding":"Json",
"requestType":"Post",
"responseType":"Json",
"url":"https://restoque.my.salesforce.com/services/data/v61.0/sobjects/Case"
},
"body":{
"Subject":"Assunto do Caso teste",
"Origin":"Telefone",
"Description":"Descrição detalhada do caso test",
"Status":"Novo",
"Priority":"Alta",
"Categoria__c":"Telefonia",
"ContactId":"",
"RecordTypeId":"0124P00000070MzQAI"
},
"response":{
"id":"id"
}
}
}
]
}

View File

@ -116,7 +116,8 @@ const AuthenticationSchema = new Schema({
crmScopes: String,
crmOAuthRefreshToken: String,
crmOAuthToken: String,
crmPhoneTest: String
crmPhoneTest: String,
crmAccountId: String
})

View File

@ -52,7 +52,7 @@ async function createTicket(companyId, rest, authentication, crmPhone, crmFirstN
console.log('========> body3: ', JSON.stringify(body, null, 6))
const { type, userName, passWord, token, crmClientId } = authentication
const { type, userName, passWord, token, crmClientId, crmAccountId } = authentication
//url, crmPhone, requestType, requestContentType, type, userName, passWord, token, crmClientId, data = '', ticketId = '', companyId
const config = await requestConfigHeader(url, crmPhone, requestType, requestContentType, type, userName, passWord, token, crmClientId, body, '', companyId)
@ -117,7 +117,8 @@ async function createTicket(companyId, rest, authentication, crmPhone, crmFirstN
await CRM_Ticket.create({ companyId, contact, ticketId: auxTicketId, crm })
ticketUrl = `https://app.hubspot.com/contacts/23636141/ticket/${auxTicketId}`
// ticketUrl = `https://app.hubspot.com/contacts/23636141/ticket/${auxTicketId}`
ticketUrl = `https://app.hubspot.com/contacts/${crmAccountId}/ticket/${auxTicketId}`
sendEventTicketCreatedToSocket({ companyId, extension: crmAgent, ticketUrl: ticketUrl })

View File

@ -17,7 +17,7 @@ async function lookupContactByPhone(rest, authentication, crmPhone, companyId, t
let { requestContentType, requestEncoding, requestType, responseType, url } = request
const { type, userName, passWord, token, crmClientId } = authentication
const { type, userName, passWord, token, crmClientId, crmAccountId} = authentication
if (cacheContact) {
const crmInfo = await CRM_Contact.findOne({ companyId, crmBaseURL: new URL(url).hostname, phone: crmPhone })
@ -153,6 +153,13 @@ async function lookupContactByPhone(rest, authentication, crmPhone, companyId, t
}
}
// Tenta pegar o accountId no body da resposta se não conseguir, pega do template se a propriedade crmAccountId existir no template
// Foi criado dessa forma para evitar problemas com integrações que já estão em funcionamento
if(!auxAccountId && crmAccountId){
console.log('---------> auxAccountId definido a partir do crmAccountId do template: ',crmAccountId)
auxAccountId = crmAccountId
}
console.log('---------> auxPhone: ', auxPhone, ' | auxContactId: ', auxContactId, ' | auxAccountId: ', auxAccountId)
if (auxPhone) {

View File

@ -26,7 +26,7 @@ async function ticketCRM(companyId, crmPhone, crmAgent = "0000", crmFirstName =
for (const crmConfig of crmFiles) {
const { crmRest: rest, authentication } = crmConfig.crm
const { crmRest: rest, authentication } = crmConfig.crm
// Send the ticket url link to hitphone to open on another browser tab
let obj = findProperty(rest, 'lookupTicket')
@ -36,6 +36,10 @@ async function ticketCRM(companyId, crmPhone, crmAgent = "0000", crmFirstName =
if (obj) {
const { crmAccountId } = authentication
console.log("------------> ticketCRM crmAccountId: ",crmAccountId)
let { url } = obj.request
let contact = await _lookupContact(rest, authentication, crmPhone, companyId, crmFirstName, url)
@ -91,7 +95,7 @@ async function ticketCRM(companyId, crmPhone, crmAgent = "0000", crmFirstName =
isCreated = false
crmTicketLinks.push({
ticketId: `https://app.hubspot.com/contacts/23636141/ticket/${ticket_id}`,
ticketId: `https://app.hubspot.com/contacts/${crmAccountId}/ticket/${ticket_id}`,
created: isCreated,
})
@ -130,7 +134,7 @@ async function ticketCRM(companyId, crmPhone, crmAgent = "0000", crmFirstName =
isCreated = false
crmTicketLinks.push({
ticketId: `https://app.hubspot.com/contacts/23636141/ticket/${ticket_id}`,
ticketId: `https://app.hubspot.com/contacts/${crmAccountId}/ticket/${ticket_id}`,
created: isCreated,
})
@ -147,7 +151,7 @@ async function ticketCRM(companyId, crmPhone, crmAgent = "0000", crmFirstName =
}
crmTicketLinks.push({
ticketId: `https://app.hubspot.com/contacts/23636141/ticket/${ticket_id}`,
ticketId: `https://app.hubspot.com/contacts/${crmAccountId}/ticket/${ticket_id}`,
created: isCreated,
})
@ -193,15 +197,15 @@ async function sincTicket(authentication, contact, companyId, crm, obj_contact,
}
async function findTicketOpenHubspot(authentication, contact) {
const ticket = await findTicketOpenHubspotByContact(authentication, contact)
const ticket = await findTicketOpenHubspotByContact(authentication, contact)
console.log('=========> OPEN TICKET 2: ', JSON.stringify(ticket, null, 6))
if (ticket && Object.keys(ticket).length != 0) {
console.log('**** TICKET ESTA ABERTO 2 ****')
return { ticketId: ticket.id, auxTicketStatus: 1 }
}
console.log('**** TICKET ESTA ABERTO 2 ****')
return { ticketId: ticket.id, auxTicketStatus: 1 }
}
}
async function _lookupContact(rest, authentication, crmPhone, companyId, crmFirstName, url) {