Ajustes para evitar ura com ura infinita

pull/20/head
adriano 2023-06-27 20:17:09 -03:00
parent 864c24381c
commit 8c38542ab5
3 changed files with 59 additions and 28 deletions

View File

@ -9,13 +9,15 @@ import WhatsQueueIndex from "./WhatsQueueIndex";
const hitPortalMonitoring = async (params: object) => {
let response2 = await endPointQuery('http://177.107.193.124:8095/labs/zabbix-frontend/api/api.php', 'post', params)
console.log('response2: ', response2.data.result)
if (response2 && response2.data.result) {
return response2.data.result
} else {
let response = await endPointQuery('http://177.107.193.124:8095/labs/zabbix-frontend/api/api.php', 'post', params)
if (response && response.data.result.trim().length > 0) {
return response.data.result
}
else if (response && response.data.result.trim().length === 0) {
return ''
}
else {
return null
}

View File

@ -12,7 +12,7 @@ import { Op, where } from "sequelize";
import { Sequelize } from "sequelize";
import moment from 'moment';
import { startOfDay, endOfDay, parseISO, getDate} from "date-fns";
import { startOfDay, endOfDay, parseISO, getDate, subSeconds} from "date-fns";
import { string } from "yup/lib/locale";
//Report by user, startDate, endDate
@ -26,13 +26,29 @@ const ShowTicketMessage = async (ticketId: string | number, onlyNumber: boolean
fromMe: fromMe ? fromMe : 0,
//body: {[Op.regexp]: '^[0-9]*$'},
// body: {[Op.regexp]: '^[0-3]$'},
body: {[Op.regexp]: regexp},
body: {[Op.regexp]: regexp},
}
}
else{
where_clause = {
ticketId: ticketId,
fromMe: fromMe ? fromMe : 0,
updatedAt: {
[Op.between]: [+subSeconds(new Date(), 50), +new Date()],
},
body: {
[Op.or]: [
{
[Op.like]: '%não compreendi%'
},
{
[Op.like]: '%não captei%'
},
{
[Op.like]: '%Não consegui compreender%'
}
]
},
}
}

View File

@ -72,6 +72,7 @@ import { getWhatsappIds, setWhatsappId } from "../../helpers/WhatsappIdMultiSess
import SendWhatsAppMedia from "./SendWhatsAppMedia";
import AppError from "../../errors/AppError";
import hitPortalMonitoring from "../../helpers/HitPortalMonitoring";
import { tr } from "date-fns/locale";
@ -387,7 +388,7 @@ async function sendDelayedMessages(wbot: Session, ticket: Ticket, contact: Conta
let url = msgAction.actions[1].replace(/\.php.*/, '.php')
let response: any = null
let response: any = ''
if (params[0] === 'cod_web') {
@ -400,13 +401,17 @@ async function sendDelayedMessages(wbot: Session, ticket: Ticket, contact: Conta
}
if (response && response.trim() == 0) {
botSendMessage(ticket, contact, wbot, `Não existe nenhum chamado para essa consulta!\n _Digite *0* para voltar ao menu principal._`)
}
else if (response && response.trim().length > 0) {
await SendWhatsAppMessage({ body: response, ticket });
}
else {
console.log('~~~~~~~~~~~~~~~~~~~~~~>response: ', response, ' | response.trim().length: ', response.trim().length)
try {
if (response.trim().length == 0) {
botSendMessage(ticket, contact, wbot, `Não existe nenhum chamado para essa consulta!\n _Digite *0* para voltar ao menu principal._`)
}
else if (response.trim().length > 0) {
await SendWhatsAppMessage({ body: response, ticket });
}
} catch (error) {
botSendMessage(ticket, contact, wbot, `Houve um erro ao realizar a consulta!\n _Digite *0* para voltar ao menu principal._`)
}
@ -414,17 +419,17 @@ async function sendDelayedMessages(wbot: Session, ticket: Ticket, contact: Conta
console.log('>>>>>>>>>>>>>>> msgAction: ', msgAction, ' | msgAction.actions[1]: ', msgAction.actions[1])
const contact_custom_field = await ShowContactCustomFieldService(contact.id)
// const contact_custom_field = await ShowContactCustomFieldService(contact.id)
if (contact_custom_field && contact_custom_field.length > 0) {
// if (contact_custom_field && contact_custom_field.length > 0) {
const msg_endpoint = await queryEndPointHit(contact_custom_field[0].value)
// const msg_endpoint = await queryEndPointHit(contact_custom_field[0].value)
await monitoramento_response2(msg_endpoint, wbot, contact, ticket, contact_custom_field[0].value)
// await monitoramento_response2(msg_endpoint, wbot, contact, ticket, contact_custom_field[0].value)
}
// }
console.log('************* contact_custom_field: ', contact_custom_field)
// console.log('************* contact_custom_field: ', contact_custom_field)
// OLD
// const msg = await wbot.sendMessage(`${contact.number}@c.us`, msgAction.msgBody);
@ -693,7 +698,7 @@ const transferTicket = async (queueIndex: number, wbot: Session, ticket: Ticket,
const queues = queuesWhatsGreetingMessage.queues
console.log('queues ---> ', queues)
// console.log('queues ---> ', queues)
await botTransferTicket(queues[queueIndex], ticket, contact, wbot)
@ -1026,15 +1031,22 @@ const handleMessage = async (
// console.log('okkkkkkkkkkkkkkkkkk 5 test: ', test)
//test del transfere o atendimento se entrar na ura infinita
let ticket_message = await ShowTicketMessage(ticket.id, false);
let ticket_message = await ShowTicketMessage(ticket.id, false, true);
// console.log('=========> ticket_message ', ticket_message)
console.log('ticket_message.length ', ticket_message.length)
if (ticket_message.length > 5) {
if (ticket_message.length > 3) {
const { queues, } = await ShowWhatsAppService(wbot.id!);
// const { queues, } = await ShowWhatsAppService(wbot.id!);
await UpdateTicketService({ ticketData: { status: 'pending', queueId: queues[0].id }, ticketId: ticket.id });
await transferTicket(0, wbot, ticket, contact)
await SendWhatsAppMessage({
body: `Seu atendimento foi transferido para um agente!\n\nPara voltar ao menu principal digite *0*
`, ticket, number: `${contact.number}@c.us`
})
}
else {
@ -1067,6 +1079,7 @@ const handleMessage = async (
} catch (err) {
Sentry.captureException(err);
console.log('xxxxxxxxxxxxx err: ', err)
logger.error(`Error handling whatsapp message: Err: ${err}`);
}
};