forked from codigoencasa/builderbot
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(provider): new provider - venon:zap: configuracion inicial provi…
feat(provider): new provider - venon:zap: configuracion inicial provi…
- Loading branch information
Showing
16 changed files
with
774 additions
and
466 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const { ProviderClass } = require('@bot-whatsapp/bot') | ||
const venom = require('venom-bot') | ||
const { cleanNumber } = require('./utils/utils') | ||
|
||
class VenomProvider extends ProviderClass { | ||
constructor() { | ||
super() | ||
this.vendor | ||
venom | ||
.create( | ||
{ | ||
session: 'session-1', //nombre de la sesion o id | ||
multidevice: true, | ||
}, | ||
(base64Qrimg) => this.generateQr(base64Qrimg) | ||
) | ||
.then((client) => { | ||
this.vendor = client | ||
this.start() | ||
}) | ||
.catch((erro) => { | ||
console.log(erro) | ||
}) | ||
} | ||
|
||
generateQr = () => { | ||
this.emit('require_action', { | ||
instructions: [ | ||
`Debes escanear el QR Code para iniciar session reivsa qr.svg`, | ||
`Recuerda que el QR se actualiza cada minuto `, | ||
`Necesitas ayuda: https://link.codigoencasa.com/DISCORD`, | ||
], | ||
}) | ||
//generateImage(qr) | ||
} | ||
|
||
start = () => { | ||
this.vendor.onMessage((payload) => { | ||
payload.from = cleanNumber(payload.from, true) | ||
this.emit('message', payload) | ||
}) | ||
} | ||
|
||
sendMessage = async (userId, message, { options }) => { | ||
console.log('entramos') | ||
const number = cleanNumber(userId) | ||
if (options?.buttons?.length) | ||
return this.sendButtons(number, message, options.buttons) | ||
if (options?.media) return this.sendMedia(number, options.media) | ||
return this.vendor.sendText(number, message) | ||
} | ||
} | ||
|
||
module.exports = VenomProvider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const qr = require('qr-image') | ||
const { createWriteStream } = require('fs') | ||
|
||
const cleanNumber = (number, full = false) => { | ||
number = number.replace('@c.us', '') | ||
number = !full ? `${number}@c.us` : `${number}` | ||
return number | ||
} | ||
|
||
const generateImage = (base64) => { | ||
let qr_svg = qr.image(base64, { type: 'svg', margin: 4 }) | ||
qr_svg.pipe(createWriteStream(`${process.cwd()}/qr.svg`)) | ||
} | ||
|
||
module.exports = { cleanNumber, generateImage } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
### BASE APP | ||
|
||
Este bot contiene un flujo basico en el cual una persona (cliente) escribe **"hola"** y el bot responde. | ||
- Bienvenido a mi tienda | ||
- Como puedo ayudarte? | ||
- Tengo: Zapatos Bolsos etc.. | ||
|
||
------ | ||
- [Discord](https://link.codigoencasa.com/DISCORD) | ||
- [Twitter](https://twitter.com/leifermendez) | ||
- [Youtube](https://www.youtube.com/watch?v=5lEMCeWEJ8o&list=PL_WGMLcL4jzWPhdhcUyhbFU6bC0oJd2BR) | ||
- [Telegram](https://t.me/leifermendez) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const { | ||
createBot, | ||
createProvider, | ||
createFlow, | ||
addKeyword, | ||
} = require('@bot-whatsapp/bot') | ||
|
||
const WebWhatsappProvider = require('@bot-whatsapp/provider/venom') | ||
const MockAdapter = require('@bot-whatsapp/database/mock') | ||
|
||
const flowPrincipal = addKeyword(['hola', 'ole', 'HOLA']) | ||
.addAnswer('Bienvenido a mi tienda') | ||
.addAnswer('Como puedo ayudarte?') | ||
.addAnswer(['Tengo:', 'Zapatos', 'Bolsos', 'etc..']) | ||
|
||
const main = async () => { | ||
const adapterDB = new MockAdapter() | ||
const adapterFlow = createFlow([flowPrincipal]) | ||
const adapterProvider = createProvider(WebWhatsappProvider) | ||
|
||
createBot({ | ||
flow: adapterFlow, | ||
provider: adapterProvider, | ||
database: adapterDB, | ||
}) | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "bot-whatsapp-base", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "app.js", | ||
"scripts": { | ||
"pre-copy": "cd .. && yarn run copy.lib base-venom-mysql", | ||
"start": "node app.js" | ||
}, | ||
"keywords": [], | ||
"dependencies": { | ||
"venom-bot": "^4.3.7", | ||
"@bot-whatsapp/bot": "latest", | ||
"@bot-whatsapp/cli": "latest", | ||
"@bot-whatsapp/database": "latest", | ||
"@bot-whatsapp/provider": "latest" | ||
}, | ||
"author": "", | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
### BASE APP | ||
|
||
Este bot contiene un flujo basico en el cual una persona (cliente) escribe **"hola"** y el bot responde. | ||
- Bienvenido a mi tienda | ||
- Como puedo ayudarte? | ||
- Tengo: Zapatos Bolsos etc.. | ||
|
||
------ | ||
- [Discord](https://link.codigoencasa.com/DISCORD) | ||
- [Twitter](https://twitter.com/leifermendez) | ||
- [Youtube](https://www.youtube.com/watch?v=5lEMCeWEJ8o&list=PL_WGMLcL4jzWPhdhcUyhbFU6bC0oJd2BR) | ||
- [Telegram](https://t.me/leifermendez) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const { | ||
createBot, | ||
createProvider, | ||
createFlow, | ||
addKeyword, | ||
} = require('@bot-whatsapp/bot') | ||
|
||
const WebWhatsappProvider = require('@bot-whatsapp/provider/venom') | ||
const MockAdapter = require('@bot-whatsapp/database/mock') | ||
|
||
const flowPrincipal = addKeyword(['hola', 'ole', 'HOLA']) | ||
.addAnswer('Bienvenido a mi tienda') | ||
.addAnswer('Como puedo ayudarte?') | ||
.addAnswer(['Tengo:', 'Zapatos', 'Bolsos', 'etc..']) | ||
|
||
const main = async () => { | ||
const adapterDB = new MockAdapter() | ||
const adapterFlow = createFlow([flowPrincipal]) | ||
const adapterProvider = createProvider(WebWhatsappProvider) | ||
|
||
createBot({ | ||
flow: adapterFlow, | ||
provider: adapterProvider, | ||
database: adapterDB, | ||
}) | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "bot-whatsapp-base", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "app.js", | ||
"scripts": { | ||
"pre-copy": "cd .. && yarn run copy.lib base-venom-mysql", | ||
"start": "node app.js" | ||
}, | ||
"keywords": [], | ||
"dependencies": { | ||
"venom-bot": "^4.3.7", | ||
"@bot-whatsapp/bot": "latest", | ||
"@bot-whatsapp/cli": "latest", | ||
"@bot-whatsapp/database": "latest", | ||
"@bot-whatsapp/provider": "latest" | ||
}, | ||
"author": "", | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
### BASE APP | ||
|
||
Este bot contiene un flujo basico en el cual una persona (cliente) escribe **"hola"** y el bot responde. | ||
- Bienvenido a mi tienda | ||
- Como puedo ayudarte? | ||
- Tengo: Zapatos Bolsos etc.. | ||
|
||
------ | ||
- [Discord](https://link.codigoencasa.com/DISCORD) | ||
- [Twitter](https://twitter.com/leifermendez) | ||
- [Youtube](https://www.youtube.com/watch?v=5lEMCeWEJ8o&list=PL_WGMLcL4jzWPhdhcUyhbFU6bC0oJd2BR) | ||
- [Telegram](https://t.me/leifermendez) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const { | ||
createBot, | ||
createProvider, | ||
createFlow, | ||
addKeyword, | ||
} = require('@bot-whatsapp/bot') | ||
|
||
const WebWhatsappProvider = require('@bot-whatsapp/provider/venom') | ||
const MockAdapter = require('@bot-whatsapp/database/mock') | ||
|
||
const flowPrincipal = addKeyword(['hola', 'ole', 'HOLA']) | ||
.addAnswer('Bienvenido a mi tienda') | ||
.addAnswer('Como puedo ayudarte?') | ||
.addAnswer(['Tengo:', 'Zapatos', 'Bolsos', 'etc..']) | ||
|
||
const main = async () => { | ||
const adapterDB = new MockAdapter() | ||
const adapterFlow = createFlow([flowPrincipal]) | ||
const adapterProvider = createProvider(WebWhatsappProvider) | ||
|
||
createBot({ | ||
flow: adapterFlow, | ||
provider: adapterProvider, | ||
database: adapterDB, | ||
}) | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "bot-whatsapp-base", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "app.js", | ||
"scripts": { | ||
"pre-copy": "cd .. && yarn run copy.lib base-venom-mysql", | ||
"start": "node app.js" | ||
}, | ||
"keywords": [], | ||
"dependencies": { | ||
"venom-bot": "^4.3.7", | ||
"@bot-whatsapp/bot": "latest", | ||
"@bot-whatsapp/cli": "latest", | ||
"@bot-whatsapp/database": "latest", | ||
"@bot-whatsapp/provider": "latest" | ||
}, | ||
"author": "", | ||
"license": "ISC" | ||
} |
Oops, something went wrong.