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 { Sequelize } from "sequelize";
import moment from 'moment';
import { startOfDay, endOfDay, parseISO, getDate, subSeconds} from "date-fns";
import { Sequelize } from "sequelize";
import moment from 'moment';
import { startOfDay, endOfDay, parseISO, getDate, subSeconds } from "date-fns";
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
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 = {}
if(onlyNumber){
where_clause = {
ticketId: ticketId,
fromMe: fromMe ? fromMe : 0,
if (onlyNumber) {
where_clause = {
ticketId: ticketId,
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,
else {
where_clause = {
ticketId: ticketId,
fromMe: fromMe ? fromMe : 0,
updatedAt: {
[Op.between]: [+subSeconds(new Date(), 50), +new Date()],
[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%'
}
]
},
}
[Op.or]: paramsQuery(params)
}
// body: {
// [Op.or]: [
// {
// [Op.like]: '%não compreendi%'
// },
// {
// [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,
raw:true,
attributes: ['body', 'read', 'mediaType','fromMe', 'mediaUrl', [Sequelize.fn("DATE_FORMAT",Sequelize.col("createdAt"),"%d/%m/%Y %H:%i:%s"),"createdAt"]],
raw: true,
attributes: ['body', 'read', 'mediaType', 'fromMe', 'mediaUrl', [Sequelize.fn("DATE_FORMAT", Sequelize.col("createdAt"), "%d/%m/%Y %H:%i:%s"), "createdAt"]],
order: [
['createdAt', 'DESC']
]
});
]
});
if (!ticket) {
throw new AppError("ERR_NO_TICKET_FOUND", 404);
}
return ticket;
};
};
export default ShowTicketMessage;

View File

@ -648,7 +648,13 @@ const verifyQueue = async (
//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)
@ -1031,13 +1037,21 @@ 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, 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.length ', ticket_message.length)
if (ticket_message.length > 3) {
if (ticket_message.length > 3 || ticket_message2.length > 3) {
// const { queues, } = await ShowWhatsAppService(wbot.id!);