feat: Delete client session keys from Redis after 3 minutes of inactivity
parent
02ded6e4ee
commit
9e84e4cf08
|
@ -0,0 +1,44 @@
|
||||||
|
NODE_ENV=
|
||||||
|
BACKEND_URL=http://localhost
|
||||||
|
FRONTEND_URL=http://localhost:3000
|
||||||
|
PROXY_PORT=8080
|
||||||
|
PORT=8080
|
||||||
|
|
||||||
|
DB_DIALECT=mysql
|
||||||
|
DB_HOST=localhost
|
||||||
|
DB_USER=whaticket
|
||||||
|
DB_PASS=strongpassword
|
||||||
|
DB_NAME=whaticket
|
||||||
|
|
||||||
|
# WHATSAPP OFFICIAL
|
||||||
|
VERIFY_TOKEN=HAPPY
|
||||||
|
TOKEN=EAAEPZBB2YqgwBOZBEAvPxYaO2nbPvuzU3ZBaZA6YF6tyWtjKom2yLxPxOm421njhbb1ZC2rOkyQyZCWpZBk9jXZCAaMLNY6SkNOrwPoRNaqO9Fbj31mZC8mxra08jIhBiziX7IZBFDWYbkcfw5cfLdTSys9ilfRlKsIZClOUlTiHnhSDkMvXY6rMFrvWswR2YVvJVH1qPvM7hGuuUqM
|
||||||
|
VERSION=v17.0
|
||||||
|
URL_WHATSAPP_MEDIA=https://ccsm-api.omnihit.app.br/whatsapp/official/media
|
||||||
|
URL_WHATSAPP_API=https://graph.facebook.com
|
||||||
|
|
||||||
|
JWT_SECRET=3123123213123
|
||||||
|
JWT_REFRESH_SECRET=75756756756
|
||||||
|
|
||||||
|
SENTRY_DSN=
|
||||||
|
|
||||||
|
CACHE=
|
||||||
|
|
||||||
|
WHATS_NUMBER_VALIDATOR_URL=http://localhost:8021
|
||||||
|
|
||||||
|
TOKEN_REMOTE_TICKET_CREATION=emvd7UfskjstMC99mFqs2tEiNmn05PgsUVK06TZP9LfkyjxDrsKCxlVV5ApYM7hP
|
||||||
|
TOKEN_IAM_HORACIUS_EL=emvd7UfskjstMC99mFqs2tEiNmn05PgsUVK06TZP9LfkyjxDrsKCxlVV5ApYM7hP
|
||||||
|
|
||||||
|
# omnihit da hit test bot
|
||||||
|
# APP_NAME=recrutamento_el
|
||||||
|
APP_NAME=test
|
||||||
|
|
||||||
|
BACKEND_URL_RAW=http://localhost
|
||||||
|
|
||||||
|
PUBLICKEY=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwOvEh4Qc0yeJidiX3YpDdOB/XuDeyNRaypmSyW5FjjIxBFaMiUmNSZ2X2m2LqyyrHJxQgRqwjifHUQ+ivmNBm4YFNSr05iFB/kgi/1Jmbst6h1MnmuD1YFSRnEsmdUXzhhgcj5btyjRfw6L2rGwOnqzMzS54seE1aAy+rtN82DW8wfbYU/IO83MAJiocthCBOev5MDUq6hdkGPPZ/kdFOLcQe+wt/suhmF4KRfq77X4GgLM5nAOMj7N7cJ6b97nB47krfPOMJissNzPDZ879BKeQX4t8TwJGUFNOvLd3UW3xVBTBz8pSS36VlCXjbYm44za8eTuBLDYYbGkUNEFYxwIDAQAB
|
||||||
|
|
||||||
|
REDIS_URI=redis://127.0.0.1:6379
|
||||||
|
|
||||||
|
URL_DASHBOARD_SESSIONS=http://localhost:6002
|
||||||
|
TOKEN_DASHBOARD_SESSIONS=8168dd72adb7bab7e8f54f9d022468ab
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
"socket.io-client": "^4.5.4",
|
"socket.io-client": "^4.5.4",
|
||||||
"uuid": "^8.3.2",
|
"uuid": "^8.3.2",
|
||||||
"whatsapp-web.js": "github:pedroslopez/whatsapp-web.js",
|
"whatsapp-web.js": "github:pedroslopez/whatsapp-web.js",
|
||||||
|
"xml2js": "^0.6.2",
|
||||||
"yup": "^0.32.8"
|
"yup": "^0.32.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
@ -92,11 +92,21 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
||||||
return res.status(200).json(queue);
|
return res.status(200).json(queue);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const form = async (req: Request, res: Response): Promise<Response> => {
|
||||||
|
const { form, name } = req.body;
|
||||||
|
|
||||||
|
if (!form || !name) throw new AppError("BAD REQUEST", 400);
|
||||||
|
|
||||||
|
await set(name, form);
|
||||||
|
|
||||||
|
return res.status(200).json({ [name]: form });
|
||||||
|
};
|
||||||
|
|
||||||
export const customization = async (
|
export const customization = async (
|
||||||
req: Request,
|
req: Request,
|
||||||
res: Response
|
res: Response
|
||||||
): Promise<Response> => {
|
): Promise<Response> => {
|
||||||
const { ura } = req.body;
|
const { ura, number } = req.body;
|
||||||
|
|
||||||
if (!ura) throw new AppError("BAD REQUEST", 400);
|
if (!ura) throw new AppError("BAD REQUEST", 400);
|
||||||
|
|
||||||
|
@ -184,10 +194,10 @@ export const customization = async (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await set("ura", ura);
|
await set(`ura_${number}`, ura);
|
||||||
|
|
||||||
const _ura = await get({ key: "ura", parse: true });
|
const _ura = await get({ key: `ura_${number}`, parse: true });
|
||||||
console.log("_URA: ", _ura);
|
console.log(`ura_${number}`, _ura);
|
||||||
|
|
||||||
return res.status(200).json({ new_queues });
|
return res.status(200).json({ new_queues });
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,54 +1,60 @@
|
||||||
import ListTicketTimeLife from "../services/TicketServices/ListTicketTimeLife";
|
import ListTicketTimeLife from "../services/TicketServices/ListTicketTimeLife";
|
||||||
import UpdateTicketService from "../services/TicketServices/UpdateTicketService";
|
import UpdateTicketService from "../services/TicketServices/UpdateTicketService";
|
||||||
|
import { delForm } from "../services/WbotServices/wbotMessageListener";
|
||||||
import BotIsOnQueue from "./BotIsOnQueue";
|
import BotIsOnQueue from "./BotIsOnQueue";
|
||||||
|
import { del } from "./RedisClient";
|
||||||
|
|
||||||
const fsPromises = require("fs/promises");
|
const fsPromises = require("fs/promises");
|
||||||
const fs = require('fs')
|
const fs = require("fs");
|
||||||
|
|
||||||
let timer: any
|
let timer: any;
|
||||||
|
|
||||||
const CloseBotTickets = async () => {
|
const CloseBotTickets = async () => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const botInfo = await BotIsOnQueue("botqueue");
|
||||||
|
|
||||||
const botInfo = await BotIsOnQueue('botqueue')
|
if (!botInfo.userIdBot) return;
|
||||||
|
|
||||||
if (!botInfo.userIdBot) return
|
let tickets: any = await ListTicketTimeLife({
|
||||||
|
timeseconds: 60,
|
||||||
|
status: "open",
|
||||||
|
userId: botInfo.userIdBot
|
||||||
|
});
|
||||||
|
|
||||||
let tickets: any = await ListTicketTimeLife({ timeseconds: 60, status: 'open', userId: botInfo.userIdBot })
|
console.log("tickets: ", tickets);
|
||||||
|
|
||||||
console.log('tickets: ', tickets)
|
|
||||||
|
|
||||||
for (let i = 0; i < tickets.length; i++) {
|
for (let i = 0; i < tickets.length; i++) {
|
||||||
|
|
||||||
await UpdateTicketService({
|
await UpdateTicketService({
|
||||||
ticketData: { 'status': 'closed', 'userId': botInfo.userIdBot, 'statusChatEnd': 'FINALIZADO' },
|
ticketData: {
|
||||||
|
status: "closed",
|
||||||
|
userId: botInfo.userIdBot,
|
||||||
|
statusChatEnd: "FINALIZADO"
|
||||||
|
},
|
||||||
ticketId: tickets[i].ticket_id
|
ticketId: tickets[i].ticket_id
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tickets[i].id = tickets[i].ticket_id;
|
||||||
|
delForm(tickets[i]);
|
||||||
|
del(`form:${tickets[i].id}:request`);
|
||||||
|
del(`form:${tickets[i].id}:confirmation`);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('There was an error on try close the bot tickets: ', error)
|
console.log("There was an error on try close the bot tickets: ", error);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|
||||||
const schedule = async () => {
|
const schedule = async () => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
clearInterval(timer);
|
clearInterval(timer);
|
||||||
|
|
||||||
await CloseBotTickets()
|
await CloseBotTickets();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('error on schedule: ', error)
|
console.log("error on schedule: ", error);
|
||||||
|
} finally {
|
||||||
|
timer = setInterval(schedule, 180000);
|
||||||
}
|
}
|
||||||
finally {
|
};
|
||||||
timer = setInterval(schedule, 60000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
timer = setInterval(schedule, 60000);
|
timer = setInterval(schedule, 180000);
|
||||||
|
|
||||||
export default schedule;
|
export default schedule;
|
|
@ -44,7 +44,7 @@ export async function get({ key, value, parse }: getData) {
|
||||||
for (const key of keys) {
|
for (const key of keys) {
|
||||||
const val = await redis.get(key);
|
const val = await redis.get(key);
|
||||||
if (parse) res.push(JSON.parse(val));
|
if (parse) res.push(JSON.parse(val));
|
||||||
res.push(val);
|
else res.push(val);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ queueRoutes.post("/queue", isAuth, QueueController.store);
|
||||||
|
|
||||||
queueRoutes.post("/queue/customization", QueueController.customization);
|
queueRoutes.post("/queue/customization", QueueController.customization);
|
||||||
|
|
||||||
|
queueRoutes.post("/queue/form", QueueController.form);
|
||||||
|
|
||||||
queueRoutes.get("/queue/remote/list", isAuth, QueueController.listQueues);
|
queueRoutes.get("/queue/remote/list", isAuth, QueueController.listQueues);
|
||||||
|
|
||||||
queueRoutes.get("/queue/:queueId", isAuth, QueueController.show);
|
queueRoutes.get("/queue/:queueId", isAuth, QueueController.show);
|
||||||
|
|
|
@ -19,7 +19,7 @@ import {
|
||||||
|
|
||||||
import ListWhatsAppsNumber from "../WhatsappService/ListWhatsAppsNumber";
|
import ListWhatsAppsNumber from "../WhatsappService/ListWhatsAppsNumber";
|
||||||
import { getWbot } from "../../libs/wbot";
|
import { getWbot } from "../../libs/wbot";
|
||||||
import { json } from "sequelize/types";
|
import { QueryTypes, json } from "sequelize/types";
|
||||||
|
|
||||||
import { restartWhatsSession } from "../../helpers/RestartWhatsSession";
|
import { restartWhatsSession } from "../../helpers/RestartWhatsSession";
|
||||||
// import { insertOrUpeateWhatsCache, searchWhatsappCache } from "../../helpers/WhatsCache";
|
// import { insertOrUpeateWhatsCache, searchWhatsappCache } from "../../helpers/WhatsCache";
|
||||||
|
@ -58,12 +58,6 @@ const SendWhatsAppMessage = async ({
|
||||||
|
|
||||||
let quotedMsgSerializedId: string | undefined;
|
let quotedMsgSerializedId: string | undefined;
|
||||||
|
|
||||||
if (quotedMsg) {
|
|
||||||
await GetWbotMessage(ticket, quotedMsg.id);
|
|
||||||
|
|
||||||
quotedMsgSerializedId = SerializeWbotMsgId(ticket, quotedMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("quotedMsgSerializedId: ", quotedMsgSerializedId);
|
console.log("quotedMsgSerializedId: ", quotedMsgSerializedId);
|
||||||
|
|
||||||
let whatsapps: any;
|
let whatsapps: any;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue