Ajustes para resolver o loop infinito de uras

pull/20/head
adriano 2023-06-29 06:01:37 -03:00
parent 8c38542ab5
commit 3568bf1461
2 changed files with 80 additions and 44 deletions

View File

@ -9,69 +9,91 @@ import { userInfo } from "os";
import { Op, where } from "sequelize"; import { Op, where } from "sequelize";
import { Sequelize } from "sequelize"; import { Sequelize } from "sequelize";
import moment from 'moment'; import moment from 'moment';
import { startOfDay, endOfDay, parseISO, getDate, subSeconds} from "date-fns"; import { startOfDay, endOfDay, parseISO, getDate, subSeconds } from "date-fns";
import { string } from "yup/lib/locale"; import { string } from "yup/lib/locale";
function paramsQuery(params: string[]) {
let like = []
for (let i = 0; i < params.length; i++) {
like.push({ [Op.like]: `%${params[i]}%` })
}
return like
}
//Report by user, startDate, endDate //Report by user, startDate, endDate
const ShowTicketMessage = async (ticketId: string | number, onlyNumber: boolean = false, fromMe?:boolean, limit?: number, regexp?: string): Promise<Message[]> => { const ShowTicketMessage = async (
ticketId: string | number,
onlyNumber: boolean = false,
params: string[],
fromMe?: boolean,
limit?: number,
regexp?: string): Promise<Message[]> => {
let where_clause = {} let where_clause = {}
if(onlyNumber){
where_clause = {
ticketId: ticketId, if (onlyNumber) {
fromMe: fromMe ? fromMe : 0, where_clause = {
ticketId: ticketId,
fromMe: fromMe ? fromMe : 0,
//body: {[Op.regexp]: '^[0-9]*$'}, //body: {[Op.regexp]: '^[0-9]*$'},
// body: {[Op.regexp]: '^[0-3]$'}, // body: {[Op.regexp]: '^[0-3]$'},
body: {[Op.regexp]: regexp}, body: { [Op.regexp]: regexp },
} }
} }
else{ else {
where_clause = { where_clause = {
ticketId: ticketId, ticketId: ticketId,
fromMe: fromMe ? fromMe : 0, fromMe: fromMe ? fromMe : 0,
updatedAt: { updatedAt: {
[Op.between]: [+subSeconds(new Date(), 50), +new Date()], [Op.between]: [+subSeconds(new Date(), 50), +new Date()],
}, },
body: { body: {
[Op.or]: [ [Op.or]: paramsQuery(params)
{ }
[Op.like]: '%não compreendi%' // body: {
}, // [Op.or]: [
{ // {
[Op.like]: '%não captei%' // [Op.like]: '%não compreendi%'
}, // },
{ // {
[Op.like]: '%Não consegui compreender%' // [Op.like]: '%não captei%'
} // },
] // {
}, // [Op.like]: '%Não consegui compreender%'
} // }
// ]
// },
}
} }
const ticket = await Message.findAll({
where: where_clause , const ticket = await Message.findAll({
where: where_clause,
limit: limit ? limit : 10000, limit: limit ? limit : 10000,
raw:true, raw: true,
attributes: ['body', 'read', 'mediaType','fromMe', 'mediaUrl', [Sequelize.fn("DATE_FORMAT",Sequelize.col("createdAt"),"%d/%m/%Y %H:%i:%s"),"createdAt"]], attributes: ['body', 'read', 'mediaType', 'fromMe', 'mediaUrl', [Sequelize.fn("DATE_FORMAT", Sequelize.col("createdAt"), "%d/%m/%Y %H:%i:%s"), "createdAt"]],
order: [ order: [
['createdAt', 'DESC'] ['createdAt', 'DESC']
] ]
}); });
if (!ticket) { if (!ticket) {
throw new AppError("ERR_NO_TICKET_FOUND", 404); throw new AppError("ERR_NO_TICKET_FOUND", 404);
} }
return ticket; return ticket;
}; };
export default ShowTicketMessage; export default ShowTicketMessage;

View File

@ -648,7 +648,13 @@ const verifyQueue = async (
//test del transfere o atendimento se entrar na ura infinita //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);
let ticket_message = await ShowTicketMessage(ticket.id, false, [],);
console.log('ticket_message.length ', ticket_message.length) console.log('ticket_message.length ', ticket_message.length)
@ -1031,13 +1037,21 @@ const handleMessage = async (
// console.log('okkkkkkkkkkkkkkkkkk 5 test: ', test) // console.log('okkkkkkkkkkkkkkkkkk 5 test: ', test)
//test del transfere o atendimento se entrar na ura infinita //test del transfere o atendimento se entrar na ura infinita
let ticket_message = await ShowTicketMessage(ticket.id, false, true); let ticket_message = await ShowTicketMessage(
ticket.id, false,
['não compreendi', 'não captei', 'Não consegui compreender'],
true);
let ticket_message2 = await ShowTicketMessage(
ticket.id, false,
['favor informe o',],
true);
// console.log('=========> ticket_message ', ticket_message) // console.log('=========> ticket_message ', ticket_message)
console.log('ticket_message.length ', ticket_message.length) console.log('ticket_message.length ', ticket_message.length)
if (ticket_message.length > 3) { if (ticket_message.length > 3 || ticket_message2.length > 3) {
// const { queues, } = await ShowWhatsAppService(wbot.id!); // const { queues, } = await ShowWhatsAppService(wbot.id!);