Ajustes para fechamentos de tickets automatico do bot
parent
69d99206e9
commit
8dd865281e
|
@ -20,7 +20,6 @@ let timer: any;
|
||||||
|
|
||||||
const AutoCloseTickets = async () => {
|
const AutoCloseTickets = async () => {
|
||||||
try {
|
try {
|
||||||
// const botInfo = await BotIsOnQueue('botqueue')
|
|
||||||
|
|
||||||
// if (!botInfo.userIdBot) return
|
// if (!botInfo.userIdBot) return
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,11 @@ import endPointQuery from "./helpers/old_EndPointQuery";
|
||||||
import { cacheSize, flushCache, loadTicketsCache } from "./helpers/TicketCache";
|
import { cacheSize, flushCache, loadTicketsCache } from "./helpers/TicketCache";
|
||||||
import { loadContactsCache } from "./helpers/ContactsCache";
|
import { loadContactsCache } from "./helpers/ContactsCache";
|
||||||
|
|
||||||
import "./helpers/CloseBotTickets";
|
|
||||||
import { loadSchedulesCache } from "./helpers/SchedulingNotifyCache";
|
import { loadSchedulesCache } from "./helpers/SchedulingNotifyCache";
|
||||||
import { delRestoreControllFile } from "./helpers/RestoreControll";
|
import { delRestoreControllFile } from "./helpers/RestoreControll";
|
||||||
import "./helpers/AutoCloseTickets";
|
import "./helpers/AutoCloseTickets";
|
||||||
|
import "./helpers/CloseBotTickets";
|
||||||
|
|
||||||
import "./helpers/SchedulingNotifySendMessage"
|
import "./helpers/SchedulingNotifySendMessage"
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
|
@ -1,46 +1,57 @@
|
||||||
|
import { Sequelize } from "sequelize";
|
||||||
import { Sequelize, } from "sequelize";
|
|
||||||
|
|
||||||
const dbConfig = require("../../config/database");
|
const dbConfig = require("../../config/database");
|
||||||
const sequelize = new Sequelize(dbConfig);
|
const sequelize = new Sequelize(dbConfig);
|
||||||
const { QueryTypes } = require('sequelize');
|
const { QueryTypes } = require("sequelize");
|
||||||
|
|
||||||
import { splitDateTime } from "../../helpers/SplitDateTime";
|
import { splitDateTime } from "../../helpers/SplitDateTime";
|
||||||
import format from 'date-fns/format';
|
import format from "date-fns/format";
|
||||||
import ptBR from 'date-fns/locale/pt-BR';
|
import ptBR from "date-fns/locale/pt-BR";
|
||||||
|
import BotIsOnQueue from "../../helpers/BotIsOnQueue";
|
||||||
|
|
||||||
interface Request {
|
interface Request {
|
||||||
timeseconds: string | number;
|
timeseconds: string | number;
|
||||||
status: string;
|
status: string;
|
||||||
userId?: string | number;
|
userId?: string | number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ListTicketTimeLife = async ({timeseconds, status, userId }: Request): Promise<any[]> => {
|
const ListTicketTimeLife = async ({
|
||||||
|
timeseconds,
|
||||||
|
status,
|
||||||
|
userId
|
||||||
|
}: Request): Promise<any[]> => {
|
||||||
|
let tickets = [];
|
||||||
|
|
||||||
let tickets = []
|
let currentDate = format(new Date(), "yyyy-MM-dd HH:mm:ss", { locale: ptBR });
|
||||||
|
|
||||||
let currentDate = format(new Date(), 'yyyy-MM-dd HH:mm:ss', { locale: ptBR })
|
// console.log('------------------> currentDate: ', currentDate)
|
||||||
|
|
||||||
// console.log('------------------> currentDate: ', currentDate)
|
if (userId) {
|
||||||
|
// CONSULTANDO FILAS PELO ID DO USUARIO
|
||||||
if (userId) {
|
tickets = await sequelize.query(
|
||||||
// CONSULTANDO FILAS PELO ID DO USUARIO
|
`select user.id as user_id, user.name as user_name, t.id as ticket_id from Tickets as t inner join Users as user on
|
||||||
tickets = await sequelize.query(`select user.id as user_id, user.name as user_name, t.id as ticket_id from Tickets as t inner join Users as user on
|
t.userId = user.id and user.name = 'botqueue' and t.status='${status}' and (TIMESTAMPDIFF(SECOND, t.updatedAt, '${currentDate}')) >= ${timeseconds};`,
|
||||||
t.userId = user.id and user.name = 'botqueue' and t.status='${status}' and (TIMESTAMPDIFF(SECOND, t.updatedAt, '${currentDate}')) >= ${timeseconds};`, { type: QueryTypes.SELECT });
|
{ type: QueryTypes.SELECT }
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
const botInfo = await BotIsOnQueue("botqueue");
|
||||||
|
|
||||||
|
if (botInfo.isOnQueue) {
|
||||||
|
// CONSULTANDO FILAS PELO USUARIO
|
||||||
|
tickets = await sequelize.query(
|
||||||
|
`select id as ticket_id from Tickets where status='${status}' and userId != ${botInfo.userIdBot} and (TIMESTAMPDIFF(SECOND, updatedAt, '${currentDate}')) >= ${timeseconds};`,
|
||||||
|
{ type: QueryTypes.SELECT }
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
|
// CONSULTANDO FILAS PELO USUARIO
|
||||||
// CONSULTANDO FILAS PELO USUARIO
|
tickets = await sequelize.query(
|
||||||
tickets = await sequelize.query(`select id as ticket_id from Tickets where status='${status}' and
|
`select id as ticket_id from Tickets where status='${status}' and (TIMESTAMPDIFF(SECOND, updatedAt, '${currentDate}')) >= ${timeseconds};`,
|
||||||
(TIMESTAMPDIFF(SECOND, updatedAt, '${currentDate}')) >= ${timeseconds};`, { type: QueryTypes.SELECT });
|
{ type: QueryTypes.SELECT }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return tickets;
|
return tickets;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ListTicketTimeLife;
|
export default ListTicketTimeLife;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -81,14 +81,14 @@ import { setMessageAsRead } from "../../helpers/SetMessageAsRead";
|
||||||
import FindOrCreateQueryItemService from "../SLM/FindOrCreateQueryItemService";
|
import FindOrCreateQueryItemService from "../SLM/FindOrCreateQueryItemService";
|
||||||
import ShowQueryItemService from "../SLM/ShowQueryItemService";
|
import ShowQueryItemService from "../SLM/ShowQueryItemService";
|
||||||
import QueryItem from "../../models/QueryItem";
|
import QueryItem from "../../models/QueryItem";
|
||||||
import SettingTicket from "../../models/SettingTicket"
|
import SettingTicket from "../../models/SettingTicket";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
format as _format,
|
format as _format,
|
||||||
isWithinInterval,
|
isWithinInterval,
|
||||||
parse,
|
parse,
|
||||||
subMinutes
|
subMinutes
|
||||||
} from "date-fns";
|
} from "date-fns";
|
||||||
|
|
||||||
var lst: any[] = getWhatsappIds();
|
var lst: any[] = getWhatsappIds();
|
||||||
|
|
||||||
|
@ -922,20 +922,18 @@ const handleMessage = async (msg: any, wbot: any): Promise<void> => {
|
||||||
// let groupContact: Contact | undefined;
|
// let groupContact: Contact | undefined;
|
||||||
|
|
||||||
if (msg.fromMe) {
|
if (msg.fromMe) {
|
||||||
|
const ticketExpiration = await SettingTicket.findOne({
|
||||||
|
where: { key: "ticketExpiration" }
|
||||||
|
});
|
||||||
|
|
||||||
const ticketExpiration = await SettingTicket.findOne({
|
if (
|
||||||
where: { key: "ticketExpiration" }
|
ticketExpiration &&
|
||||||
});
|
ticketExpiration.value == "enabled" &&
|
||||||
|
ticketExpiration?.message.trim() == msg.body.trim()
|
||||||
if (
|
) {
|
||||||
ticketExpiration &&
|
console.log("*********** TICKET EXPIRATION");
|
||||||
ticketExpiration.value == "enabled" &&
|
return;
|
||||||
ticketExpiration?.message.trim() == msg.body.trim()
|
}
|
||||||
) {
|
|
||||||
console.log("*********** TICKET EXPIRATION");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// console.log('FROM ME: ', msg.fromMe, ' | /\u200e/.test(msg.body[0]: ', (/\u200e/.test(msg.body[0])))
|
// console.log('FROM ME: ', msg.fromMe, ' | /\u200e/.test(msg.body[0]: ', (/\u200e/.test(msg.body[0])))
|
||||||
|
|
||||||
|
@ -1235,6 +1233,7 @@ const handleMessage = async (msg: any, wbot: any): Promise<void> => {
|
||||||
if (
|
if (
|
||||||
msg.fromMe &&
|
msg.fromMe &&
|
||||||
businessTime &&
|
businessTime &&
|
||||||
|
businessTime.value == "enabled" &&
|
||||||
!businessTime.isWithinRange &&
|
!businessTime.isWithinRange &&
|
||||||
businessTime.message.trim() == msg.body.trim()
|
businessTime.message.trim() == msg.body.trim()
|
||||||
) {
|
) {
|
||||||
|
@ -1242,7 +1241,12 @@ const handleMessage = async (msg: any, wbot: any): Promise<void> => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!businessTime.isWithinRange && businessTime.message.trim().length > 0) {
|
if (
|
||||||
|
businessTime &&
|
||||||
|
businessTime.value == "enabled" &&
|
||||||
|
!businessTime.isWithinRange &&
|
||||||
|
businessTime.message.trim().length > 0
|
||||||
|
) {
|
||||||
botSendMessage(ticket, businessTime.message);
|
botSendMessage(ticket, businessTime.message);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -1305,7 +1309,10 @@ const handleMessage = async (msg: any, wbot: any): Promise<void> => {
|
||||||
|
|
||||||
console.log("Is the time within the range?", isWithinRange);
|
console.log("Is the time within the range?", isWithinRange);
|
||||||
|
|
||||||
return { isWithinRange, message: outBusinessHours.message };
|
return {
|
||||||
|
isWithinRange,
|
||||||
|
message: outBusinessHours.message
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue