Compare commits
3 Commits
344dafbb48
...
f05bfa4047
Author | SHA1 | Date |
---|---|---|
|
f05bfa4047 | |
|
1d300e07ca | |
|
89db3e83c9 |
|
@ -145,16 +145,16 @@ const callJournaling = async (req, res) => {
|
||||||
res.status(StatusCodes.OK).send()
|
res.status(StatusCodes.OK).send()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// console.log(`[ERROR - ${new Date()}] Erro no Call Journaling`, error?.response?.data)
|
// console.log(`[ERROR - ${new Date()}] Erro no Call Journaling`, error?.response?.data)
|
||||||
|
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
console.error('==================> callJournaling Erro na resposta da API:', {
|
console.error('==================> callJournaling Erro na resposta da API:', {
|
||||||
status: error.response.status,
|
status: error.response.status,
|
||||||
data: error.response.data,
|
data: error.response.data,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
else if (error.request) {
|
else if (error.request) {
|
||||||
console.error('==================> callJournaling Nenhuma resposta recebida da API:', error.request)
|
console.error('==================> callJournaling Nenhuma resposta recebida da API:', error.request)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.error('==================> callJournaling Erro ao configurar a request:', error.message)
|
console.error('==================> callJournaling Erro ao configurar a request:', error.message)
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,7 @@ const sfCreateCase = async (req, res) => {
|
||||||
|
|
||||||
const { companyId, crmPhone } = req.body
|
const { companyId, crmPhone } = req.body
|
||||||
|
|
||||||
mustContainProperties(req, ['companyId', 'crmPhone',])
|
mustContainProperties(req, ['companyId', 'crmPhone',])
|
||||||
|
|
||||||
const sfCaseRes = await sfcase(companyId, crmPhone)
|
const sfCaseRes = await sfcase(companyId, crmPhone)
|
||||||
|
|
||||||
|
@ -223,7 +223,7 @@ const oauthCallBack = async (req, res) => {
|
||||||
if (code) {
|
if (code) {
|
||||||
|
|
||||||
console.log('xxxxxxxxxx passed')
|
console.log('xxxxxxxxxx passed')
|
||||||
|
|
||||||
let crmOauth = await CRM.findOne({ 'crm.authentication.crmClientId': clientId, 'companyId': companyId })
|
let crmOauth = await CRM.findOne({ 'crm.authentication.crmClientId': clientId, 'companyId': companyId })
|
||||||
|
|
||||||
crmOauth = crmOauth.toObject()
|
crmOauth = crmOauth.toObject()
|
||||||
|
@ -421,12 +421,12 @@ const webhook = async (req, res) => {
|
||||||
if (!req.body?.meta)
|
if (!req.body?.meta)
|
||||||
return res.status(StatusCodes.OK).send()
|
return res.status(StatusCodes.OK).send()
|
||||||
|
|
||||||
let { name, phone_number } = req.body.meta.sender
|
let { name, phone_number } = req.body.meta.sender
|
||||||
|
|
||||||
const {id: ticketId, account_id: accountId} = req.body
|
const { id: ticketId, account_id: accountId } = req.body
|
||||||
|
|
||||||
//channel: 'Channel::FacebookPage'
|
//channel: 'Channel::FacebookPage'
|
||||||
console.log("2 =============> ticketId id: ", ticketId, " | accountId account_id: ",accountId)
|
console.log("2 =============> ticketId id: ", ticketId, " | accountId account_id: ", accountId)
|
||||||
|
|
||||||
if (!phone_number) {
|
if (!phone_number) {
|
||||||
|
|
||||||
|
@ -436,24 +436,30 @@ const webhook = async (req, res) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
let crmPhone = phone_number.replace('+', '')
|
let crmPhone = phone_number.replace('+', '')
|
||||||
|
|
||||||
|
const company = await Company.findOne({
|
||||||
|
integrations: {
|
||||||
|
$elemMatch: {
|
||||||
|
name: "omnihit",
|
||||||
|
"config.accountId": `${accountId}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const companies = [
|
if (!company) {
|
||||||
// { companyId: "99", account_id: "1" },
|
return res.status(StatusCodes.NOT_FOUND).send({ msg: "companyId not found!" })
|
||||||
{ companyId: "99", account_id: "15" },
|
}
|
||||||
]
|
|
||||||
|
|
||||||
const obj = companies.find(c => +c.account_id == +accountId)
|
|
||||||
|
|
||||||
console.log('=======> name: ', name)
|
console.log('=======> name: ', name)
|
||||||
console.log('=======> crmPhone: ', crmPhone)
|
console.log('=======> crmPhone: ', crmPhone)
|
||||||
console.log('=======> accountId: ', accountId)
|
console.log('=======> accountId: ', accountId)
|
||||||
console.log('=======> companyId: ', obj.companyId)
|
console.log('=======> companyId: ', company.companyId)
|
||||||
|
|
||||||
console.log('=======> ticketId: ', ticketId)
|
console.log('=======> ticketId: ', ticketId)
|
||||||
|
|
||||||
|
|
||||||
await whatsappJournalingCRM(
|
await whatsappJournalingCRM(
|
||||||
companyId = obj.companyId,
|
companyId = company.companyId,
|
||||||
crmPhone = crmPhone,
|
crmPhone = crmPhone,
|
||||||
crmAgent = '0000',
|
crmAgent = '0000',
|
||||||
crmFirstName = name,
|
crmFirstName = name,
|
||||||
|
@ -517,16 +523,14 @@ const webhook_crm = async (req, res) => {
|
||||||
|
|
||||||
if (!contact) return res.send()
|
if (!contact) return res.send()
|
||||||
|
|
||||||
const { phone } = contact
|
const { phone } = contact
|
||||||
|
|
||||||
// const obj = omnihitV2Integration.find(o => o.companyId == companyId)
|
const config = await getIntegrationsConfig(companyId, 'omnihit')
|
||||||
|
|
||||||
const config = await getIntegrationsConfig(companyId, 'omnihit')
|
|
||||||
|
|
||||||
if (config) {
|
if (config) {
|
||||||
|
|
||||||
const { accountId, api: { url, token } = {},
|
const { accountId, api: { url, token } = {},
|
||||||
createConversation: { inbox_id, status, team_id } = {} = {} } = config
|
createConversation: { inbox_id, status, team_id } = {} = {} } = config
|
||||||
|
|
||||||
const contactIdChatwoot = await getContactIdChatwoot(url, token, phone)
|
const contactIdChatwoot = await getContactIdChatwoot(url, token, phone)
|
||||||
|
|
||||||
|
@ -549,16 +553,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)
|
||||||
}
|
}
|
||||||
|
|
||||||
const integration = async (req, res) => {
|
|
||||||
const { companyId } = req.query
|
|
||||||
const { integration } = req.body
|
|
||||||
|
|
||||||
console.log("====> companyId: ", companyId, " | integration: ", integration)
|
|
||||||
|
|
||||||
res.send()
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
contactCreate,
|
contactCreate,
|
||||||
|
|
Loading…
Reference in New Issue