mirror of
https://github.com/cheveguerra/bot-whatsapp.git
synced 2026-04-17 19:26:23 +00:00
docs(example): example bot
This commit is contained in:
@@ -1,68 +0,0 @@
|
||||
```js
|
||||
|
||||
const { inout, provider, database } = require('@bot-whatsapp')
|
||||
|
||||
|
||||
const adapterDB = database.instance(
|
||||
{
|
||||
engine:'mysql / pg / mongo / json (json-default)',
|
||||
credentials:{....}
|
||||
}
|
||||
)
|
||||
|
||||
const adapterProvider = provider.instance(
|
||||
{
|
||||
vendor:'twilio / web / meta',
|
||||
credentials:{...}
|
||||
}
|
||||
)
|
||||
|
||||
const adapterFlow = (() => {
|
||||
const flowA = inout
|
||||
.addKeyword('hola')
|
||||
.addAnswer('Bienvenido a tu tienda 🥲')
|
||||
.addAnswer('escribe *catalogo* o *ofertas*')
|
||||
.toJson()
|
||||
|
||||
const flowB = inout
|
||||
.addKeyword(['catalogo', 'ofertas'])
|
||||
.addAnswer('Este es nuestro CATALOGO mas reciente!', {
|
||||
buttons: [{ body: 'Xiaomi' }, { body: 'Samsung' }],
|
||||
}).toJson()
|
||||
|
||||
const flowC = inout
|
||||
.addKeyword('Xiaomi')
|
||||
.addAnswer('Estos son nuestro productos XIAOMI ....', {
|
||||
media: 'https://....',
|
||||
})
|
||||
.addAnswer('Si quieres mas info escrbie *info*').toJson()
|
||||
|
||||
const flowD = inout
|
||||
.addKeyword('chao!')
|
||||
.addAnswer('bye!')
|
||||
.addAnswer('Recuerda que tengo esta promo', {
|
||||
media: 'https://media2.giphy.com/media/VQJu0IeULuAmCwf5SL/giphy.gif',
|
||||
}).toJson()
|
||||
|
||||
const flowE = inout
|
||||
.addKeyword('Modelo C', { sensitive: false })
|
||||
.addAnswer('100USD', { media: 'http//:...' }).toJson()
|
||||
|
||||
return [...flowA, ...flowB, ...flowC, ...flowC, ...flowD, ...flowE]
|
||||
})
|
||||
|
||||
|
||||
const bot = await provider.start(
|
||||
{
|
||||
database: adapterDB,
|
||||
flow: adapterFlow,
|
||||
provider:adapterProvider
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
bot.on('message | auth | auth_error ', (ctx) => {
|
||||
....
|
||||
})
|
||||
|
||||
```
|
||||
@@ -4,9 +4,6 @@
|
||||
"description": "Esto es el conector a Twilio, Meta, etc...",
|
||||
"main": "./lib/mock/index.cjs",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"test.unit": "cross-env NODE_ENV=test node ../../node_modules/uvu/bin.js tests"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
@@ -14,9 +11,9 @@
|
||||
"@bot-whatsapp/bot": "*",
|
||||
"qr-image": "^3.2.0"
|
||||
},
|
||||
"files": [
|
||||
"./lib/mock/*",
|
||||
"./lib/twilio/*",
|
||||
"./lib/web-whatsapp/*"
|
||||
]
|
||||
"exports": {
|
||||
"./mock": "./lib/mock/index.cjs",
|
||||
"./twilio": "./lib/twilio/index.cjs",
|
||||
"./web-whatsapp": "./lib/web-whatsapp/index.cjs"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ const commonjs = require('@rollup/plugin-commonjs')
|
||||
|
||||
module.exports = [
|
||||
{
|
||||
input: join(__dirname, 'web-whatsapp', 'index.js'),
|
||||
input: join(__dirname, 'src', 'web-whatsapp', 'index.js'),
|
||||
output: {
|
||||
file: join(__dirname, 'lib', 'web-whatsapp', 'index.cjs'),
|
||||
format: 'cjs',
|
||||
@@ -11,7 +11,7 @@ module.exports = [
|
||||
plugins: [commonjs()],
|
||||
},
|
||||
{
|
||||
input: join(__dirname, 'twilio', 'index.js'),
|
||||
input: join(__dirname, 'src', 'twilio', 'index.js'),
|
||||
output: {
|
||||
file: join(__dirname, 'lib', 'twilio', 'index.cjs'),
|
||||
format: 'cjs',
|
||||
@@ -19,7 +19,7 @@ module.exports = [
|
||||
plugins: [commonjs()],
|
||||
},
|
||||
{
|
||||
input: join(__dirname, 'mock', 'index.js'),
|
||||
input: join(__dirname, 'src', 'mock', 'index.js'),
|
||||
output: {
|
||||
file: join(__dirname, 'lib', 'mock', 'index.cjs'),
|
||||
format: 'cjs',
|
||||
|
||||
Reference in New Issue
Block a user