From ffe63c2ec454502cd7baf63d685b8f77f3a4f2e7 Mon Sep 17 00:00:00 2001 From: cheveguerra Date: Sat, 18 Feb 2023 10:40:32 -0600 Subject: [PATCH] un poco de organizacion --- app.js | 142 ++------------------------------- implementaciones/extraFuncs.js | 122 ++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 137 deletions(-) diff --git a/app.js b/app.js index cf6debf..3b283bf 100644 --- a/app.js +++ b/app.js @@ -6,7 +6,7 @@ global.provider = process.env.PROVIDER || 'wwebjs'; const fs = require('fs'); global.siguientePaso = [{"numero":"1", "va":"XXX"}]; //MOD by CHV - Agregamos para pasar el VAMOSA a "index.js" global.pasoAnterior = []; -const axios = require('axios').default;//MOD by CHV - Agregamos para el get del "/URL" +const axios = require('axios').default; const { List } = require('whatsapp-web.js'); // const mysqlConnection = require('./config/mysql') const { initBot, traeVariables } = require(`./provider/${provider}`) @@ -16,8 +16,8 @@ const { getMessages, responseMessages, bothResponse, waitFor } = require('./cont const { sendMedia, sendMessage, sendMessageButton, sendMessageList, readChat } = require(`./controllers/send_${provider}`); const { stepsInitial, vamosA, traeUltimaVisita } = require('./adapter/index');//MOD by CHV - Agregamos para utilizar remplazos y stepsInitial const { removeDiacritics, getRandomInt, remplazos, soloNumero, agregaVars } = require('./implementaciones/extraFuncs') -const { guardaXLSDatos, leeXLSDatos} = require('./Excel'); -const { ingresarDatos, leerDatos } = require('./implementaciones/sheets') +// const { guardaXLSDatos, leeXLSDatos} = require('./Excel'); +// const { ingresarDatos, leerDatos } = require('./implementaciones/sheets') const MULTI_DEVICE = process.env.MULTI_DEVICE || 'true'; const delay = (ms) => new Promise((resolve) => setTimeout(resolve,ms)) let client @@ -39,7 +39,7 @@ function listenMessage(client){ if(provider == 'wwebjs'){ msg.type = 'notify' } if (vars[from] === undefined) vars[from] = [] // Este bug lo reporto Lucas Aldeco Brescia para evitar que se publiquen estados - if (from === 'status@broadcast' || msg.type !== 'notify') { console.log("########### status@broadcast o tipo mensaje = ", msg.type); return } + if (from === 'status@broadcast' || msg.type !== 'notify') { console.log("++++++ status@broadcast o tipo mensaje = ", msg.type); return } console.log("+++++++++++++++++++++++++++++++++++++ INICIO +++++++++++++++++++++++++++++++++++++++"); console.log("HORA:"+new Date().toLocaleTimeString()+" FROM:"+from+", BODY:"+body+", HASMEDIA:"+hasMedia+", DEVICETYPE:"+client.theMsg?.deviceType); // * Numero NO válido. @@ -57,10 +57,7 @@ function listenMessage(client){ /** * Si el mensaje trae un archivo multimedia, aquí lo guardamos. */ - if (process.env.SAVE_MEDIA === 'true' && hasMedia) { - const media = await msg.downloadMedia(); - saveMedia(media); - } + if (process.env.SAVE_MEDIA === 'true' && hasMedia) { const media = await msg.downloadMedia(); saveMedia(media); } // Guardamos los mensajes entrantes en una hoja de Google Sheets // ingresarDatos(from, body, 'Entrada', 'Bot Pruebas') @@ -95,60 +92,6 @@ function listenMessage(client){ return } - if(body == "/botones"){ - // Asi se mandan botones **directamente** con el cliente de whatsapp-web.js "client.sendMessage(from, productList)" - const buttonMessage = [ - {"body":"boton 1"}, - {"body":"boton 2"} - ] - const ab = { - "title":"¿Que te interesa ver?", - "message":"%saludo%\nHoy es %dia_semana%.\nSon las %hora24%:%minutos% hrs.\nSon las %hora12%:%minutos% %ampm%\n*Palabra random:* %rnd_arbol,burro,cabra,dinosaurio,elefante,fuego,gorila%\n*Emoji random:* %rnd_👍🏽,😁,🤣,🤔,🤦🏽‍♂️,🙄,😎%\n*Número random:* %rnd_1,2,3,4,5,6,7%\n", - "footer":"Gracias", - "buttons":[ - {"body":"Cursos"}, - {"body":"Youtube"}, - {"body":"Telegram"} - ] - } - console.log("Enviamos botones = ", from, ab) - sendMessageButton(client, from, "texto", ab) - } - - if(body=='/listas'){ - // Asi se mandan **listas** directamente con el ciente de whatsapp-web.js "client.sendMessage(from, productList)" - const productList = new List( - "Here's our list of products at 50% off", - "View all products", - [ - { - title: "Products list", - rows: [ - { id: "apple", title: "Apple" }, - { id: "mango", title: "Mango" }, - { id: "banana", title: "Banana" }, - ], - }, - ], - "Please select a product" - ); - console.log('##################################################################################################') - console.log("****************** productList ******************") - console.log(productList) - client.sendMessage(from, productList); - // Asi se manda directamente con la funcion del bot. "sendMessageList(client, from, null, lista)" - // let sections = [ - // { title:'sectionTitle', - // rows:[ - // {id:'ListItem1', title: 'title1'}, - // {id:'ListItem2', title:'title2'} - // ] - // } - // ]; - // let lista = new List('List body','btnText',sections,'Title','footer'); - await sendMessageList(client, from, null, productList); //sendMessageList recibe el arreglo CON nombres, tal cual se usa en "response.json" - } - /** * Si el texto del mensaje dispara alguna regla, entramos a esta condición. */ @@ -166,72 +109,6 @@ function listenMessage(client){ // ############################## INICIAN FUNCIONES PERSONALIZADAS ##################################### // ############################################################################################################ - /** - * Trae información desde un archivo de excel y le manda a cada número un mensaje. (Envío masivo) - */ - if(body=='traeXLS'){ - const rows = await leeXLSDatos('x') - console.log("RESULTADOS:") - function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)) } - async function retardo() { - for (sp=1;sp setTimeout(resolve, ms)); - } - async function retardo() { - for (sp=0;sp setTimeout(resolve, ms)) } + async function retardo() { + for (sp=1;sp setTimeout(resolve, ms)); + } + async function retardo() { + for (sp=0;sp