mirror of
https://github.com/cheveguerra/bot-whatsapp.git
synced 2026-04-20 12:39:24 +00:00
refactor(io): added new method addChild
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -14,13 +14,16 @@ mediaSend/*
|
|||||||
.wwebjs_auth
|
.wwebjs_auth
|
||||||
packages/cli/config.json
|
packages/cli/config.json
|
||||||
config.json
|
config.json
|
||||||
|
.yarnrc.yml
|
||||||
coverage/
|
coverage/
|
||||||
*.lcov
|
*.lcov
|
||||||
log
|
log
|
||||||
lib
|
lib
|
||||||
tmp/
|
tmp/
|
||||||
.yarn/*
|
.yarn/*
|
||||||
|
!.yarn/releases
|
||||||
.fleet/
|
.fleet/
|
||||||
example-app/
|
example-app/
|
||||||
qr.svg
|
qr.svg
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
yarn-error.log
|
||||||
0
.husky/commit-msg
Normal file → Executable file
0
.husky/commit-msg
Normal file → Executable file
0
.husky/pre-commit
Normal file → Executable file
0
.husky/pre-commit
Normal file → Executable file
0
.husky/pre-push
Normal file → Executable file
0
.husky/pre-push
Normal file → Executable file
807
.yarn/releases/yarn-3.3.0.cjs
vendored
Normal file
807
.yarn/releases/yarn-3.3.0.cjs
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -1 +1,3 @@
|
|||||||
|
nodeLinker: node-modules
|
||||||
|
npmPublishRegistry: 'https://registry.npmjs.org'
|
||||||
yarnPath: .yarn/releases/yarn-3.3.0.cjs
|
yarnPath: .yarn/releases/yarn-3.3.0.cjs
|
||||||
|
|||||||
@@ -5,15 +5,44 @@ __Requerimientos:__
|
|||||||
- __[Yarn](https://classic.yarnpkg.com/lang/en/docs/install/#windows-stable)__ como gestor de paquetes. En el link conseguiras las intrucciones para instalar yarn.
|
- __[Yarn](https://classic.yarnpkg.com/lang/en/docs/install/#windows-stable)__ como gestor de paquetes. En el link conseguiras las intrucciones para instalar yarn.
|
||||||
- Se usara la rama __dev__ *(https://github.com/leifermendez/bot-whatsapp/tree/dev)* como rama principal hasta que se haga oficialmente el lanzamiento de la V2
|
- Se usara la rama __dev__ *(https://github.com/leifermendez/bot-whatsapp/tree/dev)* como rama principal hasta que se haga oficialmente el lanzamiento de la V2
|
||||||
|
|
||||||
__Clonar__
|
>💡 Se usa la version 3.3.0 o superior de Yarn para establecer esta version simplemente ejecuta el siguiente comando: `yarn set version 3.3.0`
|
||||||
```shell
|
|
||||||
|
__Clonar repo rama dev__
|
||||||
|
```
|
||||||
git clone --branch dev https://github.com/leifermendez/bot-whatsapp
|
git clone --branch dev https://github.com/leifermendez/bot-whatsapp
|
||||||
```
|
```
|
||||||
__Instalar dependencias__
|
__Instalar dependencias__
|
||||||
```shell
|
```
|
||||||
cd bot-whatsapp
|
cd bot-whatsapp
|
||||||
yarn
|
yarn set version 3.3.0
|
||||||
|
yarn install
|
||||||
```
|
```
|
||||||
|
> __ATENCIÓN__ Si esta estas en ubuntu/linux ejecutar lo siguiente comandos adicionales.
|
||||||
|
|
||||||
|
```sheell
|
||||||
|
npx husky install
|
||||||
|
chmod ug+x .husky/*
|
||||||
|
```
|
||||||
|
|
||||||
|
__Compilar (build)__
|
||||||
|
Para compilar la aplicación es necesario ejecutar, eso te genera dentro de packages del monorepo un directorio `lib`
|
||||||
|
|
||||||
|
```
|
||||||
|
yarn build
|
||||||
|
```
|
||||||
|
Luego de ejecutar el comando conseguiras algo como lo siguiente. Esas carpetas lib NO se suben al repo estan ignoradas.
|
||||||
|
```
|
||||||
|
packages/bot/lib
|
||||||
|
packages/cli/lib
|
||||||
|
packages/database/lib
|
||||||
|
packages/provider/lib
|
||||||
|
```
|
||||||
|
|
||||||
|
__Linking__
|
||||||
|
```
|
||||||
|
yarn link.dist
|
||||||
|
```
|
||||||
|
|
||||||
__Commit y Push__
|
__Commit y Push__
|
||||||
El proyecto tiene implementado __[husky](https://typicode.github.io/husky/#/)__ es una herramienta que dispara unas acciones al momento de hacer commit y hacer push
|
El proyecto tiene implementado __[husky](https://typicode.github.io/husky/#/)__ es una herramienta que dispara unas acciones al momento de hacer commit y hacer push
|
||||||
|
|
||||||
@@ -22,6 +51,13 @@ __commit:__ Los commit son semanticos esto quiere decir que deben cumplir un sta
|
|||||||
__push:__ Cada push ejecutar `yarn run test` el cual ejecuta los test internos que tienen que cumplir con __95% de cobertura__.
|
__push:__ Cada push ejecutar `yarn run test` el cual ejecuta los test internos que tienen que cumplir con __95% de cobertura__.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
__Example-app__
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
------
|
------
|
||||||
- [Discord](https://link.codigoencasa.com/DISCORD)
|
- [Discord](https://link.codigoencasa.com/DISCORD)
|
||||||
- [Twitter](https://twitter.com/leifermendez)
|
- [Twitter](https://twitter.com/leifermendez)
|
||||||
|
|||||||
1
TODO.md
1
TODO.md
@@ -29,3 +29,4 @@
|
|||||||
- [ ] Meta adapter
|
- [ ] Meta adapter
|
||||||
|
|
||||||
### @bot-whatsapp/cli
|
### @bot-whatsapp/cli
|
||||||
|
- [ ] Hacer comando para crear `example-app`
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
"lint:check": "eslint ./packages",
|
"lint:check": "eslint ./packages",
|
||||||
"lint:fix": "eslint --fix ./packages",
|
"lint:fix": "eslint --fix ./packages",
|
||||||
"build": "yarn run cli:rollup && yarn run bot:rollup && yarn run provider:rollup && yarn run database:rollup",
|
"build": "yarn run cli:rollup && yarn run bot:rollup && yarn run provider:rollup && yarn run database:rollup",
|
||||||
"link.dist": "cd packages/bot && npm link && cd ../provider && npm link && cd ../cli && npm link",
|
"link.dist": "cd packages/bot && npm link && cd ../provider && npm link && cd ../cli && npm link && cd ../database && npm link && cd ../provider && npm link",
|
||||||
"test.unit": "node ./node_modules/uvu/bin.js packages test",
|
"test.unit": "node ./node_modules/uvu/bin.js packages test",
|
||||||
"test.coverage": "node ./node_modules/c8/bin/c8.js npm run test.unit",
|
"test.coverage": "node ./node_modules/c8/bin/c8.js npm run test.unit",
|
||||||
"test": "npm run test.coverage",
|
"test": "npm run test.coverage",
|
||||||
@@ -24,6 +24,7 @@
|
|||||||
"dev": "node ./example-app/app.js",
|
"dev": "node ./example-app/app.js",
|
||||||
"prepare": "npx husky install",
|
"prepare": "npx husky install",
|
||||||
"preinstall": "npx only-allow yarn",
|
"preinstall": "npx only-allow yarn",
|
||||||
|
"postinstall": "npx prettier --write .",
|
||||||
"release": "standard-version"
|
"release": "standard-version"
|
||||||
},
|
},
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
@@ -81,7 +82,7 @@
|
|||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16",
|
"node": ">=16",
|
||||||
"npm": "please-use-yarn",
|
"npm": "please-use-yarn",
|
||||||
"yarn": ">=1"
|
"yarn": ">=3"
|
||||||
},
|
},
|
||||||
"author": "Leifer Mendez <leifer33@gmail.com>",
|
"author": "Leifer Mendez <leifer33@gmail.com>",
|
||||||
"config": {
|
"config": {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const CoreClass = require('./core/core.class')
|
const CoreClass = require('./core/core.class')
|
||||||
const ProviderClass = require('./provider/provider.class')
|
const ProviderClass = require('./provider/provider.class')
|
||||||
const FlowClass = require('./io/flow.class')
|
const FlowClass = require('./io/flow.class')
|
||||||
const { addKeyword, addAnswer, toSerialize } = require('./io/methods')
|
const { addKeyword, addAnswer, addChild, toSerialize } = require('./io/methods')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Crear instancia de clase Bot
|
* Crear instancia de clase Bot
|
||||||
@@ -38,6 +38,7 @@ module.exports = {
|
|||||||
createProvider,
|
createProvider,
|
||||||
addKeyword,
|
addKeyword,
|
||||||
addAnswer,
|
addAnswer,
|
||||||
|
addChild,
|
||||||
toSerialize,
|
toSerialize,
|
||||||
ProviderClass,
|
ProviderClass,
|
||||||
CoreClass,
|
CoreClass,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ const { toSerialize } = require('./toSerialize')
|
|||||||
const addAnswer =
|
const addAnswer =
|
||||||
(inCtx) =>
|
(inCtx) =>
|
||||||
(answer, options, cb = null, nested = []) => {
|
(answer, options, cb = null, nested = []) => {
|
||||||
|
answer = Array.isArray(answer) ? answer.join('\n') : answer
|
||||||
/**
|
/**
|
||||||
* Todas las opciones referentes a el mensaje en concreto options:{}
|
* Todas las opciones referentes a el mensaje en concreto options:{}
|
||||||
* @returns
|
* @returns
|
||||||
|
|||||||
15
packages/bot/io/methods/addChild.js
Normal file
15
packages/bot/io/methods/addChild.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
const { toSerialize } = require('./toSerialize')
|
||||||
|
/**
|
||||||
|
* @deprecate
|
||||||
|
* @param answer string
|
||||||
|
* @param options {media:string, buttons:[], capture:true default false}
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
const addChild = (flowIn = null) => {
|
||||||
|
if (!flowIn?.toJson) {
|
||||||
|
throw new Error('DEBE SER UN FLOW CON toJSON()')
|
||||||
|
}
|
||||||
|
return toSerialize(flowIn.toJson())
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { addChild }
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
const { addAnswer } = require('./addAnswer')
|
const { addAnswer } = require('./addAnswer')
|
||||||
const { addKeyword } = require('./addKeyword')
|
const { addKeyword } = require('./addKeyword')
|
||||||
|
const { addChild } = require('./addChild')
|
||||||
const { toSerialize } = require('./toSerialize')
|
const { toSerialize } = require('./toSerialize')
|
||||||
const { toCtx } = require('./toCtx')
|
const { toCtx } = require('./toCtx')
|
||||||
const { toJson } = require('./toJson')
|
const { toJson } = require('./toJson')
|
||||||
|
|
||||||
module.exports = { addAnswer, addKeyword, toCtx, toJson, toSerialize }
|
module.exports = { addAnswer, addKeyword, addChild, toCtx, toJson, toSerialize }
|
||||||
|
|||||||
@@ -22,6 +22,15 @@ test('Debere probar las propeidades array', () => {
|
|||||||
assert.is(MAIN_CTX.ctx.keyword, ARRANGE.keyword)
|
assert.is(MAIN_CTX.ctx.keyword, ARRANGE.keyword)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('Debere probar las propeidades array en answer', () => {
|
||||||
|
const ARRANGE = {
|
||||||
|
keyword: ['hola!', 'ole'],
|
||||||
|
}
|
||||||
|
const MAIN_CTX = addKeyword(ARRANGE.keyword).addAnswer(['hola', 'chao'])
|
||||||
|
|
||||||
|
assert.is(MAIN_CTX.ctx.keyword, ARRANGE.keyword)
|
||||||
|
})
|
||||||
|
|
||||||
test('Debere probar toSerialize', () => {
|
test('Debere probar toSerialize', () => {
|
||||||
const ARRANGE = {
|
const ARRANGE = {
|
||||||
keyword: ['hola!', 'ole'],
|
keyword: ['hola!', 'ole'],
|
||||||
|
|||||||
0
packages/cli/bin/cli.js
Normal file → Executable file
0
packages/cli/bin/cli.js
Normal file → Executable file
@@ -25,6 +25,28 @@ const main = async () => {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
#### CTX
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
ref: 'ans_7d9981e5-5019-422c-a19a-565cbb021391',
|
||||||
|
keyword: 'ans_cfdad31b-ff6d-475f-873a-4ed6f8a79a43',
|
||||||
|
answer: 'Esperando respuesta...',
|
||||||
|
options: {
|
||||||
|
media: null,
|
||||||
|
buttons: [],
|
||||||
|
capture: true,
|
||||||
|
child: null,
|
||||||
|
nested: [Array],
|
||||||
|
keyword: {},
|
||||||
|
callback: true
|
||||||
|
},
|
||||||
|
refSerialize: '81f18f563fd26a6c6d12c62aed98095f',
|
||||||
|
from: 'NUMERO_PERSONA_QUE_ESCRIBE'
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
#### Video
|
#### Video
|
||||||
|
|
||||||
> Video explicando como debes de agregar nuevos adaptadores
|
> Video explicando como debes de agregar nuevos adaptadores
|
||||||
|
|||||||
@@ -1,15 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* Si necesitas saber que trae el "ctx"
|
||||||
|
* Puedes ver el README.md dentro packages/database
|
||||||
|
*/
|
||||||
|
|
||||||
class MockDatabase {
|
class MockDatabase {
|
||||||
|
db
|
||||||
listHistory = []
|
listHistory = []
|
||||||
|
|
||||||
constructor() {
|
constructor() {}
|
||||||
/**
|
|
||||||
* Se debe cargar listHistory con historial de mensajes
|
getPrevByNumber = (from) => {
|
||||||
* para que se pueda continuar el flow
|
const history = this.listHistory.slice().reverse()
|
||||||
*/
|
return history.find((a) => a.from === from)
|
||||||
}
|
}
|
||||||
|
|
||||||
save = (ctx) => {
|
save = (ctx) => {
|
||||||
console.log('Guardando DB...', ctx)
|
|
||||||
this.listHistory.push(ctx)
|
this.listHistory.push(ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8944
yarn-error.log
Normal file
8944
yarn-error.log
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user