Codificação para quando houver mais de uma fila na conexão. O atendente só vai interagir com o usuário quando o mesmo escolher uma fila
parent
ab7464f776
commit
02b36b6bf7
|
@ -0,0 +1,24 @@
|
||||||
|
const fsPromises = require("fs/promises");
|
||||||
|
const fs = require('fs')
|
||||||
|
|
||||||
|
import ShowWhatsAppService from "../services/WhatsappService/ShowWhatsAppService";
|
||||||
|
|
||||||
|
import { Client } from "whatsapp-web.js";
|
||||||
|
|
||||||
|
interface Session extends Client { id?: number;}
|
||||||
|
|
||||||
|
const _queuesOutBot =async (wbot:Session, botId: string | number) => {
|
||||||
|
|
||||||
|
const { queues, greetingMessage } = await ShowWhatsAppService(wbot.id!);
|
||||||
|
|
||||||
|
const indexQueue = queues.findIndex((q) => q.id == botId)
|
||||||
|
|
||||||
|
if(indexQueue != -1){
|
||||||
|
queues.splice(indexQueue, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return {queues, greetingMessage}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default _queuesOutBot;
|
|
@ -41,6 +41,15 @@ const CreateMessageService = async ({messageData}: Request): Promise<Message> =>
|
||||||
|
|
||||||
//console.log('SERVER SIDE MESSAGE: ', message)
|
//console.log('SERVER SIDE MESSAGE: ', message)
|
||||||
|
|
||||||
|
// console.log('>>>>>>>>>>>>>>>>>>>>>> TICKET STATUS: ',message.ticket.status)
|
||||||
|
|
||||||
|
//test del
|
||||||
|
// const ticketInfo = await Ticket.findByPk(message.ticket.id)
|
||||||
|
// console.log('&&&&&&&&&&&&&&&&& TICKET INFO queueId: ', ticketInfo?.queueId)
|
||||||
|
//
|
||||||
|
|
||||||
|
if(message.ticket.status!='queueChoice'){
|
||||||
|
|
||||||
const io = getIO();
|
const io = getIO();
|
||||||
io.to(message.ticketId.toString())
|
io.to(message.ticketId.toString())
|
||||||
.to(message.ticket.status)
|
.to(message.ticket.status)
|
||||||
|
@ -52,6 +61,9 @@ const CreateMessageService = async ({messageData}: Request): Promise<Message> =>
|
||||||
contact: message.ticket.contact
|
contact: message.ticket.contact
|
||||||
});
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return message;
|
return message;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
import { subHours, subMinutes, subSeconds } from "date-fns";
|
import { subHours, subMinutes, subSeconds } from "date-fns";
|
||||||
import { Op } from "sequelize";
|
import { Op } from "sequelize";
|
||||||
|
import BotIsOnQueue from "../../helpers/BotIsOnQueue";
|
||||||
import Contact from "../../models/Contact";
|
import Contact from "../../models/Contact";
|
||||||
import Ticket from "../../models/Ticket";
|
import Ticket from "../../models/Ticket";
|
||||||
|
import ShowWhatsAppService from "../WhatsappService/ShowWhatsAppService";
|
||||||
import ShowTicketService from "./ShowTicketService";
|
import ShowTicketService from "./ShowTicketService";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const FindOrCreateTicketService = async (
|
const FindOrCreateTicketService = async (
|
||||||
contact: Contact,
|
contact: Contact,
|
||||||
whatsappId: number,
|
whatsappId: number,
|
||||||
|
@ -15,12 +18,20 @@ const FindOrCreateTicketService = async (
|
||||||
let ticket = await Ticket.findOne({
|
let ticket = await Ticket.findOne({
|
||||||
where: {
|
where: {
|
||||||
status: {
|
status: {
|
||||||
[Op.or]: ["open", "pending"]
|
[Op.or]: ["open", "pending", "queueChoice"]
|
||||||
},
|
},
|
||||||
contactId: groupContact ? groupContact.id : contact.id
|
contactId: groupContact ? groupContact.id : contact.id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const { queues, greetingMessage } = await ShowWhatsAppService(whatsappId);
|
||||||
|
|
||||||
|
const botInfo = await BotIsOnQueue('botqueue')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (ticket) {
|
if (ticket) {
|
||||||
await ticket.update({ unreadMessages });
|
await ticket.update({ unreadMessages });
|
||||||
}
|
}
|
||||||
|
@ -33,7 +44,10 @@ const FindOrCreateTicketService = async (
|
||||||
order: [["updatedAt", "DESC"]]
|
order: [["updatedAt", "DESC"]]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (ticket) {
|
if (ticket) {
|
||||||
|
|
||||||
await ticket.update({
|
await ticket.update({
|
||||||
status: "pending",
|
status: "pending",
|
||||||
userId: null,
|
userId: null,
|
||||||
|
@ -61,6 +75,7 @@ const FindOrCreateTicketService = async (
|
||||||
});
|
});
|
||||||
|
|
||||||
if (ticket) {
|
if (ticket) {
|
||||||
|
|
||||||
await ticket.update({
|
await ticket.update({
|
||||||
status: "pending",
|
status: "pending",
|
||||||
userId: null,
|
userId: null,
|
||||||
|
@ -71,9 +86,15 @@ const FindOrCreateTicketService = async (
|
||||||
|
|
||||||
if (!ticket) {
|
if (!ticket) {
|
||||||
|
|
||||||
|
let status = "pending"
|
||||||
|
|
||||||
|
if(queues.length > 1 && !botInfo.isOnQueue){
|
||||||
|
status = "queueChoice"
|
||||||
|
}
|
||||||
|
|
||||||
ticket = await Ticket.create({
|
ticket = await Ticket.create({
|
||||||
contactId: groupContact ? groupContact.id : contact.id,
|
contactId: groupContact ? groupContact.id : contact.id,
|
||||||
status: "pending",
|
status: status,
|
||||||
isGroup: !!groupContact,
|
isGroup: !!groupContact,
|
||||||
unreadMessages,
|
unreadMessages,
|
||||||
whatsappId
|
whatsappId
|
||||||
|
|
|
@ -201,6 +201,14 @@ const verifyQueue = async (
|
||||||
|
|
||||||
if (choosenQueue) {
|
if (choosenQueue) {
|
||||||
|
|
||||||
|
// Atualizando o status do ticket para mostrar notificação para o atendente da fila escolhida pelo usuário. De queueChoice para pending
|
||||||
|
if(queues.length > 1 && !botInfo.isOnQueue){
|
||||||
|
|
||||||
|
await ticket.update({status: "pending" });
|
||||||
|
|
||||||
|
}
|
||||||
|
//
|
||||||
|
|
||||||
await UpdateTicketService({
|
await UpdateTicketService({
|
||||||
ticketData: { queueId: choosenQueue.id },
|
ticketData: { queueId: choosenQueue.id },
|
||||||
ticketId: ticket.id
|
ticketId: ticket.id
|
||||||
|
@ -230,8 +238,6 @@ const verifyQueue = async (
|
||||||
body = `\u200e${choosenQueue.greetingMessage}`;
|
body = `\u200e${choosenQueue.greetingMessage}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// const body = `\u200e${choosenQueue.greetingMessage}`;
|
|
||||||
|
|
||||||
const sentMessage = await wbot.sendMessage(`${contact.number}@c.us`, body);
|
const sentMessage = await wbot.sendMessage(`${contact.number}@c.us`, body);
|
||||||
|
|
||||||
await verifyMessage(sentMessage, ticket, contact);
|
await verifyMessage(sentMessage, ticket, contact);
|
||||||
|
|
|
@ -11,7 +11,7 @@ const ShowWhatsAppService = async (id: string | number): Promise<Whatsapp> => {
|
||||||
attributes: ["id", "name", "color", "greetingMessage"]
|
attributes: ["id", "name", "color", "greetingMessage"]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
order: [["queues", "name", "ASC"]]
|
order: [["queues", "id", "ASC"]]
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!whatsapp) {
|
if (!whatsapp) {
|
||||||
|
|
|
@ -6,13 +6,13 @@ import openSocket from "socket.io-client";
|
||||||
import useSound from "use-sound";
|
import useSound from "use-sound";
|
||||||
|
|
||||||
import Popover from "@material-ui/core/Popover";
|
import Popover from "@material-ui/core/Popover";
|
||||||
import IconButton from "@material-ui/core/IconButton";
|
//import IconButton from "@material-ui/core/IconButton";
|
||||||
import List from "@material-ui/core/List";
|
import List from "@material-ui/core/List";
|
||||||
import ListItem from "@material-ui/core/ListItem";
|
import ListItem from "@material-ui/core/ListItem";
|
||||||
import ListItemText from "@material-ui/core/ListItemText";
|
import ListItemText from "@material-ui/core/ListItemText";
|
||||||
import { makeStyles } from "@material-ui/core/styles";
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
import Badge from "@material-ui/core/Badge";
|
//import Badge from "@material-ui/core/Badge";
|
||||||
import ChatIcon from "@material-ui/icons/Chat";
|
//import ChatIcon from "@material-ui/icons/Chat";
|
||||||
|
|
||||||
import TicketListItem from "../TicketListItem";
|
import TicketListItem from "../TicketListItem";
|
||||||
import { i18n } from "../../translate/i18n";
|
import { i18n } from "../../translate/i18n";
|
||||||
|
@ -113,6 +113,11 @@ const NotificationsPopOver = () => {
|
||||||
!data.message.read &&
|
!data.message.read &&
|
||||||
(data.ticket.userId === user?.id || !data.ticket.userId)
|
(data.ticket.userId === user?.id || !data.ticket.userId)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
console.log(`data.ticket.userId: ${data.ticket.userId }\n
|
||||||
|
data.ticket.status: ${data.ticket.status}\n
|
||||||
|
data.ticket.userId: ${data.ticket.userId }`)
|
||||||
|
|
||||||
setNotifications(prevState => {
|
setNotifications(prevState => {
|
||||||
const ticketIndex = prevState.findIndex(t => t.id === data.ticket.id);
|
const ticketIndex = prevState.findIndex(t => t.id === data.ticket.id);
|
||||||
if (ticketIndex !== -1) {
|
if (ticketIndex !== -1) {
|
||||||
|
@ -126,10 +131,11 @@ const NotificationsPopOver = () => {
|
||||||
(data.message.ticketId === ticketIdRef.current &&
|
(data.message.ticketId === ticketIdRef.current &&
|
||||||
document.visibilityState === "visible") ||
|
document.visibilityState === "visible") ||
|
||||||
(data.ticket.userId && data.ticket.userId !== user?.id) ||
|
(data.ticket.userId && data.ticket.userId !== user?.id) ||
|
||||||
data.ticket.isGroup;
|
data.ticket.isGroup || !data.ticket.userId;
|
||||||
|
|
||||||
if (shouldNotNotificate) return;
|
if (shouldNotNotificate) return;
|
||||||
|
|
||||||
|
|
||||||
handleNotifications(data);
|
handleNotifications(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -174,9 +180,9 @@ const NotificationsPopOver = () => {
|
||||||
soundAlertRef.current();
|
soundAlertRef.current();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClick = () => {
|
// const handleClick = () => {
|
||||||
setIsOpen(prevState => !prevState);
|
// setIsOpen(prevState => !prevState);
|
||||||
};
|
// };
|
||||||
|
|
||||||
const handleClickAway = () => {
|
const handleClickAway = () => {
|
||||||
setIsOpen(false);
|
setIsOpen(false);
|
||||||
|
@ -188,7 +194,7 @@ const NotificationsPopOver = () => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<IconButton
|
{/* <IconButton
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
// buttonRef={anchorEl}
|
// buttonRef={anchorEl}
|
||||||
ref={anchorEl}
|
ref={anchorEl}
|
||||||
|
@ -198,7 +204,7 @@ const NotificationsPopOver = () => {
|
||||||
<Badge badgeContent={notifications.length} color="secondary">
|
<Badge badgeContent={notifications.length} color="secondary">
|
||||||
<ChatIcon />
|
<ChatIcon />
|
||||||
</Badge>
|
</Badge>
|
||||||
</IconButton>
|
</IconButton> */}
|
||||||
<Popover
|
<Popover
|
||||||
disableScrollLock
|
disableScrollLock
|
||||||
open={isOpen}
|
open={isOpen}
|
||||||
|
|
Loading…
Reference in New Issue