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":{
"LastName":"crmLastName",
"FirstName":"crmFirstName",
"Mobile":"crmPhone",
"Mobile":"+crmPhone",
"AccountID":"1000320"
},
"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()
// 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
crmPhone = '+57' + crmPhone
if(companyId == "4953"){ // companyId da gradezco colombia
crmPhone = '57' + crmPhone
}
else{
crmPhone = '55' + crmPhone

View File

@ -25,9 +25,18 @@ async function createContact(companyId, rest, authentication, crmPhone = '', crm
crmEmail
}
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])) {
const variable = mapping[body[prop]]
if (variable) {
body[prop] = variable
} else {
@ -40,7 +49,7 @@ async function createContact(companyId, rest, authentication, crmPhone = '', crm
}
}
body = unflatten(body)
body = unflatten(body)
const { type, userName, passWord, token, crmClientId } = authentication
@ -91,17 +100,22 @@ async function createContact(companyId, rest, authentication, crmPhone = '', crm
data = flatten(data)
let auxContactId
let auxContactId2
for (const prop in data) {
const _prop = prop.replace(/^\d+\./, '').replace(/(?:^|\.)\d+\b/g, '')
if (_prop == response?.id?.trim()) {
auxContactId = data[prop]
break
auxContactId = data[prop]
}
if (_prop == response?.objectId?.trim()) {
auxContactId2 = data[prop]
}
}
console.log('---------> createContact crmPhone: ', crmPhone, ' | auxContactId: ', auxContactId, ' | auxContactId2: ', auxContactId2)
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 })
}
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
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){
url = url.replace("contactObjectId", contact.contactId2)
}
console.log('----------> journalingRequest url 2: ', url)
body = flatten(body)
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
if (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