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

pull/1/head
adriano 2022-04-28 17:57:57 -03:00
parent ab7464f776
commit 02b36b6bf7
7 changed files with 104 additions and 35 deletions

View File

@ -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;

View File

@ -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;
};

View File

@ -15,7 +15,7 @@ const CreateTicketService = async ({
status,
userId
}: Request): Promise<Ticket> => {
const defaultWhatsapp = await GetDefaultWhatsApp(userId);
const defaultWhatsapp = await GetDefaultWhatsApp(userId);
await CheckContactOpenTickets(contactId);

View File

@ -1,10 +1,13 @@
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,
@ -15,13 +18,21 @@ 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
}
});
if (ticket) {
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) {
if (ticket) {
await ticket.update({
status: "pending",
userId: null,
@ -60,7 +74,8 @@ const FindOrCreateTicketService = async (
order: [["updatedAt", "DESC"]]
});
if (ticket) {
if (ticket) {
await ticket.update({
status: "pending",
userId: null,
@ -69,11 +84,17 @@ const FindOrCreateTicketService = async (
}
}
if (!ticket) {
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

View File

@ -201,12 +201,20 @@ 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
});
let botOptions = ''
// O bot abre a mensagem na fila para atender o usuario
@ -229,9 +237,7 @@ const verifyQueue = async (
else{
body = `\u200e${choosenQueue.greetingMessage}`;
}
// const body = `\u200e${choosenQueue.greetingMessage}`;
const sentMessage = await wbot.sendMessage(`${contact.number}@c.us`, body);
await verifyMessage(sentMessage, ticket, contact);
@ -477,7 +483,7 @@ const handleMessage = async (
}
// console.log('----------------- ticket_message: ', ticket_message)
// console.log('----------------- ticket_message: ', ticket_message)
// È numero

View File

@ -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) {

View File

@ -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) {
@ -125,10 +130,11 @@ const NotificationsPopOver = () => {
const shouldNotNotificate =
(data.message.ticketId === ticketIdRef.current &&
document.visibilityState === "visible") ||
(data.ticket.userId && data.ticket.userId !== user?.id) ||
data.ticket.isGroup;
(data.ticket.userId && data.ticket.userId !== user?.id) ||
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}