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,13 +1,13 @@
|
||||||
|
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;
|
||||||
|
@ -15,32 +15,43 @@ interface Request {
|
||||||
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) {
|
if (userId) {
|
||||||
// CONSULTANDO FILAS PELO ID DO USUARIO
|
// CONSULTANDO FILAS PELO ID DO USUARIO
|
||||||
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
|
tickets = await sequelize.query(
|
||||||
t.userId = user.id and user.name = 'botqueue' and t.status='${status}' and (TIMESTAMPDIFF(SECOND, t.updatedAt, '${currentDate}')) >= ${timeseconds};`, { type: QueryTypes.SELECT });
|
`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};`,
|
||||||
|
{ type: QueryTypes.SELECT }
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
|
const botInfo = await BotIsOnQueue("botqueue");
|
||||||
|
|
||||||
|
if (botInfo.isOnQueue) {
|
||||||
// CONSULTANDO FILAS PELO USUARIO
|
// CONSULTANDO FILAS PELO USUARIO
|
||||||
tickets = await sequelize.query(`select id as ticket_id from Tickets where status='${status}' and
|
tickets = await sequelize.query(
|
||||||
(TIMESTAMPDIFF(SECOND, updatedAt, '${currentDate}')) >= ${timeseconds};`, { type: QueryTypes.SELECT });
|
`select id as ticket_id from Tickets where status='${status}' and userId != ${botInfo.userIdBot} and (TIMESTAMPDIFF(SECOND, updatedAt, '${currentDate}')) >= ${timeseconds};`,
|
||||||
|
{ type: QueryTypes.SELECT }
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// CONSULTANDO FILAS PELO USUARIO
|
||||||
|
tickets = await sequelize.query(
|
||||||
|
`select id as ticket_id from Tickets where status='${status}' and (TIMESTAMPDIFF(SECOND, updatedAt, '${currentDate}')) >= ${timeseconds};`,
|
||||||
|
{ type: QueryTypes.SELECT }
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return tickets;
|
return tickets;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ListTicketTimeLife;
|
export default ListTicketTimeLife;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ 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,
|
||||||
|
@ -922,7 +922,6 @@ 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({
|
const ticketExpiration = await SettingTicket.findOne({
|
||||||
where: { key: "ticketExpiration" }
|
where: { key: "ticketExpiration" }
|
||||||
});
|
});
|
||||||
|
@ -936,7 +935,6 @@ const handleMessage = async (msg: any, wbot: any): Promise<void> => {
|
||||||
return;
|
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])))
|
||||||
|
|
||||||
// messages sent automatically by wbot have a special character in front of it
|
// messages sent automatically by wbot have a special character in front of it
|
||||||
|
@ -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