Alterção no limite de armazenamento da lista de ids das mensagens enviadas e recebidas

pull/21/head
adriano 2022-11-16 15:29:20 -03:00
parent 74f38a82cf
commit d86a7efe12
4 changed files with 49 additions and 8 deletions

View File

@ -70,8 +70,9 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
Parcial ticket info:
ticket.id: ${ticket.id}
ticket.status: ${ticket.status}
ticket.whatsapp.id: ${ticket.whatsappId}
ticket.whatsapp.id: ${ticket.whatsappId}
ticket.contact.number: ${ticket.contact.number}
message: ${body}
ticket.contact.name: ${ticket.contact.name}
ticket.contact.profilePicUrl: ${ticket.contact.profilePicUrl}
ticket.user.id: ${ticket.user.id}

View File

@ -210,8 +210,8 @@ export const initWbot = async (whatsapp: Whatsapp, backupSessionRestore: boolean
export const getWbot = (whatsappId: number): Session => {
const sessionIndex = sessions.findIndex(s => s.id === whatsappId);
console.log('----------> sessionIndex: ', sessionIndex, ' | whatasappId: ', whatsappId)
console.log('----------> sessions: ',sessions.map(s => s.id))
// console.log('----------> sessionIndex: ', sessionIndex, ' | whatasappId: ', whatsappId)
// console.log('----------> sessions: ',sessions.map(s => s.id))
if (sessionIndex === -1) {
throw new AppError("ERR_WAPP_NOT_INITIALIZED");

View File

@ -73,7 +73,7 @@ const SendWhatsAppMessage = async ({
console.log('3 --------> ticket.whatsappId: ', ticket.whatsappId)
console.log('1 --------> ticket.whatsappId: ', ticket.whatsappId)
@ -100,7 +100,7 @@ const SendWhatsAppMessage = async ({
const wbot = await GetTicketWbot(ticket);
console.log('4 --------> ticket.whatsappId: ', ticket.whatsappId)
console.log('2 --------> send from whatsapp ticket.whatsappId: ', ticket.whatsappId)
try {

View File

@ -57,10 +57,9 @@ import { updateTicketCacheByTicketId } from '../../helpers/TicketCache'
import { insertMessageContactCache, getLastId } from '../../helpers/LastMessageIdByContactCache'
let testLastId = ''
let lst: any[] = []
let lstAux: any[] = []
let clear_lst: any
interface Session extends Client {
@ -364,6 +363,45 @@ const botSendMessage = (ticket: Ticket, contact: Contact, wbot: Session, msg: st
}
const _clear_lst = () => {
console.log('LIST (lst.length) WHATSAPP MESSAGE ID MULTI SESSION: : ', lst.length)
if (lst.length < 800 ) return
console.log('BEFORE lst SLICE: ', lst)
console.log('lst whatsapp message id sliced! | lst.length: ', lst.length)
const chunk: any = Math.floor((lst.length / 2))
lst = lst.slice(chunk, chunk + lst.length);
console.log('AFTER lst SLICE: ', lst)
}
const clearMultiSessionWhatsappMessageId = () => {
try {
clearInterval(clear_lst);
_clear_lst()
} catch (error) {
console.log('error on clear lst whatsapp id message: ', error)
}
finally {
clear_lst = setInterval(_clear_lst, 10000);
}
}
clear_lst = setInterval(clearMultiSessionWhatsappMessageId, 10000);
const handleMessage = async (
msg: WbotMessage,
wbot: Session
@ -371,7 +409,6 @@ const handleMessage = async (
// TEST DEL MULTI SESSION
let index = lst.findIndex((x: any) => x.id == msg.id.id)
console.log('INDEX: ', index)
@ -383,9 +420,12 @@ const handleMessage = async (
}
else {
console.log('IGNORED ID: ', msg.id.id)
return
}
// console.log('LIST OF ID MESSAGE lst: ', lst)
console.log('PASSOU.................................FROM: ', msg.from.split("@")[0], ' | ID: ', msg.id.id)
// const contact_message = await getLastId(`contact_message:5517988310949`)