mirror of
https://github.com/cheveguerra/bot-whatsapp.git
synced 2026-04-17 19:26:23 +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
|
||||
packages/cli/config.json
|
||||
config.json
|
||||
.yarnrc.yml
|
||||
coverage/
|
||||
*.lcov
|
||||
log
|
||||
lib
|
||||
tmp/
|
||||
.yarn/*
|
||||
!.yarn/releases
|
||||
.fleet/
|
||||
example-app/
|
||||
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
|
||||
|
||||
@@ -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.
|
||||
- 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__
|
||||
```shell
|
||||
>💡 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`
|
||||
|
||||
__Clonar repo rama dev__
|
||||
```
|
||||
git clone --branch dev https://github.com/leifermendez/bot-whatsapp
|
||||
```
|
||||
__Instalar dependencias__
|
||||
```shell
|
||||
```
|
||||
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__
|
||||
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__.
|
||||
|
||||
|
||||
|
||||
__Example-app__
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
------
|
||||
- [Discord](https://link.codigoencasa.com/DISCORD)
|
||||
- [Twitter](https://twitter.com/leifermendez)
|
||||
|
||||
1
TODO.md
1
TODO.md
@@ -29,3 +29,4 @@
|
||||
- [ ] Meta adapter
|
||||
|
||||
### @bot-whatsapp/cli
|
||||
- [ ] Hacer comando para crear `example-app`
|
||||
@@ -15,7 +15,7 @@
|
||||
"lint:check": "eslint ./packages",
|
||||
"lint:fix": "eslint --fix ./packages",
|
||||
"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.coverage": "node ./node_modules/c8/bin/c8.js npm run test.unit",
|
||||
"test": "npm run test.coverage",
|
||||
@@ -24,6 +24,7 @@
|
||||
"dev": "node ./example-app/app.js",
|
||||
"prepare": "npx husky install",
|
||||
"preinstall": "npx only-allow yarn",
|
||||
"postinstall": "npx prettier --write .",
|
||||
"release": "standard-version"
|
||||
},
|
||||
"workspaces": [
|
||||
@@ -81,7 +82,7 @@
|
||||
"engines": {
|
||||
"node": ">=16",
|
||||
"npm": "please-use-yarn",
|
||||
"yarn": ">=1"
|
||||
"yarn": ">=3"
|
||||
},
|
||||
"author": "Leifer Mendez <leifer33@gmail.com>",
|
||||
"config": {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const CoreClass = require('./core/core.class')
|
||||
const ProviderClass = require('./provider/provider.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
|
||||
@@ -38,6 +38,7 @@ module.exports = {
|
||||
createProvider,
|
||||
addKeyword,
|
||||
addAnswer,
|
||||
addChild,
|
||||
toSerialize,
|
||||
ProviderClass,
|
||||
CoreClass,
|
||||
|
||||
@@ -10,6 +10,7 @@ const { toSerialize } = require('./toSerialize')
|
||||
const addAnswer =
|
||||
(inCtx) =>
|
||||
(answer, options, cb = null, nested = []) => {
|
||||
answer = Array.isArray(answer) ? answer.join('\n') : answer
|
||||
/**
|
||||
* Todas las opciones referentes a el mensaje en concreto options:{}
|
||||
* @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 { addKeyword } = require('./addKeyword')
|
||||
const { addChild } = require('./addChild')
|
||||
const { toSerialize } = require('./toSerialize')
|
||||
const { toCtx } = require('./toCtx')
|
||||
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)
|
||||
})
|
||||
|
||||
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', () => {
|
||||
const ARRANGE = {
|
||||
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 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 {
|
||||
db
|
||||
listHistory = []
|
||||
|
||||
constructor() {
|
||||
/**
|
||||
* Se debe cargar listHistory con historial de mensajes
|
||||
* para que se pueda continuar el flow
|
||||
*/
|
||||
constructor() {}
|
||||
|
||||
getPrevByNumber = (from) => {
|
||||
const history = this.listHistory.slice().reverse()
|
||||
return history.find((a) => a.from === from)
|
||||
}
|
||||
|
||||
save = (ctx) => {
|
||||
console.log('Guardando DB...', 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