ATENÇÃO! Essa alteração é uma adaptação para que possa ser enviado a ura padrão sem a alternativa do usuário escolher opções. Ex 1-.. 2-.. etc. Caso queira voltar para o comportamento padrão que é utilizar as opções definidas nas filas para que o usuário possa escolher, você precisa alterar o arquivo wbotMessageListener.ts e habilitar o seguintes trechos de código: const selectedOption = msg.body; const choosenQueue = queues[+selectedOption - 1];

pull/1/head
adriano 2022-01-18 10:47:19 -03:00
parent 9e02795e0f
commit 1d75ec1514
2 changed files with 33 additions and 30 deletions

View File

@ -1,9 +1,11 @@
import { subHours } from "date-fns";
import { subHours, subMinutes } from "date-fns";
import { Op } from "sequelize";
import Contact from "../../models/Contact";
import Ticket from "../../models/Ticket";
import ShowTicketService from "./ShowTicketService";
const FindOrCreateTicketService = async (
contact: Contact,
whatsappId: number,
@ -41,10 +43,14 @@ const FindOrCreateTicketService = async (
}
if (!ticket && !groupContact) {
ticket = await Ticket.findOne({
where: {
updatedAt: {
[Op.between]: [+subHours(new Date(), 2), +new Date()]
//[Op.between]: [+subHours(new Date(), 2), +new Date()]
// Tempo osioso para a ura responder thuanny
[Op.between]: [+subMinutes(new Date(), 4), +new Date()]
},
contactId: contact.id
},
@ -61,6 +67,7 @@ const FindOrCreateTicketService = async (
}
if (!ticket) {
ticket = await Ticket.create({
contactId: groupContact ? groupContact.id : contact.id,
status: "pending",

View File

@ -22,6 +22,8 @@ import FindOrCreateTicketService from "../TicketServices/FindOrCreateTicketServi
import ShowWhatsAppService from "../WhatsappService/ShowWhatsAppService";
import { debounce } from "../../helpers/Debounce";
import UpdateTicketService from "../TicketServices/UpdateTicketService";
import { date } from "faker";
interface Session extends Client {
id?: number;
@ -112,6 +114,8 @@ const verifyMessage = async (
ticket: Ticket,
contact: Contact
) => {
const quotedMsg = await verifyQuotedMessage(msg);
const messageData = {
id: msg.id.id,
@ -124,6 +128,7 @@ const verifyMessage = async (
quotedMsgId: quotedMsg?.id
};
await ticket.update({ lastMessage: msg.body });
await CreateMessageService({ messageData });
@ -138,20 +143,21 @@ const verifyQueue = async (
const { queues, greetingMessage } = await ShowWhatsAppService(wbot.id!);
console.log('---greetingMessage: ',greetingMessage)
if (queues.length === 1) {
await UpdateTicketService({
ticketData: { queueId: queues[0].id },
ticketId: ticket.id
});
return;
}
const selectedOption = msg.body;
//const selectedOption = msg.body;
//const choosenQueue = queues[+selectedOption - 1];
//apagar essa gambiarra e ativar as 2 linhas acima
const selectedOption = 1;
const choosenQueue = queues[+selectedOption - 1];
const choosenQueue = queues[+selectedOption - 1];
if (choosenQueue) {
await UpdateTicketService({
@ -173,8 +179,6 @@ const verifyQueue = async (
const body = `\u200e${greetingMessage}\n${options}`;
console.log('BACKEND BODY TEST: ', body)
const debouncedSentMessage = debounce(
async () => {
const sentMessage = await wbot.sendMessage(
@ -228,13 +232,12 @@ const handleMessage = async (
// in this case, return and let this message be handled by "media_uploaded" event, when it will have "hasMedia = true"
if (!msg.hasMedia && msg.type !== "chat" && msg.type !== "vcard") return;
msgContact = await wbot.getContactById(msg.to);
msgContact = await wbot.getContactById(msg.to);
} else {
msgContact = await msg.getContact();
console.log('---msgContact: ', msgContact, ' | msg.body: ', msg.body)
console.log('-----msgContact TESTE MSG: ', msgContact, ' | msg.body: ', msg.body)
}
@ -268,8 +271,6 @@ const handleMessage = async (
groupContact
);
console.log('---passou 1')
if (msg.hasMedia) {
await verifyMediaMessage(msg, ticket, contact);
@ -277,9 +278,7 @@ const handleMessage = async (
await verifyMessage(msg, ticket, contact);
}
console.log('---passou 2 ')
//await verifyQueue(wbot, msg, ticket, contact);
//setTimeout(()=>verifyQueue(wbot, msg, ticket, contact), 3000);
if (
!ticket.queue &&
@ -292,9 +291,6 @@ const handleMessage = async (
}
} catch (err) {
Sentry.captureException(err);
logger.error(`Error handling whatsapp message: Err: ${err}`);