import SetTicketMessagesAsRead from "../helpers/SetTicketMessagesAsRead"; import ShowTicketService from "../services/TicketServices/ShowTicketService"; import SendWhatsAppMessage from "../services/WbotServices/SendWhatsAppMessage"; import ListSchedulingNotifyService from "../services/SchedulingNotifyServices/ListSchedulingNotifyService"; import DeleteSchedulingNotifyService from "../services/SchedulingNotifyServices/DeleteSchedulingNotifyService"; let countTest: number = 0 let scheduler_monitor:any; // const test = async () => { // const ticket = await ShowTicketService('336'); // SetTicketMessagesAsRead(ticket); // await SendWhatsAppMessage({ body: 'Olá Sr Adriano, estamos entrando em contato para confirmar seu retorno hoje', ticket }); // } const monitor = async () => { countTest += 1 console.log(`${countTest}`) let date = new Date() let day = date.getDate().toString().padStart(2, '0'); let month = (date.getMonth()+1).toString().padStart(2, '0'); let year = date.getFullYear(); let hour = date.getHours() let minute = date.getMinutes() let fullDate = `${year}-${month}-${day}`; let dateParm = `${fullDate} ${hour.toString().padStart(2, '0')}:${minute.toString().padStart(2, '0')}:00` console.log(dateParm); const { schedulingNotifies, count, hasMore } = await ListSchedulingNotifyService({ searchParam: dateParm, pageNumber: "1" }); if(schedulingNotifies.length){ const ticket = await ShowTicketService(schedulingNotifies[0].ticketId); SetTicketMessagesAsRead(ticket); await SendWhatsAppMessage({ body: schedulingNotifies[0].message, ticket }); DeleteSchedulingNotifyService(schedulingNotifies[0].id) } }; export const startSchedulingMonitor =async (mileseconds: number) => { scheduler_monitor = setInterval(monitor, mileseconds) } export const stopSchedulingMonitor =async ( ) => { clearInterval(scheduler_monitor) }