Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/defaultendflow #894

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,34 @@ El lenguaje principal que se utilizó para desarrollar este proyecto fue __JavaS


__Requerimientos:__
- Node v16 o superior __[descargar node](https://nodejs.org/es/download/)__
- __[Yarn](https://classic.yarnpkg.com/lang/en/docs/install/#windows-stable)__ como gestor de paquetes. En el link conseguirás las intrucciones para instalar yarn.
- Node v18 o superior __[descargar node](https://nodejs.org/es/download/)__
- __[pnpm](https://pnpm.io/cli/install)__ como gestor de paquetes. En el link conseguirás las intrucciones para instalar `pnmp`.
- __[VSCode](https://code.visualstudio.com/download)__ (recomendado): Editor de código con plugins.
- __[Conventional Commits](https://marketplace.visualstudio.com/items?itemName=vivaxy.vscode-conventional-commits&ssr=false#overview)__ (plugin-vscode) este plugin te ayudará a crear commit semántico.
- Se usará la rama __dev__ *(https://github.com/leifermendez/bot-whatsapp/tree/dev)* como rama principal hasta que se haga oficialmente el lanzamiento de la V2.

### 🚀 Iniciando

__Clonar repo rama dev__
__Clona repositorio (desde tu fork)__
```
git clone --branch dev https://github.com/codigoencasa/bot-whatsapp
git clone https://github.com/codigoencasa/bot-whatsapp
```
__Instalar dependencias__
```
cd bot-whatsapp
yarn install
pnpm install
```

__Compilar (build)__
Para compilar la aplicación es necesario ejecutar este comando, el cual genera un directorio `lib` dentro de los paquetes del monorepo.

```
yarn build
pnpm run build
```

__Example-app__
Se ejecuta el CLI (Command Line Interface) para ayudarte a crear un app-bot de ejemplo.
```
yarn run cli
pnpm run cli
```

Selecionas (mediante las flechas arriba y abajo) el proveedor que quieras usar y cuando estes sobre el presiona la barra de espacio, igualmente selecciona la base de datos que quieras usar.
Expand Down
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,32 @@
"repository": "https://github.com/leifermendez/bot-whatsapp",
"license": "ISC",
"devDependencies": {
"@commitlint/cli": "^17.4.4",
"@rollup/plugin-strip": "^3.0.2",
"@commitlint/config-conventional": "^17.4.4",
"@octokit/core": "^4.2.0",
"@commitlint/cli": "^17.8.1",
"@commitlint/config-conventional": "^17.8.1",
"@octokit/core": "^4.2.4",
"@rollup/plugin-commonjs": "^23.0.7",
"@rollup/plugin-json": "^5.0.2",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^5.0.2",
"c8": "^7.13.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.4",
"@rollup/plugin-strip": "^3.0.4",
"c8": "^7.14.0",
"conventional-changelog": "^3.1.25",
"cross-env": "^7.0.3",
"eslint": "^8.34.0",
"eslint-config-prettier": "^8.6.0",
"fs-extra": "^11.1.0",
"eslint": "^8.52.0",
"eslint-config-prettier": "^8.10.0",
"fs-extra": "^11.1.1",
"git-cz": "^4.9.0",
"husky": "^8.0.3",
"mime-types": "^2.1.35",
"only-allow": "^1.1.1",
"prettier": "^2.8.4",
"only-allow": "^1.2.1",
"prettier": "^2.8.8",
"pretty-quick": "^3.1.3",
"prompts": "^2.4.2",
"rimraf": "^4.1.2",
"rollup": "^3.17.2",
"rimraf": "^4.4.1",
"rollup": "^3.29.4",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-copy": "^3.4.0",
"semver": "^7.3.8",
"rollup-plugin-copy": "^3.5.0",
"semver": "^7.5.4",
"standard-version": "^9.5.0",
"uvu": "^0.5.6"
},
Expand Down
32 changes: 31 additions & 1 deletion packages/bot/io/flow.class.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
const { toSerialize } = require('./methods/toSerialize')
const { flatObject } = require('../utils/flattener')

/**
* Esta clas se encarga de manera la manipulacion de los flows
* y la creaciones de indices donde almacenar los callbacks
*/
class FlowClass {
allCallbacks = []
flowSerialize = []
flowRaw = []

constructor(_flow) {
if (!Array.isArray(_flow)) throw new Error('Esto debe ser un ARRAY')
this.flowRaw = _flow
this.flowRaw = this.addEndsFlows(_flow)

this.allCallbacks = flatObject(_flow)

Expand All @@ -18,6 +23,26 @@ class FlowClass {
this.flowSerialize = toSerialize(mergeToJsonSerialize)
}

/**
* Agregamos un addAcion con un endFlow
* al finalizar el flow para limpiar rendimiento, colas, etc
* @param {*} _flows
* @returns
*/
addEndsFlows = (_flows) => {
return _flows.map((flow) => flow.addAction(async (_,{endFlow}) => {
return endFlow()
}))
}

/**
* Funcion principal encargada de devolver un array de mensajes a continuar
* la idea es basado en un ref o id devolver la lista de mensaes a enviar
* @param {*} keyOrWord
* @param {*} symbol
* @param {*} overFlow
* @returns
*/
find = (keyOrWord, symbol = false, overFlow = null) => {
keyOrWord = `${keyOrWord}`
let capture = false
Expand Down Expand Up @@ -83,6 +108,11 @@ class FlowClass {
}
}

/**
* El proposito es cargar los flows y la serializacion de los callbacks
* a los flows qu son hijos
* @returns
*/
getFlowsChild = () => {
try {
const flowChilds = this.flowSerialize
Expand Down
Empty file modified packages/cli/bin/cli.js
100644 → 100755
Empty file.
Loading
Loading