ajustes slm
							parent
							
								
									baaa1a5db3
								
							
						
					
					
						commit
						95bec1f92e
					
				|  | @ -87,6 +87,7 @@ export const hit = async (req: Request, res: Response): Promise<Response> => { | |||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     // let response: any = `*Olá!*\r\n\r\n*Esperamos que esteja tudo bem com você. Somos o grupo HIT e estamos aqui para mantê-lo atualizado sobre o chamado referente à unidade 0001 - Hit World Teste. Queremos garantir que você esteja informado sobre o incidente e possa acompanhar tudo de perto.*\r\n\r\nPrezado cliente, se deseja adicionar alguma informação no protocolo 200-322442 digite 2\r\n\r\n\r\n*Protocolo:* 200-322442\r\n*Data de abertura:* 07/07/2023 16:51:29\r\n*Nome do cliente:* Hit World Teste\r\n*Nome da filial:* Hit World Teste\r\n*Código do cliente:* 0001\r\n\r\n*Informação de abertura:* teste de ativação Contato: Felipe Telefone: 11983534545\r\n*Data de abertura:* 07/07/2023 16:51:29\r\n\r\n`
 | ||||
| 
 | ||||
|     let response: any = await hitPortalMonitoring({ | ||||
|       'params[n_chamado_web]': req.body['n_chamado_web'], | ||||
|  | @ -120,6 +121,8 @@ export const hit = async (req: Request, res: Response): Promise<Response> => { | |||
| 
 | ||||
|       await sendMessageHitMonitoring(response, ticket); | ||||
| 
 | ||||
|       await sendMessageInsertInfoSLM(req, ticket, ['atdabriu', 'atdatualizou']); | ||||
| 
 | ||||
|     } | ||||
|     else if (ticket.id && ticket.userId == botInfo.userIdBot) { | ||||
| 
 | ||||
|  | @ -135,6 +138,8 @@ export const hit = async (req: Request, res: Response): Promise<Response> => { | |||
| 
 | ||||
|       await sendMessageHitMonitoring(response, ticket); | ||||
| 
 | ||||
|       await sendMessageInsertInfoSLM(req, ticket, ['atdabriu', 'atdatualizou']); | ||||
| 
 | ||||
|     } | ||||
|   } | ||||
|   else { | ||||
|  | @ -146,6 +151,17 @@ export const hit = async (req: Request, res: Response): Promise<Response> => { | |||
| 
 | ||||
| }; | ||||
| 
 | ||||
| async function sendMessageInsertInfoSLM(req: Request, ticket: any, params: any[]) { | ||||
| 
 | ||||
|   if (params.includes(req.body['action'])) { | ||||
| 
 | ||||
|     await new Promise(f => setTimeout(f, 1000)); | ||||
| 
 | ||||
|     await sendMessageHitMonitoring(`Se deseja adicionar alguma informação ao protocolo acima, digite 2.`, ticket); | ||||
| 
 | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| async function sendMessageHitMonitoring(msg: any, ticket: Ticket) { | ||||
| 
 | ||||
|   if (msg && msg.length > 0) { | ||||
|  |  | |||
|  | @ -0,0 +1,26 @@ | |||
| import Whatsapp from "../models/Whatsapp"; | ||||
| import ShowQueuesByUser from "../services/UserServices/ShowQueuesByUser"; | ||||
| import ShowWhatsAppService from "../services/WhatsappService/ShowWhatsAppService"; | ||||
| 
 | ||||
| async function whatsappQueueMatchingUserQueue(userId: number, whatsapp: Whatsapp, userProfile: string = 'user') { | ||||
| 
 | ||||
|     const userQueues = await ShowQueuesByUser({ profile: userProfile, userId: userId }); | ||||
| 
 | ||||
|     if (!userQueues || userQueues && userQueues.length == 0) return | ||||
| 
 | ||||
|     // console.log('-----> userQueues: ', userQueues);
 | ||||
| 
 | ||||
|     let whats: any = await ShowWhatsAppService(whatsapp.id); | ||||
| 
 | ||||
|     if (!whats.queues || whats.queues && whats.queues.length == 0) return | ||||
| 
 | ||||
|     const whatsappQueues = whats.queues.map((e: any) => e.dataValues.name); | ||||
| 
 | ||||
|     // console.log('-----> whatsappQueues: ', whatsappQueues);
 | ||||
| 
 | ||||
|     const matchingQueue = userQueues.find(queue => whatsappQueues.includes(queue.name)); | ||||
| 
 | ||||
|     return matchingQueue | ||||
| } | ||||
| 
 | ||||
| export default whatsappQueueMatchingUserQueue | ||||
|  | @ -14,6 +14,8 @@ import { splitDateTime } from "../../helpers/SplitDateTime"; | |||
| import TicketEmiterSumOpenClosedByUser from "../../helpers/OnlineReporEmiterInfoByUser"; | ||||
| 
 | ||||
| import { createOrUpdateTicketCache } from '../../helpers/TicketCache' | ||||
| import User from "../../models/User"; | ||||
| import whatsappQueueMatchingUserQueue from "../../helpers/whatsappQueueMatchingUserQueue"; | ||||
| let flatten = require('flat') | ||||
| 
 | ||||
| 
 | ||||
|  | @ -33,12 +35,17 @@ const CreateTicketService = async ({ | |||
| }: Request): Promise<Ticket> => { | ||||
|   | ||||
| 
 | ||||
|   console.log('========> queueId:  ', queueId) | ||||
| 
 | ||||
|   try { | ||||
| 
 | ||||
|     const defaultWhatsapp = await GetDefaultWhatsApp(userId); | ||||
| 
 | ||||
| 
 | ||||
|     if (!queueId) { | ||||
|       const user = await User.findByPk(userId, { raw: true, }) | ||||
|       const matchingQueue = await whatsappQueueMatchingUserQueue(userId, defaultWhatsapp, user?.profile); | ||||
|       queueId = matchingQueue ? matchingQueue.queueId : undefined | ||||
|     } | ||||
| 
 | ||||
|     await CheckContactOpenTickets(contactId); | ||||
| 
 | ||||
|     const { isGroup } = await ShowContactService(contactId); | ||||
|  |  | |||
|  | @ -401,12 +401,12 @@ async function sendDelayedMessages(wbot: any, ticket: Ticket, contact: Contact, | |||
| 
 | ||||
|         if (valid && valid.data.result == 'open') { | ||||
| 
 | ||||
|           botSendMessage(ticket, `Protocolo validado, por favor, pode digitar o texto a ser adicionado no histórico do protocolo *${params[1]}*`) | ||||
|           botSendMessage(ticket, `✅ Protocolo validado, agora digite a informação que deseja adicionar.`) | ||||
| 
 | ||||
|         } | ||||
|         else if (valid && valid.data.result == 'notfound') { | ||||
| 
 | ||||
|           botSendMessage(ticket, `Protocolo *${params[1]}* não encontrado!\n_Digite *0* para falar com a HIT._`) | ||||
|           botSendMessage(ticket, `Protocolo *${params[1]}* não encontrado!`) | ||||
| 
 | ||||
|         } | ||||
|         else if (valid && valid.data.result == 'close') { | ||||
|  | @ -754,7 +754,7 @@ const transferTicket = async (queueIndex: number, wbot: any, ticket: Ticket) => | |||
| const botMsgActions = (params: string) => { | ||||
| 
 | ||||
|   let lstActions = params.split('dialog_actions=') | ||||
|   let bodyMsg = lstActions[0] | ||||
|   let bodyMsg = lstActions[0].trim() | ||||
|   let obj = {} | ||||
| 
 | ||||
|   console.log('lstActions: ', lstActions[1].split('=')) | ||||
|  | @ -1109,11 +1109,8 @@ const handleMessage = async ( | |||
| 
 | ||||
|         if (last_messages.length > 0 && last_messages[0].body.includes('validado') && msg.body.trim() != '0') { | ||||
| 
 | ||||
|           // botSendMessage(ticket,`Aguarde, inserindo informação...\n_Digite *0* para falar com a HIT._`)
 | ||||
| 
 | ||||
|           await SendWhatsAppMessage({ body: `Aguarde inserindo informação, em breve te atualizaremos`, ticket }) | ||||
| 
 | ||||
| 
 | ||||
|           let aux_msg = last_messages[0].body | ||||
| 
 | ||||
|           aux_msg = aux_msg.split('\n')[0] | ||||
|  | @ -1139,12 +1136,13 @@ const handleMessage = async ( | |||
| 
 | ||||
|           if (response && response.data.result) { | ||||
| 
 | ||||
|             botSendMessage(ticket, `${response.data.result}`) | ||||
|             // botSendMessage(ticket, `${response.data.result}`)
 | ||||
|             botSendMessage(ticket, `✅ A informação foi adicionada com sucesso e será armazenada no histórico do protocolo.`) | ||||
| 
 | ||||
|           } | ||||
|           else { | ||||
| 
 | ||||
|             botSendMessage(ticket, `Ops! Houve um erro ao tentar inserir sua informação devido a um erro na comunicação com o servidor.Tente novamente mais tarde.\n_Digite *0* para falar com a HIT._`) | ||||
|             botSendMessage(ticket, `Ops! Houve um erro ao tentar inserir sua informação devido a um erro na comunicação com o servidor.Tente novamente mais tarde.`) | ||||
| 
 | ||||
|           } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue