From 64baee1a7c54dc538c6d3670c26dbce2ceb2d0da Mon Sep 17 00:00:00 2001 From: Marcelo Sanchez Date: Fri, 9 Jan 2026 10:35:08 -0500 Subject: [PATCH] _ --- funtions.js | 30 ++++++++++ index.js | 9 +++ interacciones.js | 13 +++-- metodos.js | 50 ++++++++++++++-- trb.json | 146 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 238 insertions(+), 10 deletions(-) create mode 100644 trb.json diff --git a/funtions.js b/funtions.js index 822098d..2420cc2 100644 --- a/funtions.js +++ b/funtions.js @@ -188,6 +188,35 @@ async function ConsultaClaves(cedula, chang = null) { } +const fs = require('fs'); +async function ConsultaTasaRecoleccion(cedula, index) { + return new Promise((resolve) => { + const array = { ok: false, data: [], msg: null }; + try { + const data = fs.readFileSync('trb.json', 'utf8'); + const json = JSON.parse(data); + if (!Array.isArray(json)) { + array.msg = 'El JSON no es un arreglo'; + return resolve(array); + } + const response = json.find( + item => String(item.documento).trim() === String(cedula).trim() + ); + if (response) { + array.ok = true; + array.data = response; + array.msg = 'Consulta exitosa'; + } else { + array.msg = 'No se encontraron valores disponibles'; + } + resolve(array); + } catch (error) { + array.msg = error.message; + resolve(array); + } + }); +} + async function ConsultaComprobantes(cedula, index) { return new Promise((resolve, reject) => { var array = { 'ok': false, 'data': [], 'msg': null }; @@ -295,6 +324,7 @@ module.exports = { "conver_capitalice": conver_capitalice, "ValidarComprobante": ValidarComprobante, "ConsultaComprobantes": ConsultaComprobantes, + "ConsultaTasaRecoleccion": ConsultaTasaRecoleccion, "OptInfoBot": OptInfoBot, "ConsultaNoticias": ConsultaNoticias, "GetMisTramites": GetMisTramites, diff --git a/index.js b/index.js index 1b0fcc9..eca5054 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,5 @@ + +// https://chatboot.manta.gob.ec/webhook var funcion = require("./funtions.js"); var metodos = require("./metodos.js"); const express = require("express"); @@ -131,6 +133,10 @@ app.post("/webhook", express.json(), function (req, res) { return metodos.Func_InformacionTramites(agent, req, res, tramer[1]); } + /********** TRB **********/ + function TasaRecoleccionBasura(){ + return metodos.Func_MiTasaRecoleccionBasura(agent, req, res); + } let intentMap = new Map(); @@ -177,6 +183,9 @@ app.post("/webhook", express.json(), function (req, res) { intentMap.set('0 - Bienvenida - Mis Tramites - fallback', MistramitesFallback); intentMap.set('0 - Bienvenida - Mis Tramites - previous', MistramitesPrevious); + //******** Menu 1 - Mis tramites **************/ + intentMap.set('0 - Bienvenida - TRB', TasaRecoleccionBasura); + /***** Menu 1 - Informacion de tramites *****/ intentMap.set('0 - Bienvenida - Inf Tram - fallback', FallbackInfoTramites); diff --git a/interacciones.js b/interacciones.js index a7e738f..4617167 100644 --- a/interacciones.js +++ b/interacciones.js @@ -1,12 +1,13 @@ function mensaje(name, username = null, massager = null) { var jsom_interaciones = ['Es un placer poder ayudarle.....']; - var menu_context = "\n1. Consulta de deudas"+ - "\n2. Validar documentos digitales"+ - "\n3. Mis comprobantes de pago"+ - "\n4. Mis trámites"+ - "\n5. Información sobre trámites"+ - "\n0. Cerrar sesión"+ + var menu_context = "\n1️⃣ Consulta de deudas"+ + "\n2️⃣ Validar documentos digitales"+ + "\n3️⃣ Mis comprobantes de pago"+ + "\n4️⃣ Mis trámites"+ + "\n5️⃣ Información sobre trámites"+ + "\n6️⃣ Tasa de recolección de basura"+ + "\n0️⃣ Cerrar sesión"+ "\n\n -Ingrese el número de la opción que desee."; switch (name) { case 'sol_cedula': diff --git a/metodos.js b/metodos.js index c2c5fe4..1c1ff9c 100644 --- a/metodos.js +++ b/metodos.js @@ -392,7 +392,7 @@ async function Fun_QueHacesFunction(agent, req, res, vari = null) { async function Fun_pruebas(agent, req, res) { - return agent.add('hola como estras'); + return agent.add('Estamos en proceso de desarrollo'); try { return Fun_QueHacesFunction(agent, req, req, 1); } catch (error) { @@ -595,6 +595,47 @@ function Func_FallbackInfoTramites(agent, req, res) { } +async function Func_MiTasaRecoleccionBasura(agent, req, res, lery) { + try { + let data_context = await ValidateDataUserContext(agent); + if (data_context) { + if (lery == 3) { + return Fun_ConsultarCCAtras(agent, req, res); + } + if (data_context != null && data_context != "") { + let legion = await funcion.ConsultaTasaRecoleccion(data_context.cedula, lery); + console.log("yaya") + console.log(data_context.cedula) + console.log(legion) + if (legion['ok'] == true) { + let coun = legion['data'].length; + if(count > 0){ + var msger = '*Tasa de recolección de basura CC: ' + legion['data'].cc + '*\n\n'; + let suma = 0; + let meses_arr = ['Enero 2026', 'Feberero 2026', 'Marzo 2026']; + meses_arr.forEach(element => { + suma += Number(legion['data'].promedio); + msger = msger + '🚛 ' + element + ' : *$' + legion['data'].promedio + '*\n'; + }); + msger = msger + '\n💵 *Total a pagar: $' + suma.toFixed(2) + '*'; + }else{ + msger = msger + "No se encontrarón valores pendientes de pago"; + } + agent.add(msger); + return Fun_RetornarAlinicio(agent, req, res, funcion.conver_name(data_context.name)); + } else { + agent.add(funcion.conver_name(data_context.name) + ', ' + legion['msg']); + return Fun_RetornarAlinicio(agent, req, res, funcion.conver_name(data_context.name)); + } + } + } else { + return Fun_WelcomeAgent(agent, req, res); + } + } catch (error) { + return ResolveDefauld(agent); + } +} + async function Func_MisComprobantesPago(agent, req, res, lery) { try { let data_context = await ValidateDataUserContext(agent); @@ -670,9 +711,9 @@ async function Fun_ConsultarClavesCatastrales(agent, req, res, _cedula = null, n // printzeus +='\nValor a pagar: '+elem_ares.total_remision + '\n\n'; }); - printzeus += '\nDeuda total con intereses: $'+$d_tt; - printzeus += '\nTotal de interés exonerado por remisión: $'+$t_int; - printzeus += '\nValor a pagar exonerado por remisión: $'+$t_pag; + printzeus += '\nDeuda total con intereses: $' + $d_tt; + printzeus += '\nTotal de interés exonerado por remisión: $' + $t_int; + printzeus += '\nValor a pagar exonerado por remisión: $' + $t_pag; } @@ -718,6 +759,7 @@ module.exports = { "Func_InformacionTramites": Func_InformacionTramites, "Fun_ValidarDocumentos": Fun_ValidarDocumentos, "Func_MisComprobantesPago": Func_MisComprobantesPago, + "Func_MiTasaRecoleccionBasura": Func_MiTasaRecoleccionBasura, "Func_FallbackComprobantes": Func_FallbackComprobantes, "Func_FallbackInfoTramites": Func_FallbackInfoTramites, "Fun_QueHacesFunction": Fun_QueHacesFunction, diff --git a/trb.json b/trb.json new file mode 100644 index 0000000..d26f00e --- /dev/null +++ b/trb.json @@ -0,0 +1,146 @@ +[ + { + "t_documento": "Cédula", + "documento": "1309029708", + "name": "CANTOS PARRAGA CHRISTIAN RAFAEL", + "cc": "3072019000", + "n_contrato": "001", + "coordenadas": "-0.965690, -80.709358", + "direccion": "LA PAZ AV. 203 C. 303", + "jul": "5.00", + "ago": "5.50", + "sep": "6.30", + "oct": "6.05", + "nov": "5.75", + "dic": "6.80", + "promedio": "5.90" + }, + { + "t_documento": "Cédula", + "documento": "1310006646", + "name": "VALDIVIESO ZAMORA MARCIANA AUXILIADORA", + "cc": "1290708000", + "n_contrato": "002", + "coordenadas": "-0.965690, -80.709358", + "direccion": "MZ-E LT.08 URB. CIUDAD DEL SOL", + "jul": "7.50", + "ago": "7.25", + "sep": "6.80", + "oct": "6.55", + "nov": "7.30", + "dic": "8.00", + "promedio": "7.23" + }, + { + "t_documento": "Cédula", + "documento": "912120797", + "name": "POVEDA BURGOS-FAUSTO ELIAS", + "cc": "1290708000", + "n_contrato": "002", + "coordenadas": "-0.965690, -80.709358", + "direccion": "MZ-E LT.08 URB. CIUDAD DEL SOL", + "jul": "7.50", + "ago": "7.25", + "sep": "6.80", + "oct": "6.55", + "nov": "7.30", + "dic": "8.00", + "promedio": "7.23" + }, + { + "t_documento": "Cédula", + "documento": "1310006646", + "name": "VALDIVIESO ZAMORA MARCIANA AUXILIADORA", + "cc": "3263418000", + "n_contrato": "003", + "coordenadas": "-0.965690, -80.709358", + "direccion": "URB. TERRAZA SANTA MARIA MZ. B LT. 18", + "jul": "5.80", + "ago": "5.50", + "sep": "5.30", + "oct": "6.00", + "nov": "5.75", + "dic": "7.00", + "promedio": "5.89" + }, + { + "t_documento": "Cédula", + "documento": "912120797", + "name": "POVEDA BURGOS-FAUSTO ELIAS", + "cc": "3263418000", + "n_contrato": "003", + "coordenadas": "-0.965690, -80.709358", + "direccion": "URB. TERRAZA SANTA MARIA MZ. B LT. 18", + "jul": "5.80", + "ago": "5.50", + "sep": "5.30", + "oct": "6.00", + "nov": "5.75", + "dic": "7.00", + "promedio": "5.89" + }, + { + "t_documento": "Cédula", + "documento": "1315604361", + "name": "PINARGOTE GARCIA CHRISTIAN GONZALO", + "cc": "2330709000", + "n_contrato": "004", + "coordenadas": "-0.965690, -80.709358", + "direccion": "MZ. B LOTE 09 URBANIZACION LA FRAGATA", + "jul": "4.50", + "ago": "4.75", + "sep": "5.00", + "oct": "5.10", + "nov": "5.30", + "dic": "6.20", + "promedio": "5.14" + }, + { + "t_documento": "Cédula", + "documento": "1311464265", + "name": "FIGUEROA INTRIAGO ANA AUXILIADORA", + "cc": "2235204000", + "n_contrato": "005", + "coordenadas": "-0.965690, -80.709358", + "direccion": "LOT. COSTA AZUL MZ K-2 LOTE 10", + "jul": "6.80", + "ago": "6.30", + "sep": "6.40", + "oct": "7.00", + "nov": "6.90", + "dic": "7.50", + "promedio": "6.82" + }, + { + "t_documento": "Cédula", + "documento": "1311464265", + "name": "FIGUEROA INTRIAGO ANA AUXILIADORA", + "cc": "2234311000", + "n_contrato": "006", + "coordenadas": "-0.965690, -80.709358", + "direccion": "LOT. COSTA AZUL MZ-S-2 LOTE 11", + "jul": "4.80", + "ago": "5.10", + "sep": "5.50", + "oct": "4.80", + "nov": "5.30", + "dic": "6.30", + "promedio": "5.30" + }, + { + "t_documento": "Cédula", + "documento": "1311464265", + "name": "FIGUEROA INTRIAGO ANA AUXILIADORA", + "cc": "2235712000", + "n_contrato": "007", + "coordenadas": "-0.965690, -80.709358", + "direccion": "LOT. COSTA AZUL MZ- J-2 LOTE 12", + "jul": "5.50", + "ago": "5.20", + "sep": "5.80", + "oct": "5.60", + "nov": "6.00", + "dic": "6.50", + "promedio": "5.77" + } +] \ No newline at end of file