feat: Automatically return remote/campaign tickets to awaiting when agent does not send campaign message
parent
8eb2156845
commit
96a7e23ee6
|
@ -303,7 +303,8 @@ export const remoteTicketCreation = async (
|
|||
id: ticket.id,
|
||||
createdAt: ticket.createdAt,
|
||||
updatedAt: ticket.updatedAt,
|
||||
whatsappId: ticket.whatsappId
|
||||
whatsappId: ticket.whatsappId,
|
||||
status: ticket.status
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -624,6 +625,26 @@ export const update = async (
|
|||
await setMessageAsRead(ticket);
|
||||
}
|
||||
|
||||
if (ticketData.status == "open" || ticketData.status == "pending") {
|
||||
let ticketRemote = await get({
|
||||
key: `remote:ticketId:${ticketId}`
|
||||
});
|
||||
|
||||
if (ticketRemote) {
|
||||
ticketRemote = JSON.parse(ticketRemote);
|
||||
|
||||
ticketRemote = {
|
||||
...ticketRemote,
|
||||
...{
|
||||
status: ticketData.status == "open" ? "open" : "pending",
|
||||
updatedAt: ticket.updatedAt
|
||||
}
|
||||
};
|
||||
|
||||
set(`remote:ticketId:${ticketId}`, JSON.stringify(ticketRemote));
|
||||
}
|
||||
}
|
||||
|
||||
if (ticketData.userId) {
|
||||
const dateToday = splitDateTime(
|
||||
new Date(format(new Date(), "yyyy-MM-dd HH:mm:ss", { locale: ptBR }))
|
||||
|
|
|
@ -2,6 +2,7 @@ import { intervalToDuration } from "date-fns";
|
|||
import { del, get, set } from "./RedisClient";
|
||||
import { getIO } from "../libs/socket";
|
||||
import controllByNumber from "./controllByNumber";
|
||||
import UpdateTicketService from "../services/TicketServices/UpdateTicketService";
|
||||
|
||||
let timer: any;
|
||||
|
||||
|
@ -11,6 +12,64 @@ const AutoRemoteTickets = async () => {
|
|||
|
||||
if (!obj?.tickets) return;
|
||||
|
||||
// console.log("remote tickets: ", obj?.tickets);
|
||||
|
||||
for (const ticket of obj.tickets) {
|
||||
if (!ticket.includes("open") || ticket.includes("messageDateTime"))
|
||||
continue;
|
||||
|
||||
const regex = /"updatedAt":"([^"]+)"/;
|
||||
let match = ticket.match(regex);
|
||||
|
||||
const updatedAt = match ? match[1] : null;
|
||||
|
||||
console.log("updatedAt: ", updatedAt);
|
||||
|
||||
let timeDiff: any = intervalToDuration({
|
||||
start: new Date(updatedAt),
|
||||
end: new Date()
|
||||
});
|
||||
|
||||
console.log("----------> idle time timeDiff: ", timeDiff);
|
||||
|
||||
if (timeDiff.minutes > 2) {
|
||||
match = ticket.match(/"id":(\d+)/);
|
||||
let ticketId = match ? match[1] : null;
|
||||
console.log("ticketId: ", ticketId);
|
||||
|
||||
ticketId = JSON.parse(ticketId);
|
||||
|
||||
let ticketRemote = await get({
|
||||
key: `remote:ticketId:${ticketId}`
|
||||
});
|
||||
|
||||
if (ticketRemote) {
|
||||
ticketRemote = JSON.parse(ticketRemote);
|
||||
|
||||
ticketRemote = {
|
||||
...ticketRemote,
|
||||
...{ status: "pending" }
|
||||
};
|
||||
|
||||
set(`remote:ticketId:${ticketId}`, JSON.stringify(ticketRemote));
|
||||
|
||||
await UpdateTicketService({
|
||||
ticketData: {
|
||||
status: "pending",
|
||||
userId: null
|
||||
},
|
||||
ticketId
|
||||
});
|
||||
|
||||
const io = getIO();
|
||||
io.emit("remoteTickesControllIdleOpen", {
|
||||
action: "update",
|
||||
ticketId
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const ticket of obj.tickets) {
|
||||
if (!ticket.includes("messageDateTime")) continue;
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ var flatten = require("flat");
|
|||
|
||||
interface TicketData {
|
||||
status?: string;
|
||||
userId?: number;
|
||||
userId?: number | null;
|
||||
queueId?: number;
|
||||
statusChatEnd?: string;
|
||||
statusChatEndId?: number;
|
||||
|
|
|
@ -158,6 +158,25 @@ const Ticket = () => {
|
|||
}
|
||||
})
|
||||
|
||||
socket.on("remoteTickesControllIdleOpen", (data) => {
|
||||
if (data.action === "update") {
|
||||
let url_ticketId
|
||||
try {
|
||||
|
||||
let url_split = window.location.href.split('tickets')
|
||||
|
||||
url_ticketId = url_split[url_split.length - 1].match(/\d+/)[0]
|
||||
|
||||
if (url_ticketId && +url_ticketId === data.ticketId) {
|
||||
history.push("/tickets")
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.log('error on try do the send seen: ', error)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return () => {
|
||||
socket.disconnect()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue