Pegando opção da mensagem do dialogflow

pull/20/head
adriano 2022-12-06 00:23:47 -03:00
parent 8e3861afb4
commit bac5e1c048
1 changed files with 51 additions and 90 deletions

View File

@ -281,7 +281,7 @@ async function sendDelayedMessages(wbot: Session, ticket: Ticket, contact: Conta
let msgAction = botMsgActions(body) let msgAction = botMsgActions(body)
console.log('gggggggggggggggggggggggggggggggggg msgAction: ', msgAction) // console.log('gggggggggggggggggggggggggggggggggg msgAction: ', msgAction)
if (msgAction.actions[0] == 'request_endpoint') { if (msgAction.actions[0] == 'request_endpoint') {
@ -296,6 +296,7 @@ async function sendDelayedMessages(wbot: Session, ticket: Ticket, contact: Conta
if (endPointResponse && Object.entries(endPointResponse.data).length > 0) { if (endPointResponse && Object.entries(endPointResponse.data).length > 0) {
// endPointResponse.data.categoria = 'ELOS'
// endPointResponse.data.categoria = 'INFRAESTRUTURA' // endPointResponse.data.categoria = 'INFRAESTRUTURA'
// endPointResponse.data.subcategoria = 'INTERNET' // endPointResponse.data.subcategoria = 'INTERNET'
// endPointResponse.data.terceiro_nivel = 'QUEDA TOTAL' // endPointResponse.data.terceiro_nivel = 'QUEDA TOTAL'
@ -326,93 +327,9 @@ async function sendDelayedMessages(wbot: Session, ticket: Ticket, contact: Conta
centro_de_custo = endPointResponse.data.centro_custo_departamento centro_de_custo = endPointResponse.data.centro_custo_departamento
msg_endpoint2 = await queryEndPointHit(centro_de_custo) msg_endpoint2 = await queryEndPointHit(centro_de_custo)
// let response2 = await endPointQuery('http://177.107.193.124:8095/labs/zabbix-frontend/api/api.php', 'post', centro_de_custo.trim())
// if (response2 && response2.data.result) {
// response2 = response2.data.result;
// for (let i = 0; i < response2.length; i++) {
// let data = ''
// let sub_data = '*Atualizações:*\n\n'
// const properties: any = Object.entries(response2[i]);
// for (let x = 0; x < properties.length; x++) {
// if (typeof (properties[x][1]) != 'object') {
// data += `*${properties[x][0]}*: ${properties[x][1].replace(/(\r\n|\n|\r)/gm, "")}\n`
// }
// else if (typeof (properties[x][1]) == 'object') {
// const sub_properties = properties[x][1];
// for (let k = 0; k < sub_properties.length; k++) {
// const inner_properties: any = Object.entries(sub_properties[k]);
// for (let y = 0; y < inner_properties.length; y++) {
// sub_data += `*${inner_properties[y][0]}*: ${inner_properties[y][1].replace(/(\r\n|\n|\r)/gm, "")}\n`
// }
// sub_data += '\n'
// }
// }
// }
// msg_endpoint2.push({ header: data, body: sub_data })
// }
// }
// else {
// msg_endpoint2 = null
// }
} }
// const monitoramento_response = async (response: any | null) => {
// if (!response) {
// const msg = await wbot.sendMessage(`${contact.number}@c.us`, `Houve um erro ao tentar consultar o monitoramento!\n\n_Digite *0* para voltar ao menu principal._`);
// await verifyMessage(msg, ticket, contact);
// await new Promise(f => setTimeout(f, 1000));
// }
// else if (response.length > 0) {
// for (let i = 0; i < response.length; i++) {
// const msg = await wbot.sendMessage(`${contact.number}@c.us`,
// `*Chamado ${extractCallCode(msgAction.msgBody)}*\n*Centro de custo: ${centro_de_custo}*\n\n*Incidente*:\n\n ${response[i].header}\n${response[i].body} _Digite *0* para voltar ao menu principal._`);
// await verifyMessage(msg, ticket, contact);
// await new Promise(f => setTimeout(f, 1000));
// }
// }
// else {
// const msg = await wbot.sendMessage(`${contact.number}@c.us`, `Sem incidente!\n\n_Digite *0* para voltar ao menu principal._`);
// await verifyMessage(msg, ticket, contact);
// await new Promise(f => setTimeout(f, 1000));
// }
// }
const itsm_response = async (message1: string = '', message2: string = '') => { const itsm_response = async (message1: string = '', message2: string = '') => {
const msg = await wbot.sendMessage(`${contact.number}@c.us`, `*Situação do chamado ${extractCallCode(msgAction.msgBody)}:*${message1}${msg_endpoint_response}${message2}\n_Digite *0* para voltar ao menu principal._`); const msg = await wbot.sendMessage(`${contact.number}@c.us`, `*Situação do chamado ${extractCallCode(msgAction.msgBody)}:*${message1}${msg_endpoint_response}${message2}\n_Digite *0* para voltar ao menu principal._`);
await verifyMessage(msg, ticket, contact); await verifyMessage(msg, ticket, contact);
@ -429,8 +346,36 @@ async function sendDelayedMessages(wbot: Session, ticket: Ticket, contact: Conta
if (body.search('dialog_options') != -1) {
if ( let msgAction = botMsgActions(body)
let index = msgAction.actions.findIndex((i) => i == 'dialog_options')
if (index != -1) {
let dialog_options = msgAction.actions[index + 1]
if (dialog_options == '3' && endPointResponse.data.categoria == 'ELOS') {
index = msgAction.actions.findIndex((i) => i == 'queue_transfer')
if (index != -1) {
await itsm_response('\n\n')
await monitoramento_response2(msg_endpoint2, wbot, contact, ticket, centro_de_custo, '\n\n', false)
botSendMessage(ticket, contact, wbot, `Estamos direcionando seu atendimento para o Suporte. Em breve você será atendido por um de nossos atendentes!\n\nPara voltar ao atendimento *automatizado* e sair da fila de atendimento *humano* digite *0*`)
await transferTicket(+msgAction.actions[index + 1], wbot, ticket, contact)
}
}
}
}
else if (
(endPointResponse.data.categoria == 'INFRAESTRUTURA' && endPointResponse.data.subcategoria == 'INTERNET' && (endPointResponse.data.categoria == 'INFRAESTRUTURA' && endPointResponse.data.subcategoria == 'INTERNET' &&
endPointResponse.data.terceiro_nivel == 'QUEDA TOTAL') || endPointResponse.data.terceiro_nivel == 'QUEDA TOTAL') ||
@ -754,15 +699,31 @@ const transferTicket = async (queueIndex: number, wbot: Session, ticket: Ticket,
} }
// const botMsgActions = (params: string) => {
// let lstActions = params.split('dialog_actions=')
// let bodyMsg = lstActions[0].trim()
// let actions = lstActions[1].split("=")
// console.log('LENGTH: ')
// return { msgBody: bodyMsg, 'actions': [actions[0].trim(), actions[1].trim()] };
// }
const botMsgActions = (params: string) => { const botMsgActions = (params: string) => {
let lstActions = params.split('dialog_actions=') let lstActions = params.split('dialog_actions=')
let bodyMsg = lstActions[0].trim() let bodyMsg = lstActions[0]
let actions = lstActions[1].split("=") let obj = {}
return { msgBody: bodyMsg, 'actions': [actions[0].trim(), actions[1].trim()] }; console.log('lstActions: ', lstActions[1].split('='))
let actions = lstActions[1].split('=')
return { msgBody: bodyMsg, 'actions': actions };
} }
const isValidMsg = (msg: WbotMessage): boolean => { const isValidMsg = (msg: WbotMessage): boolean => {
if (msg.from === "status@broadcast") return false; if (msg.from === "status@broadcast") return false;
if ( if (