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,
@ -40,11 +42,15 @@ const FindOrCreateTicketService = async (
}
}
if (!ticket && !groupContact) {
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;
@ -99,7 +101,7 @@ const verifyMediaMessage = async (
mediaUrl: media.filename,
mediaType: media.mimetype.split("/")[0],
quotedMsgId: quotedMsg?.id
};
};
await ticket.update({ lastMessage: msg.body || media.filename });
const newMessage = await CreateMessageService({ messageData });
@ -112,6 +114,8 @@ const verifyMessage = async (
ticket: Ticket,
contact: Contact
) => {
const quotedMsg = await verifyQuotedMessage(msg);
const messageData = {
id: msg.id.id,
@ -123,6 +127,7 @@ const verifyMessage = async (
read: msg.fromMe,
quotedMsgId: quotedMsg?.id
};
await ticket.update({ lastMessage: msg.body });
@ -136,22 +141,23 @@ const verifyQueue = async (
contact: Contact
) => {
const { queues, greetingMessage } = await ShowWhatsAppService(wbot.id!);
console.log('---greetingMessage: ',greetingMessage)
const { queues, greetingMessage } = await ShowWhatsAppService(wbot.id!);
if (queues.length === 1) {
await UpdateTicketService({
ticketData: { queueId: queues[0].id },
ticketId: ticket.id
});
});
return;
}
//const selectedOption = msg.body;
//const choosenQueue = queues[+selectedOption - 1];
const selectedOption = msg.body;
//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(
@ -211,7 +215,7 @@ const handleMessage = async (
msg: WbotMessage,
wbot: Session
): Promise<void> => {
if (!isValidMsg(msg)) {
if (!isValidMsg(msg)) {
return;
}
@ -228,14 +232,13 @@ 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)
}
const chat = await msg.getChat();
@ -268,31 +271,24 @@ const handleMessage = async (
groupContact
);
console.log('---passou 1')
if (msg.hasMedia) {
await verifyMediaMessage(msg, ticket, contact);
} else {
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 &&
!chat.isGroup &&
!msg.fromMe &&
!ticket.userId &&
whatsapp.queues.length >= 1
) {
) {
await verifyQueue(wbot, msg, ticket, contact);
}
}
} catch (err) {