Criação do Load Balance para usuarios que estejam na mesma fila. Criação de solução de para reaproveitar sessão
parent
3d69fa84ef
commit
c5c13f2b34
|
@ -25,6 +25,7 @@
|
|||
"dotenv": "^8.2.0",
|
||||
"express": "^4.17.1",
|
||||
"express-async-errors": "^3.1.1",
|
||||
"fs-extra": "^10.1.0",
|
||||
"http-graceful-shutdown": "^2.3.2",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"multer": "^1.4.2",
|
||||
|
|
|
@ -5,6 +5,8 @@ import ShowWhatsAppService from "../services/WhatsappService/ShowWhatsAppService
|
|||
import { StartWhatsAppSession } from "../services/WbotServices/StartWhatsAppSession";
|
||||
import UpdateWhatsAppService from "../services/WhatsappService/UpdateWhatsAppService";
|
||||
|
||||
import { restartWhatsSession } from "../helpers/RestartWhatsSession";
|
||||
|
||||
import path from 'path';
|
||||
|
||||
// import { WWebJsw } from "../../WWebJS/session-bd_40"
|
||||
|
@ -31,6 +33,24 @@ const update = async (req: Request, res: Response): Promise<Response> => {
|
|||
return res.status(200).json({ message: "Starting session." });
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
const restart = async (req: Request, res: Response): Promise<Response> => {
|
||||
|
||||
const { whatsappId } = req.params;
|
||||
|
||||
console.log('FROM REQUEST WHATSAPP ID: ', whatsappId)
|
||||
|
||||
const whatsapp = await ShowWhatsAppService(whatsappId);
|
||||
|
||||
await restartWhatsSession(whatsapp)
|
||||
|
||||
return res.status(200).json({ message: "Starting session." });
|
||||
};
|
||||
|
||||
|
||||
|
||||
const remove = async (req: Request, res: Response): Promise<Response> => {
|
||||
const { whatsappId } = req.params;
|
||||
const whatsapp = await ShowWhatsAppService(whatsappId);
|
||||
|
@ -44,9 +64,9 @@ const remove = async (req: Request, res: Response): Promise<Response> => {
|
|||
|
||||
//removeDir(path.join(process.cwd(),'.wwebjs_auth', `session-bd_${whatsapp.id}`))
|
||||
|
||||
wbot.logout();
|
||||
await wbot.logout();
|
||||
|
||||
return res.status(200).json({ message: "Session disconnected." });
|
||||
};
|
||||
|
||||
export default { store, remove, update };
|
||||
export default { store, remove, update, restart };
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
const fsPromises = require("fs/promises");
|
||||
const fs = require('fs-extra')
|
||||
|
||||
// Delete a directory and its children
|
||||
export const copyFolder = (sourcePath: string, destPath: string) => {
|
||||
|
||||
fs.copySync(sourcePath, destPath, { overwrite: true }, (err: any) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
} else {
|
||||
console.log("Copy dir success!");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
|
@ -7,7 +7,7 @@ export const removeDir = async (dirPath:string) => {
|
|||
if (fs.existsSync(dirPath)){
|
||||
|
||||
try {
|
||||
await fsPromises.rm(dirPath, { recursive: true });
|
||||
await fsPromises.rm(dirPath, { recursive: true, force: true});
|
||||
console.log("Directory removed!");
|
||||
}
|
||||
catch (err) {
|
||||
|
|
|
@ -8,35 +8,47 @@ import { Op, where } from "sequelize";
|
|||
|
||||
import wbotByUserQueue from '../helpers/GetWbotByUserQueue'
|
||||
|
||||
const GetDefaultWhatsApp = async (userId?: string | number ): Promise<Whatsapp> => {
|
||||
|
||||
// import WhatsQueueIndex from "./WhatsQueueIndex";
|
||||
|
||||
import { WhatsIndex } from "./LoadBalanceWhatsSameQueue";
|
||||
|
||||
const GetDefaultWhatsApp = async (userId?: string | number): Promise<Whatsapp> => {
|
||||
|
||||
// test del
|
||||
let defaultWhatsapp = await Whatsapp.findOne({
|
||||
where: { isDefault: true }
|
||||
});
|
||||
|
||||
if (!defaultWhatsapp) {
|
||||
if (!defaultWhatsapp) {
|
||||
|
||||
if(userId){
|
||||
|
||||
let whatsapps = await wbotByUserQueue(userId)
|
||||
|
||||
if(whatsapps.length > 0){
|
||||
|
||||
defaultWhatsapp = whatsapps[0]
|
||||
if (userId) {
|
||||
|
||||
let whatsapps = await wbotByUserQueue(userId)
|
||||
|
||||
if (whatsapps.length > 0) {
|
||||
|
||||
if (whatsapps.length > 1) {
|
||||
|
||||
defaultWhatsapp = whatsapps[+WhatsIndex(whatsapps)]
|
||||
|
||||
}
|
||||
else {
|
||||
defaultWhatsapp = whatsapps[0]
|
||||
}
|
||||
|
||||
}// Quando o usuário não está em nenhuma fila
|
||||
else{
|
||||
defaultWhatsapp = await Whatsapp.findOne({ where: { status: 'CONNECTED' } });
|
||||
else {
|
||||
defaultWhatsapp = await Whatsapp.findOne({ where: { status: 'CONNECTED' } });
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
|
||||
defaultWhatsapp = await Whatsapp.findOne({ where: { status: 'CONNECTED' } });
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
defaultWhatsapp = await Whatsapp.findOne({ where: { status: 'CONNECTED' } });
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -49,7 +61,7 @@ const GetDefaultWhatsApp = async (userId?: string | number ): Promise<Whatsapp>
|
|||
|
||||
|
||||
|
||||
// const defaultWhatsapp = await Whatsapp.findOne({
|
||||
// const defaultWhatsapp = await Whatsapp.findOne({
|
||||
// where: { isDefault: true }
|
||||
// });
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
export const isPositiveInteger = (index: string ) => {
|
||||
|
||||
if (typeof index !== 'string') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const num = Number(index);
|
||||
|
||||
if (Number.isInteger(num) && num >= 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
const fsPromises = require("fs/promises");
|
||||
const fs = require('fs')
|
||||
|
||||
import WhatsQueueIndex from "./WhatsQueueIndex";
|
||||
|
||||
// Delete a directory and its children
|
||||
export const WhatsIndex = (whatsapps: Object[]) => {
|
||||
|
||||
let index: number = 0
|
||||
|
||||
if (WhatsQueueIndex.getIndex() >= whatsapps.length) {
|
||||
WhatsQueueIndex.setIndex(0)
|
||||
}
|
||||
|
||||
// console.log('WhatsQueueIndex.getIndex(): ', WhatsQueueIndex.getIndex())
|
||||
|
||||
index = +WhatsQueueIndex.getIndex()
|
||||
|
||||
WhatsQueueIndex.setIndex(+WhatsQueueIndex.getIndex() + 1)
|
||||
|
||||
console.log('WhatsQueue Index: ', index)
|
||||
|
||||
return index
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
import path from "path";
|
||||
import { number } from "yup";
|
||||
import { removeWbot } from "../libs/wbot";
|
||||
import Whatsapp from "../models/Whatsapp";
|
||||
import { StartWhatsAppSession } from "../services/WbotServices/StartWhatsAppSession";
|
||||
import { copyFolder } from "./CopyFolder";
|
||||
import { removeDir } from "./DeleteDirectory";
|
||||
|
||||
const fsPromises = require("fs/promises");
|
||||
const fs = require('fs')
|
||||
|
||||
// Restart session
|
||||
export const restartWhatsSession = async (whatsapp: Whatsapp) => {
|
||||
|
||||
console.log('RESTARTING THE whatsapp.id: ', whatsapp.id)
|
||||
|
||||
const sourcePath = path.join(__dirname, `../../.wwebjs_auth/sessions/`, `session-bd_${whatsapp.id}`)
|
||||
const destPath = path.join(__dirname, `../../.wwebjs_auth/`, `session-bd_${whatsapp.id}`)
|
||||
|
||||
console.log('================sourcePath: ', sourcePath)
|
||||
console.log('================destPath: ', destPath)
|
||||
|
||||
removeWbot(whatsapp.id)
|
||||
|
||||
await removeDir(destPath)
|
||||
|
||||
if (fs.existsSync(sourcePath)) {
|
||||
// copy the good session for restars the new session
|
||||
copyFolder(sourcePath, destPath)
|
||||
}
|
||||
else {
|
||||
console.log('Directory not found to copy: ', sourcePath)
|
||||
}
|
||||
|
||||
console.log('RESTARTING SESSION...')
|
||||
|
||||
await StartWhatsAppSession(whatsapp);
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
|
||||
class WhatsQueueIndex {
|
||||
|
||||
static staticIndex:Number = 0;
|
||||
|
||||
static setIndex(index:Number){
|
||||
this.staticIndex = index
|
||||
}
|
||||
|
||||
static getIndex(){
|
||||
return this.staticIndex
|
||||
}
|
||||
}
|
||||
|
||||
export default WhatsQueueIndex;
|
|
@ -1,5 +1,5 @@
|
|||
import qrCode from "qrcode-terminal";
|
||||
import { Client, LocalAuth } from "whatsapp-web.js";
|
||||
import { Client, LocalAuth } from "whatsapp-web.js";
|
||||
import { getIO } from "./socket";
|
||||
import Whatsapp from "../models/Whatsapp";
|
||||
import AppError from "../errors/AppError";
|
||||
|
@ -7,12 +7,21 @@ import { logger } from "../utils/logger";
|
|||
import { handleMessage } from "../services/WbotServices/wbotMessageListener";
|
||||
const fs = require('fs')
|
||||
|
||||
import { copyFolder } from "../helpers/CopyFolder";
|
||||
import path from "path";
|
||||
import { number } from "yup";
|
||||
|
||||
interface Session extends Client {
|
||||
id?: number;
|
||||
}
|
||||
|
||||
const sessions: Session[] = [];
|
||||
|
||||
let backupSession: any[] = []
|
||||
|
||||
|
||||
|
||||
|
||||
const syncUnreadMessages = async (wbot: Session) => {
|
||||
const chats = await wbot.getChats();
|
||||
|
||||
|
@ -38,7 +47,7 @@ export const initWbot = async (whatsapp: Whatsapp): Promise<Session> => {
|
|||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
|
||||
|
||||
|
||||
const io = getIO();
|
||||
const sessionName = whatsapp.name;
|
||||
let sessionCfg;
|
||||
|
@ -47,9 +56,10 @@ export const initWbot = async (whatsapp: Whatsapp): Promise<Session> => {
|
|||
sessionCfg = JSON.parse(whatsapp.session);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//NOVA OPÇÃO MD
|
||||
const wbot: Session = new Client({session: sessionCfg, authStrategy: new LocalAuth({clientId: 'bd_'+whatsapp.id}),
|
||||
const wbot: Session = new Client({
|
||||
session: sessionCfg, authStrategy: new LocalAuth({ clientId: 'bd_' + whatsapp.id }),
|
||||
puppeteer: { args: ['--no-sandbox', '--disable-setuid-sandbox'], executablePath: process.env.CHROME_BIN || undefined },
|
||||
});
|
||||
|
||||
|
@ -75,7 +85,12 @@ export const initWbot = async (whatsapp: Whatsapp): Promise<Session> => {
|
|||
|
||||
wbot.on("qr", async qr => {
|
||||
|
||||
console.log('************** whatsapp.id: ',whatsapp.id)
|
||||
|
||||
if (!backupSession.includes(whatsapp.id)) {
|
||||
backupSession.push(whatsapp.id)
|
||||
}
|
||||
|
||||
console.log('************** QRCODE whatsapp.id: ', whatsapp.id, ' | backupSession: ', backupSession)
|
||||
|
||||
logger.info("Session:", sessionName);
|
||||
qrCode.generate(qr, { small: true });
|
||||
|
@ -95,9 +110,7 @@ export const initWbot = async (whatsapp: Whatsapp): Promise<Session> => {
|
|||
|
||||
wbot.on("authenticated", async session => {
|
||||
logger.info(`Session: ${sessionName} AUTHENTICATED`);
|
||||
await whatsapp.update({
|
||||
session: JSON.stringify(session)
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
wbot.on("auth_failure", async msg => {
|
||||
|
@ -141,6 +154,7 @@ export const initWbot = async (whatsapp: Whatsapp): Promise<Session> => {
|
|||
|
||||
const sessionIndex = sessions.findIndex(s => s.id === whatsapp.id);
|
||||
if (sessionIndex === -1) {
|
||||
console.log('WBOT ADD ID: ', whatsapp.id)
|
||||
wbot.id = whatsapp.id;
|
||||
sessions.push(wbot);
|
||||
}
|
||||
|
@ -149,6 +163,44 @@ export const initWbot = async (whatsapp: Whatsapp): Promise<Session> => {
|
|||
await syncUnreadMessages(wbot);
|
||||
|
||||
resolve(wbot);
|
||||
|
||||
|
||||
|
||||
|
||||
console.log(`>>>>>>>>>>>>>>>>>>>>>>>>>.. BACKUP SESSION whatsapp.id ${whatsapp.id} | backupSession: ${backupSession}`)
|
||||
|
||||
const whatsIndex = backupSession.findIndex((id:number) => id === +whatsapp.id);
|
||||
|
||||
console.log(' whatsIndex: ', whatsIndex)
|
||||
|
||||
if (whatsIndex !== -1) {
|
||||
|
||||
backupSession.splice(whatsIndex, 1);
|
||||
|
||||
setTimeout(async () => {
|
||||
|
||||
const sourcePath = path.join(__dirname, `../../.wwebjs_auth/`, `session-bd_${whatsapp.id}`)
|
||||
const destPath = path.join(__dirname, `../../.wwebjs_auth/sessions`, `session-bd_${whatsapp.id}`)
|
||||
|
||||
if (fs.existsSync(path.join(__dirname, `../../.wwebjs_auth/sessions`))) {
|
||||
// copy the good session for backup dir
|
||||
copyFolder(sourcePath, destPath)
|
||||
}
|
||||
else {
|
||||
console.log('Directory not found to copy: ', destPath)
|
||||
}
|
||||
|
||||
console.log(` COPIOU backup whatsapp.id ---------------------------------->${whatsapp.id}`)
|
||||
|
||||
|
||||
}, 30000);
|
||||
|
||||
console.log(' PASSOU NO TIMEOUT!')
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
} catch (err) {
|
||||
logger.error(`${err}`);
|
||||
|
@ -169,6 +221,7 @@ export const removeWbot = (whatsappId: number): void => {
|
|||
try {
|
||||
const sessionIndex = sessions.findIndex(s => s.id === whatsappId);
|
||||
if (sessionIndex !== -1) {
|
||||
console.log('WBOT REMOVED ID: ', whatsappId)
|
||||
sessions[sessionIndex].destroy();
|
||||
sessions.splice(sessionIndex, 1);
|
||||
}
|
||||
|
|
|
@ -25,4 +25,10 @@ whatsappSessionRoutes.delete(
|
|||
WhatsAppSessionController.remove
|
||||
);
|
||||
|
||||
whatsappSessionRoutes.post(
|
||||
"/restartwhatsappsession/:whatsappId",
|
||||
isAuth,
|
||||
WhatsAppSessionController.restart
|
||||
);
|
||||
|
||||
export default whatsappSessionRoutes;
|
||||
|
|
|
@ -70,15 +70,15 @@ const ListTicketsService = async ({
|
|||
status
|
||||
};
|
||||
|
||||
if (unlimited) {
|
||||
whereCondition = {
|
||||
...whereCondition,
|
||||
createdAt: {
|
||||
[Op.gte]: dateToday.fullDate + ' 00:00:00.000000',
|
||||
[Op.lte]: dateToday.fullDate + ' 23:59:59.999999'
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (unlimited) {
|
||||
// whereCondition = {
|
||||
// ...whereCondition,
|
||||
// createdAt: {
|
||||
// [Op.gte]: dateToday.fullDate + ' 00:00:00.000000',
|
||||
// [Op.lte]: dateToday.fullDate + ' 23:59:59.999999'
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -8,8 +8,9 @@ import Ticket from "../../models/Ticket";
|
|||
|
||||
import ShowWhatsAppService from "../WhatsappService/ShowWhatsAppService";
|
||||
import wbotByUserQueue from '../../helpers/GetWbotByUserQueue'
|
||||
|
||||
|
||||
|
||||
import { WhatsIndex } from "../../helpers/LoadBalanceWhatsSameQueue";
|
||||
|
||||
|
||||
interface Request {
|
||||
body: string;
|
||||
|
@ -28,25 +29,34 @@ const SendWhatsAppMessage = async ({
|
|||
quotedMsgSerializedId = SerializeWbotMsgId(ticket, quotedMsg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
const whatsapp = await ShowWhatsAppService(ticket.whatsappId);
|
||||
|
||||
if(whatsapp.status!='CONNECTED'){
|
||||
if (whatsapp.status != 'CONNECTED') {
|
||||
|
||||
let whatsapps = await wbotByUserQueue(ticket.userId)
|
||||
let whatsapps = await wbotByUserQueue(ticket.userId)
|
||||
|
||||
if(whatsapps.length > 0){
|
||||
if (whatsapps.length > 0) {
|
||||
|
||||
await ticket.update({ whatsappId: whatsapps[0].id });
|
||||
if (whatsapps.length > 1) {
|
||||
|
||||
await ticket.update({ whatsappId: whatsapps[+WhatsIndex(whatsapps)].id });
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
await ticket.update({ whatsappId: whatsapps[0].id });
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
const wbot = await GetTicketWbot(ticket);
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
const sentMessage = await wbot.sendMessage(
|
||||
|
|
|
@ -5,10 +5,8 @@ import { getIO } from "../../libs/socket";
|
|||
import wbotMonitor from "./wbotMonitor";
|
||||
import { logger } from "../../utils/logger";
|
||||
|
||||
export const StartWhatsAppSession = async (
|
||||
whatsapp: Whatsapp
|
||||
): Promise<void> => {
|
||||
await whatsapp.update({ status: "OPENING" });
|
||||
export const StartWhatsAppSession = async (whatsapp: Whatsapp): Promise<void> => {
|
||||
await whatsapp.update({ status: "OPENING" });
|
||||
|
||||
const io = getIO();
|
||||
io.emit("whatsappSession", {
|
||||
|
@ -20,9 +18,9 @@ export const StartWhatsAppSession = async (
|
|||
const wbot = await initWbot(whatsapp);
|
||||
wbotMessageListener(wbot);
|
||||
wbotMonitor(wbot, whatsapp);
|
||||
} catch (err) {
|
||||
|
||||
} catch (err) {
|
||||
|
||||
logger.error(`${err}`);
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
|
|
@ -3,6 +3,10 @@ import { promisify } from "util";
|
|||
import { writeFile } from "fs";
|
||||
import * as Sentry from "@sentry/node";
|
||||
|
||||
import { copyFolder } from "../../helpers/CopyFolder";
|
||||
import { removeDir } from "../../helpers/DeleteDirectory";
|
||||
import path from 'path';
|
||||
|
||||
import {
|
||||
Contact as WbotContact,
|
||||
Message as WbotMessage,
|
||||
|
@ -29,7 +33,11 @@ import ShowTicketMessage from "../TicketServices/ShowTicketMessage"
|
|||
import BotIsOnQueue from "../../helpers/BotIsOnQueue"
|
||||
import Queue from "../../models/Queue";
|
||||
|
||||
import fs from 'fs';
|
||||
import fs from 'fs';
|
||||
|
||||
import { StartWhatsAppSession } from "../../services/WbotServices/StartWhatsAppSession";
|
||||
import { removeWbot } from '../../libs/wbot'
|
||||
import { restartWhatsSession } from "../../helpers/RestartWhatsSession";
|
||||
|
||||
// test del
|
||||
import data_ura from './ura'
|
||||
|
@ -732,10 +740,33 @@ const handleMessage = async (
|
|||
}
|
||||
//
|
||||
|
||||
|
||||
|
||||
// test del
|
||||
// console.log('WBOT.id: ',wbot.id)
|
||||
|
||||
// const sourcePath = path.join(__dirname,`../../../.wwebjs_auth/sessions/`, `session-bd_${wbot.id}`)
|
||||
// const destPath = path.join(__dirname,`../../../.wwebjs_auth/`, `session-bd_${wbot.id}`)
|
||||
|
||||
// console.log('================sourcePath: ', sourcePath)
|
||||
// console.log('================sourcePath: ', destPath)
|
||||
|
||||
// removeWbot(33)
|
||||
|
||||
// await removeDir(destPath)
|
||||
|
||||
// copyFolder(sourcePath, destPath)
|
||||
|
||||
// await StartWhatsAppSession(whatsapp);
|
||||
|
||||
// console.log('RESTARTING SESSION...')
|
||||
//
|
||||
|
||||
|
||||
} catch (err) {
|
||||
Sentry.captureException(err);
|
||||
logger.error(`Error handling whatsapp message: Err: ${err}`);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -112,6 +112,8 @@ const Connections = () => {
|
|||
const [confirmModalOpen, setConfirmModalOpen] = useState(false);
|
||||
|
||||
|
||||
|
||||
|
||||
const confirmationModalInitialState = {
|
||||
action: "",
|
||||
title: "",
|
||||
|
@ -131,6 +133,16 @@ const Connections = () => {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
const handleRestartWhatsAppSession = async whatsAppId => {
|
||||
try {
|
||||
await api.post(`/restartwhatsappsession/${whatsAppId}`);
|
||||
} catch (err) {
|
||||
toastError(err);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const handleRequestNewQrCode = async whatsAppId => {
|
||||
try {
|
||||
await api.put(`/whatsappsession/${whatsAppId}`);
|
||||
|
@ -319,6 +331,7 @@ const Connections = () => {
|
|||
perform="connections-view:show"
|
||||
yes={() => (
|
||||
<MainContainer>
|
||||
|
||||
<ConfirmationModal
|
||||
title={confirmModalInfo.title}
|
||||
open={confirmModalOpen}
|
||||
|
@ -327,21 +340,23 @@ const Connections = () => {
|
|||
>
|
||||
{confirmModalInfo.message}
|
||||
</ConfirmationModal>
|
||||
|
||||
|
||||
<QrcodeModal
|
||||
open={qrModalOpen}
|
||||
onClose={handleCloseQrModal}
|
||||
whatsAppId={!whatsAppModalOpen && selectedWhatsApp?.id}
|
||||
/>
|
||||
|
||||
<WhatsAppModal
|
||||
open={whatsAppModalOpen}
|
||||
onClose={handleCloseWhatsAppModal}
|
||||
whatsAppId={!qrModalOpen && selectedWhatsApp?.id}
|
||||
/>
|
||||
|
||||
<MainHeader>
|
||||
<Title>{i18n.t("connections.title")}</Title>
|
||||
<MainHeaderButtonsWrapper>
|
||||
|
||||
|
||||
<Can
|
||||
role={user.profile}
|
||||
perform="btn-add-whatsapp"
|
||||
|
@ -354,23 +369,23 @@ const Connections = () => {
|
|||
</Button>
|
||||
)}
|
||||
/>
|
||||
|
||||
|
||||
|
||||
</MainHeaderButtonsWrapper>
|
||||
</MainHeader>
|
||||
|
||||
|
||||
<Paper className={classes.mainPaper} variant="outlined">
|
||||
<Table size="small">
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
|
||||
<TableCell align="center">
|
||||
{i18n.t("connections.table.name")}
|
||||
</TableCell>
|
||||
|
||||
<TableCell align="center">
|
||||
{i18n.t("connections.table.status")}
|
||||
</TableCell>
|
||||
|
||||
|
||||
<Can
|
||||
role={user.profile}
|
||||
perform="connection-button:show"
|
||||
|
@ -383,6 +398,20 @@ const Connections = () => {
|
|||
|
||||
|
||||
|
||||
|
||||
<Can
|
||||
role={user.profile}
|
||||
perform="connection-button:show"
|
||||
yes={() => (
|
||||
<TableCell align="center">
|
||||
Restart
|
||||
</TableCell>
|
||||
)}
|
||||
/>
|
||||
|
||||
|
||||
|
||||
|
||||
<TableCell align="center">
|
||||
{i18n.t("connections.table.lastUpdate")}
|
||||
</TableCell>
|
||||
|
@ -403,6 +432,7 @@ const Connections = () => {
|
|||
whatsApps.map(whatsApp => (
|
||||
<TableRow key={whatsApp.id}>
|
||||
<TableCell align="center">{whatsApp.name}</TableCell>
|
||||
|
||||
<TableCell align="center">
|
||||
{renderStatusToolTips(whatsApp)}
|
||||
</TableCell>
|
||||
|
@ -419,9 +449,38 @@ const Connections = () => {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<Can
|
||||
role={user.profile}
|
||||
perform="connection-button:show"
|
||||
yes={() => (
|
||||
<TableCell align="center">
|
||||
|
||||
<Button
|
||||
size="small"
|
||||
variant="contained"
|
||||
color="primary"
|
||||
onClick={() => handleRestartWhatsAppSession(whatsApp.id)}
|
||||
|
||||
>
|
||||
Restart
|
||||
</Button>
|
||||
|
||||
</TableCell>
|
||||
)}
|
||||
/>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<TableCell align="center">
|
||||
{format(parseISO(whatsApp.updatedAt), "dd/MM/yy HH:mm")}
|
||||
</TableCell>
|
||||
|
||||
|
||||
<TableCell align="center">
|
||||
{whatsApp.isDefault && (
|
||||
<div className={classes.customTableCell}>
|
||||
|
@ -429,6 +488,8 @@ const Connections = () => {
|
|||
</div>
|
||||
)}
|
||||
</TableCell>
|
||||
|
||||
|
||||
<TableCell align="center">
|
||||
|
||||
<Can
|
||||
|
@ -442,7 +503,7 @@ const Connections = () => {
|
|||
<Edit />
|
||||
</IconButton>
|
||||
)}
|
||||
/>
|
||||
/>
|
||||
|
||||
|
||||
<Can
|
||||
|
|
Loading…
Reference in New Issue