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];
							parent
							
								
									9e02795e0f
								
							
						
					
					
						commit
						1d75ec1514
					
				|  | @ -1,9 +1,11 @@ | ||||||
| import { subHours } from "date-fns"; | import { subHours, subMinutes } from "date-fns"; | ||||||
| import { Op } from "sequelize"; | import { Op } from "sequelize"; | ||||||
| import Contact from "../../models/Contact"; | import Contact from "../../models/Contact"; | ||||||
| import Ticket from "../../models/Ticket"; | import Ticket from "../../models/Ticket"; | ||||||
| import ShowTicketService from "./ShowTicketService"; | import ShowTicketService from "./ShowTicketService"; | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| const FindOrCreateTicketService = async ( | const FindOrCreateTicketService = async ( | ||||||
|   contact: Contact, |   contact: Contact, | ||||||
|   whatsappId: number, |   whatsappId: number, | ||||||
|  | @ -41,10 +43,14 @@ const FindOrCreateTicketService = async ( | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   if (!ticket && !groupContact) {  |   if (!ticket && !groupContact) {  | ||||||
|  |      | ||||||
|     ticket = await Ticket.findOne({ |     ticket = await Ticket.findOne({ | ||||||
|       where: { |       where: { | ||||||
|         updatedAt: { |         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 |         contactId: contact.id | ||||||
|       }, |       }, | ||||||
|  | @ -61,6 +67,7 @@ const FindOrCreateTicketService = async ( | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   if (!ticket) { |   if (!ticket) { | ||||||
|  |      | ||||||
|     ticket = await Ticket.create({ |     ticket = await Ticket.create({ | ||||||
|       contactId: groupContact ? groupContact.id : contact.id, |       contactId: groupContact ? groupContact.id : contact.id, | ||||||
|       status: "pending", |       status: "pending", | ||||||
|  |  | ||||||
|  | @ -22,6 +22,8 @@ import FindOrCreateTicketService from "../TicketServices/FindOrCreateTicketServi | ||||||
| import ShowWhatsAppService from "../WhatsappService/ShowWhatsAppService"; | import ShowWhatsAppService from "../WhatsappService/ShowWhatsAppService"; | ||||||
| import { debounce } from "../../helpers/Debounce"; | import { debounce } from "../../helpers/Debounce"; | ||||||
| import UpdateTicketService from "../TicketServices/UpdateTicketService"; | import UpdateTicketService from "../TicketServices/UpdateTicketService"; | ||||||
|  | import { date } from "faker"; | ||||||
|  |   | ||||||
| 
 | 
 | ||||||
| interface Session extends Client { | interface Session extends Client { | ||||||
|   id?: number; |   id?: number; | ||||||
|  | @ -112,6 +114,8 @@ const verifyMessage = async ( | ||||||
|   ticket: Ticket, |   ticket: Ticket, | ||||||
|   contact: Contact |   contact: Contact | ||||||
| ) => { | ) => { | ||||||
|  | 
 | ||||||
|  |    | ||||||
|   const quotedMsg = await verifyQuotedMessage(msg); |   const quotedMsg = await verifyQuotedMessage(msg); | ||||||
|   const messageData = { |   const messageData = { | ||||||
|     id: msg.id.id, |     id: msg.id.id, | ||||||
|  | @ -124,6 +128,7 @@ const verifyMessage = async ( | ||||||
|     quotedMsgId: quotedMsg?.id |     quotedMsgId: quotedMsg?.id | ||||||
|   }; |   }; | ||||||
|   |   | ||||||
|  | 
 | ||||||
|   await ticket.update({ lastMessage: msg.body }); |   await ticket.update({ lastMessage: msg.body }); | ||||||
| 
 | 
 | ||||||
|   await CreateMessageService({ messageData }); |   await CreateMessageService({ messageData }); | ||||||
|  | @ -138,20 +143,21 @@ const verifyQueue = async ( | ||||||
| 
 | 
 | ||||||
|   const { queues, greetingMessage } = await ShowWhatsAppService(wbot.id!);   |   const { queues, greetingMessage } = await ShowWhatsAppService(wbot.id!);   | ||||||
|    |    | ||||||
|   console.log('---greetingMessage: ',greetingMessage) |  | ||||||
| 
 |  | ||||||
|   if (queues.length === 1) { |   if (queues.length === 1) { | ||||||
|     await UpdateTicketService({ |     await UpdateTicketService({ | ||||||
|       ticketData: { queueId: queues[0].id }, |       ticketData: { queueId: queues[0].id }, | ||||||
|       ticketId: ticket.id |       ticketId: ticket.id | ||||||
|     });   |     });   | ||||||
| 
 |  | ||||||
|     return; |     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) { |   if (choosenQueue) { | ||||||
|     await UpdateTicketService({ |     await UpdateTicketService({ | ||||||
|  | @ -173,8 +179,6 @@ const verifyQueue = async ( | ||||||
| 
 | 
 | ||||||
|     const body = `\u200e${greetingMessage}\n${options}`; |     const body = `\u200e${greetingMessage}\n${options}`; | ||||||
| 
 | 
 | ||||||
|     console.log('BACKEND BODY TEST: ', body) |  | ||||||
| 
 |  | ||||||
|     const debouncedSentMessage = debounce( |     const debouncedSentMessage = debounce( | ||||||
|       async () => { |       async () => { | ||||||
|         const sentMessage = await wbot.sendMessage( |         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"
 |       // 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; |       if (!msg.hasMedia && msg.type !== "chat" && msg.type !== "vcard") return; | ||||||
| 
 |         msgContact = await wbot.getContactById(msg.to); | ||||||
|       msgContact = await wbot.getContactById(msg.to); |  | ||||||
|     } else { |     } else { | ||||||
| 
 | 
 | ||||||
|       msgContact = await msg.getContact(); |       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 |         groupContact | ||||||
|       ); |       ); | ||||||
| 
 | 
 | ||||||
|       console.log('---passou 1') |  | ||||||
|        |  | ||||||
|        |        | ||||||
|       if (msg.hasMedia) { |       if (msg.hasMedia) { | ||||||
|         await verifyMediaMessage(msg, ticket, contact); |         await verifyMediaMessage(msg, ticket, contact); | ||||||
|  | @ -277,9 +278,7 @@ const handleMessage = async ( | ||||||
|         await verifyMessage(msg, ticket, contact); |         await verifyMessage(msg, ticket, contact); | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       console.log('---passou 2 ')  |      //setTimeout(()=>verifyQueue(wbot, msg, ticket, contact), 3000);   
 | ||||||
|       //await verifyQueue(wbot, msg, ticket, contact);
 |  | ||||||
|        |  | ||||||
|         |         | ||||||
|       if ( |       if ( | ||||||
|         !ticket.queue && |         !ticket.queue && | ||||||
|  | @ -292,9 +291,6 @@ const handleMessage = async ( | ||||||
|       }  |       }  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|   } catch (err) { |   } catch (err) { | ||||||
|     Sentry.captureException(err); |     Sentry.captureException(err); | ||||||
|     logger.error(`Error handling whatsapp message: Err: ${err}`); |     logger.error(`Error handling whatsapp message: Err: ${err}`); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue