This commit is contained in:
Leifer Mendez
2022-02-26 11:50:44 +01:00
parent 902431c533
commit d200100caa
10 changed files with 57 additions and 40 deletions

2
.gitignore vendored
View File

@@ -7,5 +7,5 @@ media/*
!media/.gitkeep
mediaSend/*
!mediaSend/.gitkeep
!mediaSend/PTT-20220223-WA0000.opus
!mediaSend/nota-de-voz.mp3
.env

1
app.js
View File

@@ -55,7 +55,6 @@ const listenMessage = () => client.on('message', async msg => {
const number = cleanNumber(from)
await readChat(number, message)
await sendMediaVoiceNote(client, from, 'PTT-20220223-WA0000.opus')
/**
* Guardamos el archivo multimedia que envia
*/

View File

@@ -1,5 +1,5 @@
const {get, reply, getIA} = require('../adapter')
const {saveExternalFile} = require('./handle')
const {saveExternalFile, checkIsUrl} = require('./handle')
const getMessages = async (message) => {
const data = await get(message)
@@ -9,7 +9,7 @@ const getMessages = async (message) => {
const responseMessages = async (step) => {
const data = await reply(step)
if(data && data.media){
const file = await saveExternalFile(data.media)
const file = checkIsUrl(data.media) ? await saveExternalFile(data.media) : data.media;
return {...data,...{media:file}}
}
return data

View File

@@ -31,6 +31,16 @@ const saveExternalFile = (url) => new Promise((resolve, reject) => {
});
})
const checkIsUrl = (path) => {
try{
regex = /^(http(s)?:\/\/)[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/i;
match = path.match(regex);
return match[0]
}catch(e){
return null
}
}
const generateImage = (base64, cb = () => {}) => {
let qr_svg = qr.image(base64, { type: 'svg', margin: 4 });
qr_svg.pipe(require('fs').createWriteStream('./mediaSend/qr-code.svg'));
@@ -39,4 +49,4 @@ const generateImage = (base64, cb = () => {}) => {
cb()
}
module.exports = {cleanNumber, saveExternalFile, generateImage}
module.exports = {cleanNumber, saveExternalFile, generateImage, checkIsUrl}

View File

@@ -18,7 +18,7 @@ const sendMedia = (client, number, fileName) => {
const file = `${DIR_MEDIA}/${fileName}`;
if (fs.existsSync(file)) {
const media = MessageMedia.fromFilePath(file);
client.sendMessage(number, media);
client.sendMessage(number, media, { sendAudioAsVoice: true });
}
}

View File

@@ -21,8 +21,7 @@
"keywords": [
"cursos",
"info",
"curso"
],
"curso" ],
"key": "STEP_2"
},
{
@@ -69,20 +68,26 @@
},
{
"keywords": [
"👉 Youtube"
"youtube"
],
"key": "STEP_5"
},
{
"keywords": [
"😎 Cursos"
"VER_CURSOS"
],
"key": "STEP_6"
},
{
"keywords": [
"😁 Telegram"
"telegram"
],
"key": "STEP_7"
},
{
"keywords": [
"audio"
],
"key": "STEP_8"
}
]

View File

@@ -1,21 +1,15 @@
{
"DEFAULT":{
"replyMessage":[
"🆗 Bienvenido a este 🤖 CHATBOT de Whatsapp, lo primero \n",
"decirte que mi nombre es *Leifer Mendez*😎 y te dejo opciones rapidas \n"
"*Esta respuesta es un respuesta default* cuando no se consigue una palabra clave \n",
"la puedes desactivar en tu archivo .env DEFAULT_MESSAGE=false \n",
"tambien te quiero recordar que si presentas algun error pasarte por el repositorio \n",
"https://github.com/leifermendez/bot-whatsapp#chatbot-whatsapp-opensource \n",
"y recuerda tener la ultima versión del proyecto \n\n",
"Prueba escribiendo *hola* \n"
],
"media":null,
"trigger":null,
"actions":{
"title":"¿Que te interesa ver?",
"message":"Recuerda todo este contenido es gratis y estaria genial que me siguas!",
"footer":"Gracias",
"buttons":[
{"body":"😎 Cursos"},
{"body":"👉 Youtube"},
{"body":"😁 Telegram"}
]
}
"trigger":null
},
"STEP_0":{
"replyMessage":[
@@ -28,10 +22,10 @@
},
"STEP_1":{
"replyMessage":[
"✌️ Bienvenido a este 🤖 CHATBOT de Whatsapp, lo primero \n",
"Hola! y✌️ Bienvenido a este 🤖 CHATBOT de Whatsapp, lo primero \n",
"decirte que mi nombre es *Leifer Mendez*😎 \n",
"\n Si necesitas ver más info sobre las capacitacion tecnicas ",
"escribe *cursos* o *info*"
"escribe *cursos* o *info* o escribe *audio*"
],
"media":null,
"trigger":null,
@@ -40,9 +34,9 @@
"message":"Recuerda todo este contenido es gratis y estaria genial que me siguas!",
"footer":"Gracias",
"buttons":[
{"body":"😎 Cursos"},
{"body":"👉 Youtube"},
{"body":"😁 Telegram"}
{"body":"Cursos"},
{"body":"Youtube"},
{"body":"Telegram"}
]
}
},
@@ -116,9 +110,10 @@
},
"STEP_5":{
"replyMessage":[
"Muy bien te comparto el canal de Youtube \n"
"Muy bien te comparto el canal de Youtube \n",
"https://youtube.com/leifermendez \n"
],
"media":"https://youtube.com/leifermendez",
"media":null,
"trigger":null
},
"STEP_6":{
@@ -137,9 +132,17 @@
},
"STEP_7":{
"replyMessage":[
"Vente al telegram \n"
"Vente al telegram \n",
"https://t.me/leifermendez \n"
],
"media":"https://t.me/leifermendez",
"media":null,
"trigger":null
},
"STEP_8":{
"replyMessage":[
"Esto es una nota de voz \n"
],
"media":"nota-de-voz.mp3",
"trigger":null
}
}

BIN
mediaSend/nota-de-voz.mp3 Normal file

Binary file not shown.

12
package-lock.json generated
View File

@@ -2977,9 +2977,9 @@
}
},
"puppeteer": {
"version": "13.3.2",
"resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-13.3.2.tgz",
"integrity": "sha512-TIt8/R0eaUwY1c0/O0sCJpSglvGEWVoWFfGZ2dNtxX3eHuBo1ln9abaWfxTjZfsrkYATLSs8oqEdRZpMNnCsvg==",
"version": "13.4.0",
"resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-13.4.0.tgz",
"integrity": "sha512-WrHtFF2WpYC6KWFP4OCPOHWCjW4f8tFk+FkYZeNQ8/lHn+asjXBEXiIWauune8CY2xIHBVExGas+WI6Ay8/MgQ==",
"requires": {
"cross-fetch": "3.1.5",
"debug": "4.3.3",
@@ -3696,9 +3696,9 @@
"integrity": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE="
},
"whatsapp-web.js": {
"version": "1.15.6",
"resolved": "https://registry.npmjs.org/whatsapp-web.js/-/whatsapp-web.js-1.15.6.tgz",
"integrity": "sha512-o5iKWd6KDMMxxL0VHM8Uk380D6elFY5d0THpgLN60IcCknyM4IXWtpbFHdrbDUXylnn8lFHiMf9w0hQSEhvfeQ==",
"version": "1.15.8",
"resolved": "https://registry.npmjs.org/whatsapp-web.js/-/whatsapp-web.js-1.15.8.tgz",
"integrity": "sha512-xbNKZb/7QhORU9I2iZ4acSxuhNAUx5riLckTLU+echc8XZan7cWbQuAr0Nzlrt2RKIpCyBfeH3vI6ZlMMApBRA==",
"requires": {
"@pedroslopez/moduleraid": "^5.0.2",
"fluent-ffmpeg": "^2.1.2",

View File

@@ -24,7 +24,7 @@
"qr-image": "^3.2.0",
"qrcode-terminal": "^0.12.0",
"socket.io": "^4.4.1",
"whatsapp-web.js": "^1.15.6",
"whatsapp-web.js": "^1.15.8",
"xlsx": "^0.16.9"
},
"devDependencies": {