feat: adjustment to create contact via omnihit for SAP crm

master
adriano 2025-10-13 16:09:22 -03:00
parent ebe4f901f7
commit 9db7604b93
5 changed files with 29 additions and 12 deletions

View File

@ -19,11 +19,12 @@
"body":{ "body":{
"LastName":"crmLastName", "LastName":"crmLastName",
"FirstName":"crmFirstName", "FirstName":"crmFirstName",
"Mobile":"crmPhone", "Mobile":"+crmPhone",
"AccountID":"1000320" "AccountID":"1000320"
}, },
"response":{ "response":{
"id":"d.results.ContactID" "id":"d.results.ContactID",
"objectId":"d.results.ObjectID"
} }
} }
}, },

View File

@ -191,8 +191,8 @@ const callJournaling = async (req, res) => {
// return res.status(StatusCodes.OK).send() // return res.status(StatusCodes.OK).send()
// Refactor this in the future. Integração Gradezco colombia, o crm sap precisa criar o contato com o + no inicio seguido do codigo do pais // Refactor this in the future. Integração Gradezco colombia, o crm sap precisa criar o contato com o + no inicio seguido do codigo do pais
if(companyId == "4953"){ // companyId de test para colombia if(companyId == "4953"){ // companyId da gradezco colombia
crmPhone = '+57' + crmPhone crmPhone = '57' + crmPhone
} }
else{ else{
crmPhone = '55' + crmPhone crmPhone = '55' + crmPhone

View File

@ -26,8 +26,17 @@ async function createContact(companyId, rest, authentication, crmPhone = '', crm
} }
for (const prop in body) { for (const prop in body) {
// Para o crm SAP que precisa do +57 no inicio do contato para ser criado corretamente
if(body[prop].includes("+crmPhone")){
body[prop] = `+${crmPhone}`
continue
}
if (mapping.hasOwnProperty(body[prop])) { if (mapping.hasOwnProperty(body[prop])) {
const variable = mapping[body[prop]] const variable = mapping[body[prop]]
if (variable) { if (variable) {
body[prop] = variable body[prop] = variable
} else { } else {
@ -91,6 +100,7 @@ async function createContact(companyId, rest, authentication, crmPhone = '', crm
data = flatten(data) data = flatten(data)
let auxContactId let auxContactId
let auxContactId2
for (const prop in data) { for (const prop in data) {
@ -98,10 +108,14 @@ async function createContact(companyId, rest, authentication, crmPhone = '', crm
if (_prop == response?.id?.trim()) { if (_prop == response?.id?.trim()) {
auxContactId = data[prop] auxContactId = data[prop]
break }
if (_prop == response?.objectId?.trim()) {
auxContactId2 = data[prop]
} }
} }
console.log('---------> createContact crmPhone: ', crmPhone, ' | auxContactId: ', auxContactId, ' | auxContactId2: ', auxContactId2)
if (auxContactId && !test?.testing && crmEmail=='') { if (auxContactId && !test?.testing && crmEmail=='') {
@ -110,7 +124,7 @@ async function createContact(companyId, rest, authentication, crmPhone = '', crm
await CRM_Contact.create({ companyId, crm, crmBaseURL: new URL(url).hostname, contactId: auxContactId, phone: crmPhone }) await CRM_Contact.create({ companyId, crm, crmBaseURL: new URL(url).hostname, contactId: auxContactId, phone: crmPhone })
} }
return { exist: true, contactId: auxContactId, phone: crmPhone } return { exist: true, contactId: auxContactId, phone: crmPhone, contactId2: auxContactId2}
} }

View File

@ -11,13 +11,15 @@ async function journalingRequest(request, body, crmCallDuration, contact, crmAge
let { requestContentType, requestEncoding, requestType, responseType, url } = request let { requestContentType, requestEncoding, requestType, responseType, url } = request
console.log('----------> crmCallDuration: ', crmCallDuration) console.log('----------> crmCallDuration: ', crmCallDuration)
console.log('----------> url 1: ', url) console.log('----------> journalingRequest url 1: ', url)
// Second contactId for some cases like SAP crm // Second contactId for some cases like SAP crm that use ObjectID to create note
if(url.includes("contactObjectId") && contact?.contactId2){ if(url.includes("contactObjectId") && contact?.contactId2){
url = url.replace("contactObjectId", contact.contactId2) url = url.replace("contactObjectId", contact.contactId2)
} }
console.log('----------> journalingRequest url 2: ', url)
body = flatten(body) body = flatten(body)
let ignore = [] let ignore = []

View File

@ -144,7 +144,7 @@ async function _lookupContact(rest, authentication, crmPhone, crmEmail, companyI
// Se o contato for criado, retorna suas informações // Se o contato for criado, retorna suas informações
if (contact?.contactId) { if (contact?.contactId) {
console.log(`Novo contato criado com ID: ${contact.contactId}`); console.log(`Novo contato criado com ID: ${contact.contactId}`);
return { created: true, contactId: contact.contactId }; return { created: true, contactId: contact.contactId, contactId2: contact?.contactId2};
} }
// Caso não tenha nem telefone nem e-mail, retorna um erro ou um valor nulo // Caso não tenha nem telefone nem e-mail, retorna um erro ou um valor nulo