FInalização do recurso de envio proativo

pull/20/head
adriano 2023-01-02 16:32:21 -03:00
parent db898bc804
commit f5b185e418
2 changed files with 95 additions and 10 deletions

View File

@ -13,6 +13,7 @@ import SendWhatsAppMessage from "../services/WbotServices/SendWhatsAppMessage";
import { Op, where, Sequelize } from "sequelize"; import { Op, where, Sequelize } from "sequelize";
import ShowTicketServiceByContactId from "../services/TicketServices/ShowTicketServiceByContactId"; import ShowTicketServiceByContactId from "../services/TicketServices/ShowTicketServiceByContactId";
import hitPortalMonitoring from "../helpers/HitPortalMonitoring";
// type IndexQuery = { // type IndexQuery = {
@ -29,24 +30,29 @@ export const hit = async (req: Request, res: Response): Promise<Response> => {
console.log('req.boy: ', req.body['centro_custo']) console.log('req.boy: ', req.body['centro_custo'])
if (req.headers["auth"] === '0424bd59b807674191e7d77572075f33') { if (req.headers["auth"] === '0424bd59b807674191e7d77572075f33') {
let contact = await ContactByCustomField(req.body['centro_custo']) let contact = await ContactByCustomField(req.body['centro_custo'])
// console.log('--------------> contact: ', contact) console.log('--------------> contact: ', contact)
if (contact) { if (contact) {
try { try {
let response = await hitPortalMonitoring(req.body['centro_custo'])
// console.log('RESPONSE: ', response)
const botInfo = await BotIsOnQueue('botqueue') const botInfo = await BotIsOnQueue('botqueue')
let ticket = await ShowTicketServiceByContactId(contact['contact.id']) let ticket = await ShowTicketServiceByContactId(contact['contact.id'])
if (ticket.id && ticket.status == 'pending') { if (ticket.id && ticket.status == 'pending') {
await SendWhatsAppMessage({ body: 'Resposta da operadora', ticket });
await sendMessageHitMonitoring(response, ticket);
} }
else if (!ticket.id) { else if (!ticket.id) {
@ -56,9 +62,10 @@ export const hit = async (req: Request, res: Response): Promise<Response> => {
await UpdateTicketService({ ticketData: { queueId: botInfo.botQueueId }, ticketId: ticket.id }); await UpdateTicketService({ ticketData: { queueId: botInfo.botQueueId }, ticketId: ticket.id });
await SendWhatsAppMessage({ body: 'Ola isso é um teste', ticket }); await sendMessageHitMonitoring(response, ticket);
} }
} catch (error) { } catch (error) {
@ -75,4 +82,14 @@ export const hit = async (req: Request, res: Response): Promise<Response> => {
return res.status(200).json({ "message": "Ok" }); return res.status(200).json({ "message": "Ok" });
}; };
async function sendMessageHitMonitoring(response: any, ticket: Ticket) {
for (let i = 0; i < response.length; i++) {
await SendWhatsAppMessage({ body: `*Situação do chamado na Operadora*\n\n*Incidente*:\n\n ${response[i].header}\n${response[i].body}`, ticket });
await new Promise(f => setTimeout(f, 1000));
}
}

View File

@ -0,0 +1,68 @@
const fsPromises = require("fs/promises");
const fs = require('fs')
import endPointQuery from "./EndpointQuery";
import WhatsQueueIndex from "./WhatsQueueIndex";
const hitPortalMonitoring = async (centro_de_custo: string) => {
let msg_endpoint: any = []
let response2 = await endPointQuery('http://177.107.193.124:8095/labs/zabbix-frontend/api/api.php', 'post', centro_de_custo.trim())
if (response2 && response2.data.result) {
response2 = response2.data.result;
for (let i = 0; i < response2.length; i++) {
let data = ''
let sub_data = '*Atualizações:*\n\n'
const properties: any = Object.entries(response2[i]);
for (let x = 0; x < properties.length; x++) {
if (typeof (properties[x][1]) != 'object') {
data += `*${properties[x][0]}*: ${properties[x][1].replace(/(\r\n|\n|\r)/gm, "")}\n`
}
else if (typeof (properties[x][1]) == 'object') {
const sub_properties = properties[x][1];
for (let k = 0; k < sub_properties.length; k++) {
const inner_properties: any = Object.entries(sub_properties[k]);
for (let y = 0; y < inner_properties.length; y++) {
sub_data += `*${inner_properties[y][0]}*: ${inner_properties[y][1].replace(/(\r\n|\n|\r)/gm, "")}\n`
}
sub_data += '\n'
}
}
}
msg_endpoint.push({ header: data, body: sub_data })
}
}
else {
msg_endpoint = null
}
return msg_endpoint
}
export default hitPortalMonitoring