Atualização da mensagem que é enviada automaticamente para o cliente no envio proativo

pull/20/head
adriano 2023-01-02 17:54:18 -03:00
parent f5b185e418
commit 5f55f4d50c
1 changed files with 16 additions and 11 deletions

View File

@ -19,7 +19,7 @@ import hitPortalMonitoring from "../helpers/HitPortalMonitoring";
// type IndexQuery = { // type IndexQuery = {
// centro_custo: string; // centro_custo: string;
// }; // };
export const hit = async (req: Request, res: Response): Promise<Response> => { export const hit = async (req: Request, res: Response): Promise<Response> => {
// const { // const {
@ -41,17 +41,20 @@ export const hit = async (req: Request, res: Response): Promise<Response> => {
try { try {
let response = await hitPortalMonitoring(req.body['centro_custo']) let response = await hitPortalMonitoring(req.body['centro_custo'])
// console.log('RESPONSE: ', response) if (!response || response.length == 0) {
console.log('Empty result from hit portal monitoring. Centro_de_custo: ',req.body['centro_custo'])
return res.status(200).json({ "message": "Ok" });
}
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 sendMessageHitMonitoring(response, ticket); await sendMessageHitMonitoring(response, ticket, contact);
} }
else if (!ticket.id) { else if (!ticket.id) {
@ -62,7 +65,7 @@ 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 sendMessageHitMonitoring(response, ticket); await sendMessageHitMonitoring(response, ticket, contact);
} }
@ -84,12 +87,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) { async function sendMessageHitMonitoring(response: any, ticket: Ticket, contact: any) {
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 }); if (response && response.length > 0) {
await new Promise(f => setTimeout(f, 1000)); console.log('MESSAGE WILL BE SENT!')
await SendWhatsAppMessage({ body: `*Olá. Somos a TI Espaçolaser.*\nIdentificamos em nossos monitoramentos que há um problema na internet da sua loja ${contact['contact.name']} e já estamos resolvendo. Abaixo seguem informações sobre o incidente para que possam acompanhar.\n\n*Situação do chamado na Operadora*\n\n*Incidente*:\n\n ${response[0].header}\n${response[0].body}`, ticket });
}
}
} }