Compare commits
4 Commits
f05bfa4047
...
526c016b99
Author | SHA1 | Date |
---|---|---|
|
526c016b99 | |
|
f2814269ac | |
|
61783eecf6 | |
|
844593749b |
|
@ -0,0 +1,154 @@
|
||||||
|
{
|
||||||
|
"authentication": {
|
||||||
|
"type": "oauth2",
|
||||||
|
"crmClientId": "3MVG97ZwUE6kNctcTD24tyRZJXLWfClkMmmH5wvnTw8b6EW92uMPeaYOpyyWyzjx_klDcVt7F2nF2jbluycT4",
|
||||||
|
"crmClientSecret": "FBA2860ECEAC86A3CED77841A0BD6B26AFD3E7F202C0241D534716B90E8C12AD",
|
||||||
|
"crmScopes": "full refresh_token",
|
||||||
|
"crmPhoneTest": "5511988334455"
|
||||||
|
},
|
||||||
|
"crmRest": [
|
||||||
|
{
|
||||||
|
"authorizationEndpoint": {
|
||||||
|
"request": {
|
||||||
|
"requestContentType": "empty",
|
||||||
|
"requestEncoding": "empty",
|
||||||
|
"requestType": "Get",
|
||||||
|
"responseType": "empty",
|
||||||
|
"url": "https://berlitz--blzlatam.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"
|
||||||
|
},
|
||||||
|
"body": {},
|
||||||
|
"response": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tokenEndpoint": {
|
||||||
|
"request": {
|
||||||
|
"requestContentType": "none",
|
||||||
|
"requestEncoding": "Json",
|
||||||
|
"requestType": "Post",
|
||||||
|
"responseType": "Json",
|
||||||
|
"url": "https://berlitz--blzlatam.sandbox.my.salesforce.com/services/oauth2/token"
|
||||||
|
},
|
||||||
|
"body": {},
|
||||||
|
"response": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"createContactRecord": {
|
||||||
|
"request": {
|
||||||
|
"requestContentType": "application/json",
|
||||||
|
"requestEncoding": "Json",
|
||||||
|
"requestType": "Post",
|
||||||
|
"responseType": "Json",
|
||||||
|
"url": "https://berlitz--blzlatam.sandbox.my.salesforce.com/services/data/v61.0/sobjects/Contact"
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"Phone": "crmPhone",
|
||||||
|
"LastName": "crmLastName",
|
||||||
|
"FirstName": "crmFirstName",
|
||||||
|
"Time_Zone__c": "America/Sao_Paulo"
|
||||||
|
},
|
||||||
|
"response": {
|
||||||
|
"id": "id"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"lookupContactByPhone": {
|
||||||
|
"request": {
|
||||||
|
"requestContentType": "application/json",
|
||||||
|
"requestEncoding": "Json",
|
||||||
|
"requestType": "Get",
|
||||||
|
"responseType": "Json",
|
||||||
|
"url": "https://berlitz--blzlatam.sandbox.my.salesforce.com/services/data/v61.0/query/?q=SELECT+Id,+Phone+FROM+Contact+WHERE+Phone='crmPhone'"
|
||||||
|
},
|
||||||
|
"response": {
|
||||||
|
"phone": "records[0].Phone",
|
||||||
|
"id": "records[0].Id"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"callJournaling": {
|
||||||
|
"request": {
|
||||||
|
"requestContentType": "application/json",
|
||||||
|
"requestEncoding": "Json",
|
||||||
|
"requestType": "Post",
|
||||||
|
"responseType": "Json",
|
||||||
|
"url": "https://berlitz--blzlatam.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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"response": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,201 @@
|
||||||
|
{
|
||||||
|
"authentication": {
|
||||||
|
"type": "oauth2",
|
||||||
|
"crmClientId": "3MVG97ZwUE6kNctcTD24tyRZJXLWfClkMmmH5wvnTw8b6EW92uMPeaYOpyyWyzjx_klDcVt7F2nF2jbluycT4",
|
||||||
|
"crmClientSecret": "FBA2860ECEAC86A3CED77841A0BD6B26AFD3E7F202C0241D534716B90E8C12AD",
|
||||||
|
"crmScopes": "full refresh_token",
|
||||||
|
"crmPhoneTest": "5517988335455"
|
||||||
|
},
|
||||||
|
"crmRest": [
|
||||||
|
{
|
||||||
|
"authorizationEndpoint": {
|
||||||
|
"request": {
|
||||||
|
"requestContentType": "empty",
|
||||||
|
"requestEncoding": "empty",
|
||||||
|
"requestType": "Get",
|
||||||
|
"responseType": "empty",
|
||||||
|
"url": "https://berlitz--blzlatam.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"
|
||||||
|
},
|
||||||
|
"body": {},
|
||||||
|
"response": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tokenEndpoint": {
|
||||||
|
"request": {
|
||||||
|
"requestContentType": "none",
|
||||||
|
"requestEncoding": "Json",
|
||||||
|
"requestType": "Post",
|
||||||
|
"responseType": "Json",
|
||||||
|
"url": "https://berlitz--blzlatam.sandbox.my.salesforce.com/services/oauth2/token"
|
||||||
|
},
|
||||||
|
"body": {},
|
||||||
|
"response": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"createContactRecord": {
|
||||||
|
"request": {
|
||||||
|
"requestContentType": "application/json",
|
||||||
|
"requestEncoding": "Json",
|
||||||
|
"requestType": "Post",
|
||||||
|
"responseType": "Json",
|
||||||
|
"url": "https://berlitz--blzlatam.sandbox.my.salesforce.com/services/data/v61.0/sobjects/Lead"
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"Phone": "crmPhone",
|
||||||
|
"LastName": "crmLastName",
|
||||||
|
"FirstName": "crmFirstName",
|
||||||
|
"LeadSource": "WhatsApp",
|
||||||
|
"Country_Segmentation__c": "Brazil",
|
||||||
|
"CurrencyIsoCode": "BRL",
|
||||||
|
"RecordTypeId": "0120b000000OhSqAAK"
|
||||||
|
},
|
||||||
|
"response": {
|
||||||
|
"id": "id"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"lookupContactByPhone": {
|
||||||
|
"request": {
|
||||||
|
"requestContentType": "application/json",
|
||||||
|
"requestEncoding": "Json",
|
||||||
|
"requestType": "Get",
|
||||||
|
"responseType": "Json",
|
||||||
|
"url": "https://berlitz--blzlatam.sandbox.my.salesforce.com/services/data/v61.0/query/?q=SELECT+Id,Phone+FROM+Lead+WHERE+Phone='crmPhone'"
|
||||||
|
},
|
||||||
|
"response": {
|
||||||
|
"phone": "records[0].Phone",
|
||||||
|
"id": "records[0].Id"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"callJournaling": {
|
||||||
|
"request": {
|
||||||
|
"requestContentType": "application/json",
|
||||||
|
"requestEncoding": "Json",
|
||||||
|
"requestType": "Post",
|
||||||
|
"responseType": "Json",
|
||||||
|
"url": "https://berlitz--blzlatam.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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"response": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"chatJournaling": {
|
||||||
|
"request": {
|
||||||
|
"requestContentType": "application/json",
|
||||||
|
"requestEncoding": "Json",
|
||||||
|
"requestType": "Post",
|
||||||
|
"responseType": "Json",
|
||||||
|
"url": "https://berlitz--blzlatam.sandbox.my.salesforce.com/services/data/v61.0/sobjects/Task"
|
||||||
|
},
|
||||||
|
"chats": [
|
||||||
|
{
|
||||||
|
"chatDone": {
|
||||||
|
"WhoId": "crmContactId",
|
||||||
|
"Subject": "Other",
|
||||||
|
"Description": "Conversation started via WhatsApp. Conversation link: chatLink",
|
||||||
|
"ActivityDate": "YYYY-MM-DD",
|
||||||
|
"Status": "Completed",
|
||||||
|
"Priority": "Normal"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"createCase": {
|
||||||
|
"request": {
|
||||||
|
"requestContentType": "application/json",
|
||||||
|
"requestEncoding": "Json",
|
||||||
|
"requestType": "Post",
|
||||||
|
"responseType": "Json",
|
||||||
|
"url": "https://berlitz--blzlatam.sandbox.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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -12,7 +12,8 @@ const { createCRMContact,
|
||||||
journalingRequest,
|
journalingRequest,
|
||||||
createContact,
|
createContact,
|
||||||
lookupContactByPhone,
|
lookupContactByPhone,
|
||||||
templateValidator } = require('../utils')
|
templateValidator,
|
||||||
|
loadCRM } = require('../utils')
|
||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
const { URL } = require('url')
|
const { URL } = require('url')
|
||||||
const { oauth2 } = require('../utils')
|
const { oauth2 } = require('../utils')
|
||||||
|
@ -35,16 +36,53 @@ const getSalesforceUser = require('../utils/getSalesforceUser')
|
||||||
|
|
||||||
const contactCreate = async (req, res) => {
|
const contactCreate = async (req, res) => {
|
||||||
|
|
||||||
const { companyId, crmFirstName, crmLastName, crmPhone, crmEmail } = req.body
|
const { companyId, crmFirstName, crmLastName, crmPhone, crmEmail, dynamicBodyRequest } = req.body
|
||||||
|
|
||||||
mustContainProperties(req, ['companyId', 'crmPhone',])
|
mustContainProperties(req, ['companyId', 'crmPhone',])
|
||||||
|
|
||||||
await createCRMContact(companyId, crmFirstName, crmPhone, crmEmail, crmLastName)
|
await createCRMContact(companyId, crmFirstName, crmPhone, crmEmail, crmLastName, dynamicBodyRequest)
|
||||||
|
|
||||||
res.status(StatusCodes.OK).send()
|
res.status(StatusCodes.OK).send()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const checkContact = async (req, res) => {
|
||||||
|
|
||||||
|
const { companyId, crmPhone } = req.body
|
||||||
|
|
||||||
|
mustContainProperties(req, ['companyId', 'crmPhone',])
|
||||||
|
|
||||||
|
const crmFiles = await loadCRM(companyId)
|
||||||
|
|
||||||
|
if (crmFiles.length > 0) {
|
||||||
|
const { crmRest: rest, authentication } = crmFiles[0].crm
|
||||||
|
|
||||||
|
const contact = await lookupContactByPhone(rest, authentication, crmPhone, companyId)
|
||||||
|
|
||||||
|
if (contact && contact.exist) {
|
||||||
|
return res.status(StatusCodes.OK).json({ exist: contact.exist })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
res.status(StatusCodes.OK).json({ exist: false })
|
||||||
|
}
|
||||||
|
|
||||||
|
const contactActivity = async (req, res) => {
|
||||||
|
const { companyId, crmPhone, ticketId } = req.body
|
||||||
|
|
||||||
|
mustContainProperties(req, ['companyId', 'crmPhone', 'ticketId'])
|
||||||
|
|
||||||
|
await whatsappJournalingCRM(
|
||||||
|
companyId,
|
||||||
|
crmPhone,
|
||||||
|
'0000',
|
||||||
|
crmFirstName = "unnamed",
|
||||||
|
ticketId
|
||||||
|
)
|
||||||
|
|
||||||
|
res.status(StatusCodes.OK).send()
|
||||||
|
}
|
||||||
|
|
||||||
const deleteCrm = async (req, res) => {
|
const deleteCrm = async (req, res) => {
|
||||||
|
|
||||||
let { companyId, crmBaseURL } = req.body
|
let { companyId, crmBaseURL } = req.body
|
||||||
|
@ -436,7 +474,7 @@ const webhook = async (req, res) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
let crmPhone = phone_number.replace('+', '')
|
let crmPhone = phone_number.replace('+', '')
|
||||||
|
|
||||||
const company = await Company.findOne({
|
const company = await Company.findOne({
|
||||||
integrations: {
|
integrations: {
|
||||||
$elemMatch: {
|
$elemMatch: {
|
||||||
|
@ -448,7 +486,7 @@ const webhook = async (req, res) => {
|
||||||
|
|
||||||
if (!company) {
|
if (!company) {
|
||||||
return res.status(StatusCodes.NOT_FOUND).send({ msg: "companyId not found!" })
|
return res.status(StatusCodes.NOT_FOUND).send({ msg: "companyId not found!" })
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('=======> name: ', name)
|
console.log('=======> name: ', name)
|
||||||
console.log('=======> crmPhone: ', crmPhone)
|
console.log('=======> crmPhone: ', crmPhone)
|
||||||
|
@ -523,7 +561,7 @@ const webhook_crm = async (req, res) => {
|
||||||
|
|
||||||
if (!contact) return res.send()
|
if (!contact) return res.send()
|
||||||
|
|
||||||
const { phone } = contact
|
const { phone } = contact
|
||||||
|
|
||||||
const config = await getIntegrationsConfig(companyId, 'omnihit')
|
const config = await getIntegrationsConfig(companyId, 'omnihit')
|
||||||
|
|
||||||
|
@ -553,7 +591,7 @@ const webhook_crm = async (req, res) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.set('Content-Type', 'text/xml').status(StatusCodes.OK).send(responseXml)
|
return res.set('Content-Type', 'text/xml').status(StatusCodes.OK).send(responseXml)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
contactCreate,
|
contactCreate,
|
||||||
|
@ -569,7 +607,9 @@ module.exports = {
|
||||||
webhook_crm,
|
webhook_crm,
|
||||||
sfCreateCase,
|
sfCreateCase,
|
||||||
sfUpdateCase,
|
sfUpdateCase,
|
||||||
createTicket
|
createTicket,
|
||||||
|
checkContact,
|
||||||
|
contactActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
const { authorization, } = require('../middleware/authentication')
|
const { authorization, } = require('../middleware/authentication')
|
||||||
const { contactCreate, sfCreateCase, sfUpdateCase, createTicket, testTemplate, webhook_crm, uploadCrmConfig, callJournaling, oauthCallBack, install, deleteCrm, deleteCompany, getCrms, webhook } = require('../controllers/crmController')
|
const { contactCreate, contactActivity, checkContact, sfCreateCase, sfUpdateCase, createTicket, testTemplate, webhook_crm, uploadCrmConfig, callJournaling, oauthCallBack, install, deleteCrm, deleteCompany, getCrms, webhook } = require('../controllers/crmController')
|
||||||
const { fileUpload } = require("../utils")
|
const { fileUpload } = require("../utils")
|
||||||
|
|
||||||
router.route('/create-contact').post(authorization, contactCreate)
|
router.route('/create-contact').post(authorization, contactCreate)
|
||||||
|
|
||||||
|
router.route('/find-contact').post(authorization, checkContact)
|
||||||
|
router.route('/contact-activity').post(authorization, contactActivity)
|
||||||
|
|
||||||
router.route('/create-ticket').post(authorization, createTicket)
|
router.route('/create-ticket').post(authorization, createTicket)
|
||||||
router.route('/call-journaling').post(authorization, callJournaling)
|
router.route('/call-journaling').post(authorization, callJournaling)
|
||||||
router.route('/upload').post(fileUpload.single('crm'), authorization, uploadCrmConfig)
|
router.route('/upload').post(fileUpload.single('crm'), authorization, uploadCrmConfig)
|
||||||
|
|
|
@ -2,8 +2,8 @@ const lookupContactByPhone = require('./lookupCRMContactByPhone')
|
||||||
const createContact = require('./createContact')
|
const createContact = require('./createContact')
|
||||||
const loadCRM = require('./loadCRM')
|
const loadCRM = require('./loadCRM')
|
||||||
|
|
||||||
async function createCRMContact(companyId, crmFirstName, crmPhone, crmEmail = '', crmLastName = '',) {
|
async function createCRMContact(companyId, crmFirstName, crmPhone, crmEmail = '', crmLastName = '', dynamicBodyRequest = {}) {
|
||||||
|
|
||||||
const crmFiles = await loadCRM(companyId)
|
const crmFiles = await loadCRM(companyId)
|
||||||
|
|
||||||
for (const crmConfig of crmFiles) {
|
for (const crmConfig of crmFiles) {
|
||||||
|
@ -11,11 +11,11 @@ async function createCRMContact(companyId, crmFirstName, crmPhone, crmEmail = ''
|
||||||
const { crmRest: rest, authentication } = crmConfig.crm
|
const { crmRest: rest, authentication } = crmConfig.crm
|
||||||
|
|
||||||
const contact = await lookupContactByPhone(rest, authentication, crmPhone, companyId)
|
const contact = await lookupContactByPhone(rest, authentication, crmPhone, companyId)
|
||||||
|
|
||||||
if (contact.exist) continue
|
|
||||||
|
|
||||||
await createContact(companyId, rest, authentication, crmPhone, crmFirstName, crmLastName, crmEmail,)
|
if (contact.exist) continue
|
||||||
|
|
||||||
|
await createContact(companyId, rest, authentication, crmPhone, crmFirstName, crmLastName, crmEmail, {}, dynamicBodyRequest)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ const CRM = require('../models/CRM')
|
||||||
const requestConfigHeader = require('./requestConfigHeader')
|
const requestConfigHeader = require('./requestConfigHeader')
|
||||||
const sendMessageSocket = require('./sendMessageSocket')
|
const sendMessageSocket = require('./sendMessageSocket')
|
||||||
|
|
||||||
async function createContact(companyId, rest, authentication, crmPhone, crmFirstName = 'Username', crmLastName = 'Last name', crmEmail = '', test = {}) {
|
async function createContact(companyId, rest, authentication, crmPhone, crmFirstName = 'Username', crmLastName = 'Last name', crmEmail = '', test = {}, dynamicBodyRequest = {}) {
|
||||||
let { request, body, response } = findProperty(rest, 'createContactRecord')
|
let { request, body, response } = findProperty(rest, 'createContactRecord')
|
||||||
|
|
||||||
const { requestContentType, requestEncoding, requestType, responseType, url } = request
|
const { requestContentType, requestEncoding, requestType, responseType, url } = request
|
||||||
|
@ -42,7 +42,7 @@ async function createContact(companyId, rest, authentication, crmPhone, crmFirst
|
||||||
const { type, userName, passWord, token, crmClientId } = authentication
|
const { type, userName, passWord, token, crmClientId } = authentication
|
||||||
|
|
||||||
//url, crmPhone, requestType, requestContentType, type, userName, passWord, token, crmClientId, data = '', ticketId = '', companyId
|
//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)
|
let config = await requestConfigHeader(url, crmPhone, requestType, requestContentType, type, userName, passWord, token, crmClientId, body, '', companyId)
|
||||||
|
|
||||||
if (test?.testing) {
|
if (test?.testing) {
|
||||||
msg = `Tentanto criar contato de numero ${crmPhone} no crm`
|
msg = `Tentanto criar contato de numero ${crmPhone} no crm`
|
||||||
|
@ -51,8 +51,15 @@ async function createContact(companyId, rest, authentication, crmPhone, crmFirst
|
||||||
|
|
||||||
console.log('#####################')
|
console.log('#####################')
|
||||||
console.log('CREATE CONTACT PAYLOAD: ', JSON.stringify(config, null, 6))
|
console.log('CREATE CONTACT PAYLOAD: ', JSON.stringify(config, null, 6))
|
||||||
console.log('#####################')
|
console.log('#####################')
|
||||||
|
|
||||||
|
if (dynamicBodyRequest && Object.keys(dynamicBodyRequest) !== 0) {
|
||||||
|
config.data = { ...config.data, ...dynamicBodyRequest }
|
||||||
|
console.log('#####################')
|
||||||
|
console.log('CREATE CONTACT PAYLOAD UPDATED BY DYNAMIC BODY REQUEST: ', JSON.stringify(config, null, 6))
|
||||||
|
console.log('#####################')
|
||||||
|
}
|
||||||
|
|
||||||
let data
|
let data
|
||||||
try {
|
try {
|
||||||
let { data: _data } = await axios(config)
|
let { data: _data } = await axios(config)
|
||||||
|
@ -72,8 +79,8 @@ async function createContact(companyId, rest, authentication, crmPhone, crmFirst
|
||||||
}
|
}
|
||||||
|
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
|
||||||
// let { data } = await axios(config)
|
// let { data } = await axios(config)
|
||||||
|
|
||||||
data = flatten(data)
|
data = flatten(data)
|
||||||
|
|
Loading…
Reference in New Issue