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,
|
||||
createContact,
|
||||
lookupContactByPhone,
|
||||
templateValidator } = require('../utils')
|
||||
templateValidator,
|
||||
loadCRM } = require('../utils')
|
||||
const fs = require("fs")
|
||||
const { URL } = require('url')
|
||||
const { oauth2 } = require('../utils')
|
||||
|
@ -35,16 +36,53 @@ const getSalesforceUser = require('../utils/getSalesforceUser')
|
|||
|
||||
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',])
|
||||
|
||||
await createCRMContact(companyId, crmFirstName, crmPhone, crmEmail, crmLastName)
|
||||
await createCRMContact(companyId, crmFirstName, crmPhone, crmEmail, crmLastName, dynamicBodyRequest)
|
||||
|
||||
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) => {
|
||||
|
||||
let { companyId, crmBaseURL } = req.body
|
||||
|
@ -569,7 +607,9 @@ module.exports = {
|
|||
webhook_crm,
|
||||
sfCreateCase,
|
||||
sfUpdateCase,
|
||||
createTicket
|
||||
createTicket,
|
||||
checkContact,
|
||||
contactActivity
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
const express = require('express')
|
||||
const router = express.Router()
|
||||
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")
|
||||
|
||||
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('/call-journaling').post(authorization, callJournaling)
|
||||
router.route('/upload').post(fileUpload.single('crm'), authorization, uploadCrmConfig)
|
||||
|
|
|
@ -2,7 +2,7 @@ const lookupContactByPhone = require('./lookupCRMContactByPhone')
|
|||
const createContact = require('./createContact')
|
||||
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)
|
||||
|
||||
|
@ -14,7 +14,7 @@ async function createCRMContact(companyId, crmFirstName, crmPhone, crmEmail = ''
|
|||
|
||||
if (contact.exist) continue
|
||||
|
||||
await createContact(companyId, rest, authentication, crmPhone, crmFirstName, crmLastName, crmEmail,)
|
||||
await createContact(companyId, rest, authentication, crmPhone, crmFirstName, crmLastName, crmEmail, {}, dynamicBodyRequest)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ const CRM = require('../models/CRM')
|
|||
const requestConfigHeader = require('./requestConfigHeader')
|
||||
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')
|
||||
|
||||
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
|
||||
|
||||
//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) {
|
||||
msg = `Tentanto criar contato de numero ${crmPhone} no crm`
|
||||
|
@ -53,6 +53,13 @@ async function createContact(companyId, rest, authentication, crmPhone, crmFirst
|
|||
console.log('CREATE CONTACT PAYLOAD: ', JSON.stringify(config, null, 6))
|
||||
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
|
||||
try {
|
||||
let { data: _data } = await axios(config)
|
||||
|
|
Loading…
Reference in New Issue