FInalização do recurso de envio proativo
parent
db898bc804
commit
f5b185e418
|
@ -13,6 +13,7 @@ import SendWhatsAppMessage from "../services/WbotServices/SendWhatsAppMessage";
|
|||
|
||||
import { Op, where, Sequelize } from "sequelize";
|
||||
import ShowTicketServiceByContactId from "../services/TicketServices/ShowTicketServiceByContactId";
|
||||
import hitPortalMonitoring from "../helpers/HitPortalMonitoring";
|
||||
|
||||
|
||||
// type IndexQuery = {
|
||||
|
@ -33,19 +34,24 @@ export const hit = async (req: Request, res: Response): Promise<Response> => {
|
|||
|
||||
let contact = await ContactByCustomField(req.body['centro_custo'])
|
||||
|
||||
// console.log('--------------> contact: ', contact)
|
||||
console.log('--------------> contact: ', contact)
|
||||
|
||||
|
||||
if (contact) {
|
||||
|
||||
try {
|
||||
|
||||
let response = await hitPortalMonitoring(req.body['centro_custo'])
|
||||
|
||||
// console.log('RESPONSE: ', response)
|
||||
|
||||
const botInfo = await BotIsOnQueue('botqueue')
|
||||
|
||||
let ticket = await ShowTicketServiceByContactId(contact['contact.id'])
|
||||
|
||||
if (ticket.id && ticket.status == 'pending') {
|
||||
|
||||
await SendWhatsAppMessage({ body: 'Resposta da operadora', ticket });
|
||||
await sendMessageHitMonitoring(response, ticket);
|
||||
|
||||
}
|
||||
else if (!ticket.id) {
|
||||
|
@ -56,10 +62,11 @@ export const hit = async (req: Request, res: Response): Promise<Response> => {
|
|||
|
||||
await UpdateTicketService({ ticketData: { queueId: botInfo.botQueueId }, ticketId: ticket.id });
|
||||
|
||||
await SendWhatsAppMessage({ body: 'Ola isso é um teste', ticket });
|
||||
await sendMessageHitMonitoring(response, ticket);
|
||||
|
||||
}
|
||||
|
||||
|
||||
} catch (error) {
|
||||
|
||||
console.log(`Error on try sending the message monitor: `, error)
|
||||
|
@ -76,3 +83,13 @@ export const hit = async (req: Request, res: Response): Promise<Response> => {
|
|||
|
||||
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));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue