Update funtions.js
This commit is contained in:
parent
93391f8f3c
commit
cc90b67b4d
184
funtions.js
184
funtions.js
@ -1,7 +1,8 @@
|
|||||||
const { error } = require('actions-on-google/dist/common');
|
const { error } = require('actions-on-google/dist/common');
|
||||||
const axios= require('axios');
|
const axios = require('axios');
|
||||||
const URLIC = 'https://sistemasic.manta.gob.ec/';
|
const URLIC = 'https://sistemasic.manta.gob.ec/';
|
||||||
const URLPC = 'https://portalciudadano.manta.gob.ec/';
|
const URLPC = 'https://portalciudadano.manta.gob.ec/';
|
||||||
|
const API_TOKEN_PORTAL = 'de135b313b7f3b944090754470ecb67ea52987a1559dc92c734273c55bccfe9d';
|
||||||
// const URLPC = 'https://portalciudadano.manta.gob.ec/';
|
// const URLPC = 'https://portalciudadano.manta.gob.ec/';
|
||||||
const { WebhookClient } = require("dialogflow-fulfillment");
|
const { WebhookClient } = require("dialogflow-fulfillment");
|
||||||
|
|
||||||
@ -16,26 +17,26 @@ function conver_utf8(data) {
|
|||||||
function conver_name(data, recep = null) {
|
function conver_name(data, recep = null) {
|
||||||
try {
|
try {
|
||||||
var porciones = data.split(' ');
|
var porciones = data.split(' ');
|
||||||
if(porciones.length >= 2 && porciones.length <= 4){
|
if (porciones.length >= 2 && porciones.length <= 4) {
|
||||||
var cadena = new String(data);
|
var cadena = new String(data);
|
||||||
var accion = Math.floor(Math.random() * (1 - 4)) + 4;
|
var accion = Math.floor(Math.random() * (1 - 4)) + 4;
|
||||||
console.log('publico'+recep);
|
console.log('publico' + recep);
|
||||||
if(recep != null){ accion = recep; }
|
if (recep != null) { accion = recep; }
|
||||||
if(accion == 1){
|
if (accion == 1) {
|
||||||
cadena = porciones[(porciones.length -2)];
|
cadena = porciones[(porciones.length - 2)];
|
||||||
}else if(accion == 2){
|
} else if (accion == 2) {
|
||||||
cadena = porciones[(porciones.length -1)];
|
cadena = porciones[(porciones.length - 1)];
|
||||||
}else{
|
} else {
|
||||||
cadena = porciones[(porciones.length -2)]+ ' ' +porciones[(porciones.length -1)];
|
cadena = porciones[(porciones.length - 2)] + ' ' + porciones[(porciones.length - 1)];
|
||||||
}
|
}
|
||||||
cadena = cadena.toLowerCase();
|
cadena = cadena.toLowerCase();
|
||||||
return cadena.replace(/\w\S*/g, (w) => (w.replace(/^\w/, (c) => c.toUpperCase())));
|
return cadena.replace(/\w\S*/g, (w) => (w.replace(/^\w/, (c) => c.toUpperCase())));
|
||||||
}else{
|
} else {
|
||||||
var cadena = new String(data);
|
var cadena = new String(data);
|
||||||
cadena = cadena.toLowerCase();
|
cadena = cadena.toLowerCase();
|
||||||
return cadena.replace(/\w\S*/g, (w) => (w.replace(/^\w/, (c) => c.toUpperCase())));
|
return cadena.replace(/\w\S*/g, (w) => (w.replace(/^\w/, (c) => c.toUpperCase())));
|
||||||
}
|
}
|
||||||
}catch (error) {
|
} catch (error) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,43 +48,49 @@ function conver_capitalice(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function AxiosPOST(url, params){
|
function AxiosPOST(url, params, token = null) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
axios.post(URLPC+url, params).then(function (response) {
|
axios.post(URLPC + url, params,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
).then(function (response) {
|
||||||
resolve(response.data);
|
resolve(response.data);
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
resolve({'estado':false, 'data':[], 'msg':error});
|
resolve({ 'estado': false, 'data': [], 'msg': error });
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
resolve({'estado':false, 'data':[], 'msg':'Lo siento, no logre terminar de procesar la solicitúd'});
|
resolve({ 'estado': false, 'data': [], 'msg': 'Lo siento, no logre terminar de procesar la solicitúd' });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function AxiosGET(url, params, nweurl = null){
|
function AxiosGET(url, params, nweurl = null) {
|
||||||
if(nweurl == 'sistemasic'){
|
if (nweurl == 'sistemasic') {
|
||||||
url = URLIC + url;
|
url = URLIC + url;
|
||||||
}else{
|
} else {
|
||||||
url = URLPC + url;
|
url = URLPC + url;
|
||||||
}
|
}
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
axios.get(url, params).then(function (response) {
|
axios.get(url, params).then(function (response) {
|
||||||
resolve(response.data);
|
resolve(response.data);
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
resolve({'estado':false, 'data':[], 'msg':error});
|
resolve({ 'estado': false, 'data': [], 'msg': error });
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
resolve({'estado':false, 'data':[], 'msg':'Lo siento, no logre terminar de procesar la solicitúd'});
|
resolve({ 'estado': false, 'data': [], 'msg': 'Lo siento, no logre terminar de procesar la solicitúd' });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function ValidarSession(session){
|
async function ValidarSession(session) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var array = {'ok': false, 'data':[], 'msg':null};
|
var array = { 'ok': false, 'data': [], 'msg': null };
|
||||||
AxiosPOST('apidf_ValidarSessionDialog', {'session_id':session}).then(function (result) {
|
AxiosPOST('apidf_ValidarSessionDialog', { 'session_id': session }).then(function (result) {
|
||||||
if(result['estado']){
|
if (result['estado']) {
|
||||||
if(result['data']['session_id'] != undefined && result['data']['session_id'] != null){
|
if (result['data']['session_id'] != undefined && result['data']['session_id'] != null) {
|
||||||
array['ok'] = true; array['data'] = result['data']; array['msg'] = result['msg'];
|
array['ok'] = true; array['data'] = result['data']; array['msg'] = result['msg'];
|
||||||
}else{ array['msg'] = result['msg'] }
|
} else { array['msg'] = result['msg'] }
|
||||||
}else{ array['msg'] = result['msg'] }
|
} else { array['msg'] = result['msg'] }
|
||||||
resolve(array);
|
resolve(array);
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
array['msg'] = error;
|
array['msg'] = error;
|
||||||
@ -92,13 +99,13 @@ async function ValidarSession(session){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function CerrarSession(session){
|
async function CerrarSession(session) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var array = {'ok': false, 'data':[], 'msg':null};
|
var array = { 'ok': false, 'data': [], 'msg': null };
|
||||||
AxiosPOST('apidf_CerrarSessionDialog', {'session_id':session}).then(function (result) {
|
AxiosPOST('apidf_CerrarSessionDialog', { 'session_id': session }).then(function (result) {
|
||||||
if(result['estado']){
|
if (result['estado']) {
|
||||||
array['ok'] = true; array['msg'] = result['msg'];
|
array['ok'] = true; array['msg'] = result['msg'];
|
||||||
}else{ array['msg'] = result['msg'] }
|
} else { array['msg'] = result['msg'] }
|
||||||
resolve(array);
|
resolve(array);
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
array['msg'] = error;
|
array['msg'] = error;
|
||||||
@ -107,14 +114,14 @@ async function CerrarSession(session){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function RegistrarSession(session_id, cedula){
|
async function RegistrarSession(session_id, cedula) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var heders = {'cedula': cedula, 'name':cedula, 'session_id':session_id};
|
var heders = { 'cedula': cedula, 'name': cedula, 'session_id': session_id };
|
||||||
var array = {'ok': false, 'data':[], 'msg':null};
|
var array = { 'ok': false, 'data': [], 'msg': null };
|
||||||
AxiosPOST('apidf_RegistrarSessionDialog', heders).then(function (result) {
|
AxiosPOST('apidf_RegistrarSessionDialog', heders).then(function (result) {
|
||||||
if(result['estado']){
|
if (result['estado']) {
|
||||||
array['ok'] = true; array['data'] = result['data']; array['msg'] = result['msg'];
|
array['ok'] = true; array['data'] = result['data']; array['msg'] = result['msg'];
|
||||||
}else{ array['msg'] = result['msg'] }
|
} else { array['msg'] = result['msg'] }
|
||||||
resolve(array);
|
resolve(array);
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
array['msg'] = error;
|
array['msg'] = error;
|
||||||
@ -124,18 +131,18 @@ async function RegistrarSession(session_id, cedula){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function ValidarComprobante(codigo){
|
async function ValidarComprobante(codigo) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var heders = {'codigo': codigo};
|
var heders = { 'codigo': codigo };
|
||||||
var array = {'ok': false, 'data':[], 'msg':null};
|
var array = { 'ok': false, 'data': [], 'msg': null };
|
||||||
AxiosPOST('ws_validar_cod_barras', heders).then(function (result) {
|
AxiosPOST('ws_validar_cod_barras', heders).then(function (result) {
|
||||||
let claves=Object.keys(result);
|
let claves = Object.keys(result);
|
||||||
claves.forEach(element => {
|
claves.forEach(element => {
|
||||||
if(element == 'api'){
|
if (element == 'api') {
|
||||||
if(result['api']['ok']){
|
if (result['api']['ok']) {
|
||||||
array['ok'] = true; array['data'] = result['api']; array['msg'] = 'Busquera exitosa';
|
array['ok'] = true; array['data'] = result['api']; array['msg'] = 'Busquera exitosa';
|
||||||
}else{ array['msg'] = result['api']['msg'] != undefined ? result['api']['msg'] : ['Documento no encontrado'];}
|
} else { array['msg'] = result['api']['msg'] != undefined ? result['api']['msg'] : ['Documento no encontrado']; }
|
||||||
}else{
|
} else {
|
||||||
array['msg'] = ['Documento no encontrado'];
|
array['msg'] = ['Documento no encontrado'];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -148,22 +155,21 @@ async function ValidarComprobante(codigo){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function ConsultaClaves(cedula, chang = null){
|
async function ConsultaClaves(cedula, chang = null) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var array = {'ok': false, 'data':[], 'msg':null};
|
var array = { 'ok': false, 'data': [], 'msg': null };
|
||||||
var _ur = 'consulta_predios_detalle/2/'+cedula+'?boot=true';
|
var _ur = 'consulta_predios_detalle/2/' + cedula + '?boot=true';
|
||||||
if(chang != null){
|
if (chang != null) {
|
||||||
var _ur = 'consulta_predios_detalle/1/'+cedula+'?boot=true';
|
var _ur = 'consulta_predios_detalle/1/' + cedula + '?boot=true';
|
||||||
}
|
}
|
||||||
console.log(_ur);
|
AxiosPOST(_ur, {}, API_TOKEN_PORTAL).then(function (result) {
|
||||||
AxiosPOST(_ur, {}).then(function (result) {
|
|
||||||
console.log(result);
|
console.log(result);
|
||||||
if(result['ok']){
|
if (result['ok']) {
|
||||||
array['ok'] = true;
|
array['ok'] = true;
|
||||||
array['data'] = result['data_bot'];
|
array['data'] = result['data_bot'];
|
||||||
array['msg'] = 'Consulta exitosa procedura';
|
array['msg'] = 'Consulta exitosa procedura';
|
||||||
}else{
|
} else {
|
||||||
array['msg'] = result['message'];
|
array['msg'] = result['message'];
|
||||||
}
|
}
|
||||||
// if(result['ok'] && result['data_bot']['data'].length > 0){
|
// if(result['ok'] && result['data_bot']['data'].length > 0){
|
||||||
// array['ok'] = true; array['data'] = result['data_bot']['data']; array['msg'] = 'Consulta exitosa';
|
// array['ok'] = true; array['data'] = result['data_bot']['data']; array['msg'] = 'Consulta exitosa';
|
||||||
@ -182,13 +188,13 @@ async function ConsultaClaves(cedula, chang = null){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function ConsultaComprobantes(cedula, index){
|
async function ConsultaComprobantes(cedula, index) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var array = {'ok': false, 'data':[], 'msg':null};
|
var array = { 'ok': false, 'data': [], 'msg': null };
|
||||||
AxiosGET('portalciudadano/serviciosdigitales/mis_pagos?index='+index+'&cedula='+cedula+'&keypass=U2lzdGVtYXNJQ1NlcnZpY2VfbXJj', {}).then(function (result) {
|
AxiosGET('portalciudadano/serviciosdigitales/mis_pagos?index=' + index + '&cedula=' + cedula + '&keypass=U2lzdGVtYXNJQ1NlcnZpY2VfbXJj', {}).then(function (result) {
|
||||||
if(result['ok'] && result['data'].length > 0){
|
if (result['ok'] && result['data'].length > 0) {
|
||||||
array['ok'] = true; array['data'] = result['data']; array['msg'] = 'Consulta exitosa';
|
array['ok'] = true; array['data'] = result['data']; array['msg'] = 'Consulta exitosa';
|
||||||
}else{ array['msg'] = 'No se encontró comprobantes de pago a su nombre'; }
|
} else { array['msg'] = 'No se encontró comprobantes de pago a su nombre'; }
|
||||||
resolve(array);
|
resolve(array);
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
array['msg'] = error;
|
array['msg'] = error;
|
||||||
@ -198,13 +204,13 @@ async function ConsultaComprobantes(cedula, index){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function ConsultaNoticias(){
|
async function ConsultaNoticias() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var array = {'ok': false, 'data':[], 'msg':null};
|
var array = { 'ok': false, 'data': [], 'msg': null };
|
||||||
AxiosGET('consultarPublicaciones?boot=c', {}, 'sistemasic').then(function (result) {
|
AxiosGET('consultarPublicaciones?boot=c', {}, 'sistemasic').then(function (result) {
|
||||||
if(result['data'].length > 0){
|
if (result['data'].length > 0) {
|
||||||
array['ok'] = true; array['data'] = result['data']; array['msg'] = 'Consulta exitosa';
|
array['ok'] = true; array['data'] = result['data']; array['msg'] = 'Consulta exitosa';
|
||||||
}else{ array['msg'] = 'No se encontró resultados'; }
|
} else { array['msg'] = 'No se encontró resultados'; }
|
||||||
resolve(array);
|
resolve(array);
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
array['msg'] = error;
|
array['msg'] = error;
|
||||||
@ -214,14 +220,14 @@ async function ConsultaNoticias(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function OptInfoBot(key_inf){
|
async function OptInfoBot(key_inf) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var heders = {'info_key': key_inf};
|
var heders = { 'info_key': key_inf };
|
||||||
var array = {'ok': false, 'data':[], 'msg':null};
|
var array = { 'ok': false, 'data': [], 'msg': null };
|
||||||
AxiosPOST('api/InfoBootService', heders).then(function (result) {
|
AxiosPOST('api/InfoBootService', heders).then(function (result) {
|
||||||
if(result['ok']){
|
if (result['ok']) {
|
||||||
array['ok'] = true; array['data'] = result['data']; array['msg'] = result['msg'];
|
array['ok'] = true; array['data'] = result['data']; array['msg'] = result['msg'];
|
||||||
}else{ array['msg'] = result['msg'] }
|
} else { array['msg'] = result['msg'] }
|
||||||
resolve(array);
|
resolve(array);
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
array['msg'] = error;
|
array['msg'] = error;
|
||||||
@ -231,14 +237,14 @@ async function OptInfoBot(key_inf){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Consulta mis tramites solicitados
|
//Consulta mis tramites solicitados
|
||||||
async function GetMisTramites(key_cedula){
|
async function GetMisTramites(key_cedula) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var heders = {};
|
var heders = {};
|
||||||
var array = {'ok': false, 'data':[], 'msg':null};
|
var array = { 'ok': false, 'data': [], 'msg': null };
|
||||||
AxiosGET('tramites/web_api_consulta_tramite?tipo=1&code=true&valor='+key_cedula, heders).then(function (result) {
|
AxiosGET('tramites/web_api_consulta_tramite?tipo=1&code=true&valor=' + key_cedula, heders).then(function (result) {
|
||||||
if(result['estado']){
|
if (result['estado']) {
|
||||||
array['ok'] = true; array['data'] = result['data']; array['msg'] = result['msg'];
|
array['ok'] = true; array['data'] = result['data']; array['msg'] = result['msg'];
|
||||||
}else{ array['msg'] = result['msg'] }
|
} else { array['msg'] = result['msg'] }
|
||||||
resolve(array);
|
resolve(array);
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
array['msg'] = error;
|
array['msg'] = error;
|
||||||
@ -251,14 +257,14 @@ async function GetMisTramites(key_cedula){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Consulta historial de tramites solicitados
|
//Consulta historial de tramites solicitados
|
||||||
async function GetHistorialTramites(key_cedula, index){
|
async function GetHistorialTramites(key_cedula, index) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var heders = {};
|
var heders = {};
|
||||||
var array = {'ok': false, 'data':[], 'tramite':null, 'msg':null};
|
var array = { 'ok': false, 'data': [], 'tramite': null, 'msg': null };
|
||||||
AxiosGET('tramites/resolver_index_tramite?tipo=1&code=true&index='+index+'&valor='+key_cedula, heders).then(function (result) {
|
AxiosGET('tramites/resolver_index_tramite?tipo=1&code=true&index=' + index + '&valor=' + key_cedula, heders).then(function (result) {
|
||||||
if(result['estado']){
|
if (result['estado']) {
|
||||||
array['ok'] = true; array['data'] = result['data']; array['msg'] = result['msg']; array['tramite'] = result['tramite'];
|
array['ok'] = true; array['data'] = result['data']; array['msg'] = result['msg']; array['tramite'] = result['tramite'];
|
||||||
}else{ array['msg'] = result['msg'] }
|
} else { array['msg'] = result['msg'] }
|
||||||
resolve(array);
|
resolve(array);
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
array['msg'] = error;
|
array['msg'] = error;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user