feat: new routes to find contact and create whatsapp journaling in salesforce
parent
844593749b
commit
61783eecf6
|
@ -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')
|
||||
|
@ -45,6 +46,43 @@ const contactCreate = async (req, res) => {
|
|||
|
||||
}
|
||||
|
||||
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',])
|
||||
|
||||
await whatsappJournalingCRM(
|
||||
companyId,
|
||||
crmPhone,
|
||||
'0000',
|
||||
crmFirstName = "xxx",
|
||||
ticketId
|
||||
)
|
||||
|
||||
res.status(StatusCodes.OK).send()
|
||||
}
|
||||
|
||||
const deleteCrm = async (req, res) => {
|
||||
|
||||
let { companyId, crmBaseURL } = req.body
|
||||
|
@ -436,7 +474,7 @@ const webhook = async (req, res) => {
|
|||
}
|
||||
|
||||
let crmPhone = phone_number.replace('+', '')
|
||||
|
||||
|
||||
const company = await Company.findOne({
|
||||
integrations: {
|
||||
$elemMatch: {
|
||||
|
@ -448,7 +486,7 @@ const webhook = async (req, res) => {
|
|||
|
||||
if (!company) {
|
||||
return res.status(StatusCodes.NOT_FOUND).send({ msg: "companyId not found!" })
|
||||
}
|
||||
}
|
||||
|
||||
console.log('=======> name: ', name)
|
||||
console.log('=======> crmPhone: ', crmPhone)
|
||||
|
@ -523,7 +561,7 @@ const webhook_crm = async (req, res) => {
|
|||
|
||||
if (!contact) return res.send()
|
||||
|
||||
const { phone } = contact
|
||||
const { phone } = contact
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
contactCreate,
|
||||
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue