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,16 +41,28 @@ const CreateMessageService = async ({messageData}: Request): Promise<Message> =>
|
|||
|
||||
//console.log('SERVER SIDE MESSAGE: ', message)
|
||||
|
||||
const io = getIO();
|
||||
io.to(message.ticketId.toString())
|
||||
.to(message.ticket.status)
|
||||
.to("notification")
|
||||
.emit("appMessage", {
|
||||
action: "create",
|
||||
message,
|
||||
ticket: message.ticket,
|
||||
contact: message.ticket.contact
|
||||
});
|
||||
// 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();
|
||||
io.to(message.ticketId.toString())
|
||||
.to(message.ticket.status)
|
||||
.to("notification")
|
||||
.emit("appMessage", {
|
||||
action: "create",
|
||||
message,
|
||||
ticket: message.ticket,
|
||||
contact: message.ticket.contact
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
return message;
|
||||
};
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
import { subHours, subMinutes, subSeconds } from "date-fns";
|
||||
import { Op } from "sequelize";
|
||||
import BotIsOnQueue from "../../helpers/BotIsOnQueue";
|
||||
import Contact from "../../models/Contact";
|
||||
import Ticket from "../../models/Ticket";
|
||||
import ShowWhatsAppService from "../WhatsappService/ShowWhatsAppService";
|
||||
import ShowTicketService from "./ShowTicketService";
|
||||
|
||||
|
||||
|
||||
|
||||
const FindOrCreateTicketService = async (
|
||||
contact: Contact,
|
||||
whatsappId: number,
|
||||
|
@ -15,12 +18,20 @@ const FindOrCreateTicketService = async (
|
|||
let ticket = await Ticket.findOne({
|
||||
where: {
|
||||
status: {
|
||||
[Op.or]: ["open", "pending"]
|
||||
[Op.or]: ["open", "pending", "queueChoice"]
|
||||
},
|
||||
contactId: groupContact ? groupContact.id : contact.id
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
const { queues, greetingMessage } = await ShowWhatsAppService(whatsappId);
|
||||
|
||||
const botInfo = await BotIsOnQueue('botqueue')
|
||||
|
||||
|
||||
|
||||
if (ticket) {
|
||||
await ticket.update({ unreadMessages });
|
||||
}
|
||||
|
@ -33,7 +44,10 @@ const FindOrCreateTicketService = async (
|
|||
order: [["updatedAt", "DESC"]]
|
||||
});
|
||||
|
||||
|
||||
|
||||
if (ticket) {
|
||||
|
||||
await ticket.update({
|
||||
status: "pending",
|
||||
userId: null,
|
||||
|
@ -61,6 +75,7 @@ const FindOrCreateTicketService = async (
|
|||
});
|
||||
|
||||
if (ticket) {
|
||||
|
||||
await ticket.update({
|
||||
status: "pending",
|
||||
userId: null,
|
||||
|
@ -71,9 +86,15 @@ const FindOrCreateTicketService = async (
|
|||
|
||||
if (!ticket) {
|
||||
|
||||
let status = "pending"
|
||||
|
||||
if(queues.length > 1 && !botInfo.isOnQueue){
|
||||
status = "queueChoice"
|
||||
}
|
||||
|
||||
ticket = await Ticket.create({
|
||||
contactId: groupContact ? groupContact.id : contact.id,
|
||||
status: "pending",
|
||||
status: status,
|
||||
isGroup: !!groupContact,
|
||||
unreadMessages,
|
||||
whatsappId
|
||||
|
|
|
@ -201,6 +201,14 @@ const verifyQueue = async (
|
|||
|
||||
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({
|
||||
ticketData: { queueId: choosenQueue.id },
|
||||
ticketId: ticket.id
|
||||
|
@ -230,8 +238,6 @@ const verifyQueue = async (
|
|||
body = `\u200e${choosenQueue.greetingMessage}`;
|
||||
}
|
||||
|
||||
// const body = `\u200e${choosenQueue.greetingMessage}`;
|
||||
|
||||
const sentMessage = await wbot.sendMessage(`${contact.number}@c.us`, body);
|
||||
|
||||
await verifyMessage(sentMessage, ticket, contact);
|
||||
|
|
|
@ -11,7 +11,7 @@ const ShowWhatsAppService = async (id: string | number): Promise<Whatsapp> => {
|
|||
attributes: ["id", "name", "color", "greetingMessage"]
|
||||
}
|
||||
],
|
||||
order: [["queues", "name", "ASC"]]
|
||||
order: [["queues", "id", "ASC"]]
|
||||
});
|
||||
|
||||
if (!whatsapp) {
|
||||
|
|
|
@ -6,13 +6,13 @@ import openSocket from "socket.io-client";
|
|||
import useSound from "use-sound";
|
||||
|
||||
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 ListItem from "@material-ui/core/ListItem";
|
||||
import ListItemText from "@material-ui/core/ListItemText";
|
||||
import { makeStyles } from "@material-ui/core/styles";
|
||||
import Badge from "@material-ui/core/Badge";
|
||||
import ChatIcon from "@material-ui/icons/Chat";
|
||||
//import Badge from "@material-ui/core/Badge";
|
||||
//import ChatIcon from "@material-ui/icons/Chat";
|
||||
|
||||
import TicketListItem from "../TicketListItem";
|
||||
import { i18n } from "../../translate/i18n";
|
||||
|
@ -113,6 +113,11 @@ const NotificationsPopOver = () => {
|
|||
!data.message.read &&
|
||||
(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 => {
|
||||
const ticketIndex = prevState.findIndex(t => t.id === data.ticket.id);
|
||||
if (ticketIndex !== -1) {
|
||||
|
@ -126,9 +131,10 @@ const NotificationsPopOver = () => {
|
|||
(data.message.ticketId === ticketIdRef.current &&
|
||||
document.visibilityState === "visible") ||
|
||||
(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);
|
||||
}
|
||||
|
@ -174,9 +180,9 @@ const NotificationsPopOver = () => {
|
|||
soundAlertRef.current();
|
||||
};
|
||||
|
||||
const handleClick = () => {
|
||||
setIsOpen(prevState => !prevState);
|
||||
};
|
||||
// const handleClick = () => {
|
||||
// setIsOpen(prevState => !prevState);
|
||||
// };
|
||||
|
||||
const handleClickAway = () => {
|
||||
setIsOpen(false);
|
||||
|
@ -188,7 +194,7 @@ const NotificationsPopOver = () => {
|
|||
|
||||
return (
|
||||
<>
|
||||
<IconButton
|
||||
{/* <IconButton
|
||||
onClick={handleClick}
|
||||
// buttonRef={anchorEl}
|
||||
ref={anchorEl}
|
||||
|
@ -198,7 +204,7 @@ const NotificationsPopOver = () => {
|
|||
<Badge badgeContent={notifications.length} color="secondary">
|
||||
<ChatIcon />
|
||||
</Badge>
|
||||
</IconButton>
|
||||
</IconButton> */}
|
||||
<Popover
|
||||
disableScrollLock
|
||||
open={isOpen}
|
||||
|
|
Loading…
Reference in New Issue