mirror of
https://github.com/cheveguerra/botLeiferAurik-Mod_2.0.git
synced 2026-04-20 20:59:19 +00:00
Varios
This commit is contained in:
6
.env
6
.env
@@ -1,5 +1,5 @@
|
|||||||
######DATABASE: none, mysql, dialogflow
|
###### DATABASE: none, mysql, dialogflow
|
||||||
|
###### PROVIDER: wwebjs, baileys
|
||||||
DEFAULT_MESSAGE=false
|
DEFAULT_MESSAGE=false
|
||||||
SAVE_MEDIA=true
|
SAVE_MEDIA=true
|
||||||
PORT=3005
|
PORT=3005
|
||||||
@@ -13,4 +13,4 @@ KEEP_DIALOG_FLOW=false
|
|||||||
MULTI_DEVICE=true
|
MULTI_DEVICE=true
|
||||||
DIALOGFLOW_MEDIA_FOR_SLOT_FILLING=false
|
DIALOGFLOW_MEDIA_FOR_SLOT_FILLING=false
|
||||||
GDRIVE_FOLDER_ID=
|
GDRIVE_FOLDER_ID=
|
||||||
PROVIDER=wwebjs
|
PROVIDER=baileys
|
||||||
20
app.js
20
app.js
@@ -48,12 +48,28 @@ function listenMessage(client){
|
|||||||
else { client0 = client.ev; messageEV = 'messages.upsert' } // Usamos Baileys.
|
else { client0 = client.ev; messageEV = 'messages.upsert' } // Usamos Baileys.
|
||||||
client0.on(messageEV, async msg => {
|
client0.on(messageEV, async msg => {
|
||||||
if(provider == 'wwebjs'){ msg.type = 'notify' }
|
if(provider == 'wwebjs'){ msg.type = 'notify' }
|
||||||
const { from, body, name, hasMedia } = traeVariablesFromMsg(msg);
|
const { from, body, name, hasMedia, timestamp } = traeVariablesFromMsg(msg);
|
||||||
if (vars[from] === undefined) vars[from] = []
|
if (vars[from] === undefined) vars[from] = []
|
||||||
// Este bug lo reporto Lucas Aldeco Brescia para evitar que se publiquen estados.
|
// 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 }
|
||||||
|
if ((timestamp*1000) + (300000) < Date.now()) { console.log("Mensaje Viejo"); return }// Si el mensaje es mas viejo de 300 segundos no le hacemos caso!
|
||||||
console.log("+++++++++++++++++++++++++++++++++++++ INICIO +++++++++++++++++++++++++++++++++++++++");
|
console.log("+++++++++++++++++++++++++++++++++++++ INICIO +++++++++++++++++++++++++++++++++++++++");
|
||||||
console.log("HORA:"+new Date().toLocaleTimeString()+" FROM:"+from+", BODY:"+body+", HASMEDIA:"+hasMedia+", DEVICETYPE:"+client.theMsg?.deviceType);
|
console.log("HORA:" + new Date().toLocaleTimeString() + " FROM:" + from + ", BODY:" + body + ", HASMEDIA:" + hasMedia + ", DEVICETYPE:" + msg?.deviceType);
|
||||||
|
if(provider == 'baileys'){
|
||||||
|
console.log('---------------------------------------------------------------')
|
||||||
|
console.log(msg?.messages[0]?.message)
|
||||||
|
console.log('---------------------------------------------------------------')
|
||||||
|
console.log(msg?.messages[0]?.message?.extendedTextMessage?.text)
|
||||||
|
}
|
||||||
|
// console.log('---------------------------------------------------------------')
|
||||||
|
// if(provider == 'baileys') {verificado = await client.onWhatsApp('5215512345678@s.whatsapp.net')}
|
||||||
|
// else { verificado = await client.isRegisteredUser('5215512345678@c.us') }
|
||||||
|
// console.log('VERIFICADO1=', verificado)
|
||||||
|
// console.log('---------------------------------------------------------------')
|
||||||
|
// if(provider == 'baileys') {verificado = await client.onWhatsApp('5215554192439@s.whatsapp.net')}
|
||||||
|
// else { verificado = await client.isRegisteredUser('5215554192439@c.us') }
|
||||||
|
// console.log('VERIFICADO2=', verificado)
|
||||||
|
// console.log('---------------------------------------------------------------')
|
||||||
// * Numero NO válido.
|
// * Numero NO válido.
|
||||||
if(!isValidNumber(from)){ console.log("Número invalido"); return }
|
if(!isValidNumber(from)){ console.log("Número invalido"); return }
|
||||||
const number = soloNumero(from)
|
const number = soloNumero(from)
|
||||||
|
|||||||
@@ -215,15 +215,16 @@ function traeVariablesFromMsgBaileys(msg){
|
|||||||
let body = theBody
|
let body = theBody
|
||||||
let name = pushName
|
let name = pushName
|
||||||
let hasMedia = false
|
let hasMedia = false
|
||||||
|
let timestamp = msg.messages[0].messageTimestamp
|
||||||
// console.log("fromBody=", from, body, name)
|
// console.log("fromBody=", from, body, name)
|
||||||
return {"from":from, "body":body, "name":name, "hasMedia":hasMedia}
|
return {"from":from, "body":body, "name":name, "hasMedia":hasMedia, "timestamp":timestamp}
|
||||||
}
|
}
|
||||||
|
|
||||||
function traeVariablesFromMsgWWebJS(msg){
|
function traeVariablesFromMsgWWebJS(msg){
|
||||||
const { from, body, hasMedia } = msg;
|
const { from, body, hasMedia, timestamp } = msg;
|
||||||
let name = msg?._data?.notifyName
|
let name = msg?._data?.notifyName
|
||||||
// console.log("fromBody=", msg?._data)
|
// console.log("fromBody=", msg?._data)
|
||||||
return {"from":from, "body":body, "name":name, "hasMedia":hasMedia}
|
return {"from":from, "body":body, "name":name, "hasMedia":hasMedia, "timestamp":timestamp}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
962
package-lock.json
generated
962
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,7 @@
|
|||||||
const { MessageMedia, Client, LocalAuth, Buttons, List } = require('whatsapp-web.js');
|
const { MessageMedia, Client, LocalAuth, Buttons, List } = require('whatsapp-web.js');
|
||||||
const { sendMedia, sendMessage, sendMessageButton, sendMessageList, readChat } = require(`../controllers/send`);
|
const { sendMedia, sendMessage, sendMessageButton, sendMessageList, readChat } = require(`../controllers/send`);
|
||||||
const mime = require('mime-types')
|
const mime = require('mime-types')
|
||||||
|
// const mysqlConnection = require('./config/mysql')
|
||||||
require('dotenv').config()
|
require('dotenv').config()
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
@@ -51,15 +52,22 @@ initBot = async () => {
|
|||||||
client.on('authenticated', () => {
|
client.on('authenticated', () => {
|
||||||
console.log('AUTHENTICATED');
|
console.log('AUTHENTICATED');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
client.on('qr', qr => generateImage(qr, async () => {
|
||||||
|
qrcode.generate(qr, { small: true });
|
||||||
|
console.log(`Ver QR http://localhost:${port}/bot.qr.png`)
|
||||||
|
}))
|
||||||
|
|
||||||
|
|
||||||
client.initialize();
|
client.initialize();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verificamos si tienes un gesto de db
|
* Verificamos si tienes un gesto de db
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (process.env.DATABASE === 'mysql') {
|
if (process.env.DATABASE === 'mysql') {
|
||||||
mysqlConnection.connect()
|
mysqlConnection.connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
let waReady = false
|
let waReady = false
|
||||||
// Socket IO
|
// Socket IO
|
||||||
io.on('connection', async function (socket) {
|
io.on('connection', async function (socket) {
|
||||||
|
|||||||
Reference in New Issue
Block a user