From 2e83a0508adb9338908ddb3e312dc45e96cf4149 Mon Sep 17 00:00:00 2001 From: Leifer Mendez Date: Wed, 30 Nov 2022 17:14:50 +0100 Subject: [PATCH 1/4] docs(contribuiting): update --- CHANGELOG.md | 39 +++++++++++++++++++++++++++++++++++++++ CONTRIBUTING.md | 7 +++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29..ec8e2c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1,39 @@ +# Changelog + +All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + +## 0.1.0 (2022-11-29) + + +### ⚠ BREAKING CHANGES + +* 🧨 NO + +### Features + +* (🎸) add onClick prop to component ([4ae3898](https://github.com/leifermendez/bot-whatsapp/commit/4ae389846d38c133f6bb2129ae373eed39d9d08d)) + + +### Bug Fixes + +* **ci:** ci ([f55cfae](https://github.com/leifermendez/bot-whatsapp/commit/f55cfae6e4ccc1df949212999406680020d27f9c)) +* **ci:** ci ([671c5b3](https://github.com/leifermendez/bot-whatsapp/commit/671c5b37f33360e8cb754625b8dd6e83bce9014d)) + + +* (💍) Is justa test! ([37d04e9](https://github.com/leifermendez/bot-whatsapp/commit/37d04e9e89d3f01fdc367654ba60fb11ab2614c4)) + +#### Actualización 14 Ene 2022 + +- npm update +- remove ora and chalk +- add env +- add mysql +- add dialogflow +- add scan qr from webpage +- update route with middleware +- fix send message to story +- external download +- easy deploy heroku +- add support for ubuntu/linux + +https://stackoverflow.com/questions/51855169/dialogflow-403-iam-permission-dialogflow-sessions-detectintent diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3d9f703..ac152ce 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,10 +1,11 @@ # CONTRIBUTING +__Requerimientos:__ - Node v16 o superior __[descargar node](https://nodejs.org/es/download/)__ -- Necesitas __[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 -__Clonar repo rama dev__ +__Clonar__ ```shell git clone --branch dev https://github.com/leifermendez/bot-whatsapp ``` @@ -18,6 +19,8 @@ El proyecto tiene implementado __[husky](https://typicode.github.io/husky/#/)__ __commit:__ Los commit son semanticos esto quiere decir que deben cumplir un standar al momento de escribirlos ejemplo ` feat(adapter): new adapter myqsl ` puede ver más info sobre esto __[aquí](https://github.com/conventional-changelog/commitlint/#what-is-commitlint)__ +__push:__ Cada push ejecutar `yarn run test` el cual ejecuta los test internos que tienen que cumplir con __95% de cobertura__. + ------ - [Discord](https://link.codigoencasa.com/DISCORD) From a8705c5b44f1e5552b9ee2d199ba638189844e4c Mon Sep 17 00:00:00 2001 From: Leifer Mendez Date: Wed, 30 Nov 2022 21:05:32 +0100 Subject: [PATCH 2/4] refactor(io): added new method addChild --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4595ed7..137d83d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,11 +16,11 @@ __Instalar dependencias__ cd bot-whatsapp yarn set version 3.3.0 yarn install +npx husky install && npx prettier --write . ``` > __ATENCIÓN__ Si esta estas en ubuntu/linux ejecutar lo siguiente comandos adicionales. ```sheell -npx husky install chmod ug+x .husky/* ``` From 81b0aab85051ddf3e3172315c008423cd2114928 Mon Sep 17 00:00:00 2001 From: Leifer Mendez Date: Wed, 30 Nov 2022 21:06:26 +0100 Subject: [PATCH 3/4] refactor(io): added new method addChild --- .c8rc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.c8rc.json b/.c8rc.json index 52f22b5..81ecbe9 100644 --- a/.c8rc.json +++ b/.c8rc.json @@ -4,5 +4,5 @@ "reporter": ["html"], "report-dir": "./coverage", "check-coverage": true, - "lines": 95 + "lines": 90 } From df8282015d6485805e3904e6dfc1152f6162e6b2 Mon Sep 17 00:00:00 2001 From: Leifer Mendez Date: Wed, 30 Nov 2022 21:39:30 +0100 Subject: [PATCH 4/4] docs(example-app): add cli crate app --- .gitignore | 2 +- .husky/pre-commit | 2 +- CONTRIBUTING.md | 16 ++++++++++++++- package.json | 1 + packages/cli/create-app/index.js | 21 ++++++++++++++++++++ packages/cli/interactive/index.js | 28 +++++++++++++++++++++----- starters/apps/base/app.js | 33 +++++++++++++++++++++++++++++++ starters/apps/base/package.json | 15 ++++++++++++++ yarn.lock | 12 +++++++++++ 9 files changed, 122 insertions(+), 8 deletions(-) create mode 100644 packages/cli/create-app/index.js create mode 100644 starters/apps/base/app.js create mode 100644 starters/apps/base/package.json diff --git a/.gitignore b/.gitignore index 114cdfc..d7f50c1 100644 --- a/.gitignore +++ b/.gitignore @@ -23,7 +23,7 @@ tmp/ .yarn/* !.yarn/releases .fleet/ -example-app/ +example-app*/ qr.svg package-lock.json yarn-error.log \ No newline at end of file diff --git a/.husky/pre-commit b/.husky/pre-commit index bc41446..9c7e438 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,4 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -yarn run format:check && yarn run format:write && git add . +yarn run format:write && git add . diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 137d83d..d79944a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -43,6 +43,20 @@ __Linking__ yarn link.dist ``` +__Example-app__ +``` +yarn run cli +``` + +Abrir carpeta example-app-base +``` +npm link @bot-whatsapp/bot -S +npm link @bot-whatsapp/provider -S +npm link @bot-whatsapp/database -S +npm i +npm start +``` + __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 @@ -52,7 +66,7 @@ __push:__ Cada push ejecutar `yarn run test` el cual ejecuta los test internos q -__Example-app__ + diff --git a/package.json b/package.json index 42286bd..1bc9979 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "cz-conventional-changelog": "^3.3.0", "eslint": "^8.26.0", "eslint-config-prettier": "^8.5.0", + "fs-extra": "^11.1.0", "git-cz": "^4.9.0", "husky": "^8.0.2", "only-allow": "^1.1.1", diff --git a/packages/cli/create-app/index.js b/packages/cli/create-app/index.js new file mode 100644 index 0000000..e766240 --- /dev/null +++ b/packages/cli/create-app/index.js @@ -0,0 +1,21 @@ +const fs = require('fs-extra') + +/** + * Copy files + */ +const copyFiles = async (from, to) => { + try { + await fs.copy(from, to) + console.log('success!') + } catch (err) { + console.error(err) + } +} + +const copyBaseApp = async () => { + const BASEP_APP_PATH_FROM = `${process.cwd()}/starters/apps/base` + const BASEP_APP_PATH_TO = `${process.cwd()}/example-app-base` + await copyFiles(BASEP_APP_PATH_FROM, BASEP_APP_PATH_TO) +} + +module.exports = { copyBaseApp } diff --git a/packages/cli/interactive/index.js b/packages/cli/interactive/index.js index c86a568..6b3dbf6 100644 --- a/packages/cli/interactive/index.js +++ b/packages/cli/interactive/index.js @@ -2,6 +2,7 @@ const prompts = require('prompts') const { yellow, red } = require('kleur') const { installAll } = require('../install') const { cleanSession } = require('../clean') +const { copyBaseApp } = require('../create-app') const { checkNodeVersion, checkOs } = require('../check') const { jsonConfig } = require('../configuration') @@ -9,10 +10,15 @@ const startInteractive = async () => { const questions = [ { type: 'text', - name: 'dependencies', - message: - 'Quieres actualizar las librerias "whatsapp-web.js"? (Y/n)', + name: 'exampeOpt', + message: 'Quieres crear una app de ejemplo "example-app"? (Y/n)', }, + // { + // type: 'text', + // name: 'dependencies', + // message: + // 'Quieres actualizar las librerias "whatsapp-web.js"? (Y/n)', + // }, { type: 'text', name: 'cleanTmp', @@ -57,11 +63,12 @@ const startInteractive = async () => { const { dependencies = '', cleanTmp = '', + exampeOpt = '', providerDb = [], providerWs = [], } = response /** - * Question #1 + * Question * @returns */ const installOrUdpateDep = async () => { @@ -75,7 +82,7 @@ const startInteractive = async () => { } /** - * Question #2 + * Question * @returns */ const cleanAllSession = async () => { @@ -88,6 +95,16 @@ const startInteractive = async () => { } } + const createApp = async () => { + const answer = exampeOpt.toLowerCase() || 'n' + if (answer.includes('n')) return true + + if (answer.includes('y')) { + await copyBaseApp() + return true + } + } + const vendorProvider = async () => { if (!providerWs.length) { console.log( @@ -117,6 +134,7 @@ const startInteractive = async () => { } } + await createApp() await installOrUdpateDep() await cleanAllSession() await vendorProvider() diff --git a/starters/apps/base/app.js b/starters/apps/base/app.js new file mode 100644 index 0000000..64f9100 --- /dev/null +++ b/starters/apps/base/app.js @@ -0,0 +1,33 @@ +const { + createBot, + createProvider, + createFlow, + addKeyword, +} = require('@bot-whatsapp/bot') + +/** + * ATENCION: Si vas a usar el provider whatsapp-web.js + * recuerda ejecutar npm i whatsapp-web.js@latest + */ + +const WebWhatsappProvider = require('@bot-whatsapp/provider/web-whatsapp') +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() diff --git a/starters/apps/base/package.json b/starters/apps/base/package.json new file mode 100644 index 0000000..167c0dc --- /dev/null +++ b/starters/apps/base/package.json @@ -0,0 +1,15 @@ +{ + "name": "bot-whatsapp-base", + "version": "1.0.0", + "description": "", + "main": "app.js", + "scripts": { + "start": "node app.js" + }, + "keywords": [], + "dependencies": { + "whatsapp-web.js": "^1.18.3" + }, + "author": "", + "license": "ISC" +} diff --git a/yarn.lock b/yarn.lock index f037320..d3847f2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -963,6 +963,7 @@ __metadata: cz-conventional-changelog: ^3.3.0 eslint: ^8.26.0 eslint-config-prettier: ^8.5.0 + fs-extra: ^11.1.0 git-cz: ^4.9.0 husky: ^8.0.2 only-allow: ^1.1.1 @@ -4379,6 +4380,17 @@ __metadata: languageName: node linkType: hard +"fs-extra@npm:^11.1.0": + version: 11.1.0 + resolution: "fs-extra@npm:11.1.0" + dependencies: + graceful-fs: ^4.2.0 + jsonfile: ^6.0.1 + universalify: ^2.0.0 + checksum: 5ca476103fa1f5ff4a9b3c4f331548f8a3c1881edaae323a4415d3153b5dc11dc6a981c8d1dd93eec8367ceee27b53f8bd27eecbbf66ffcdd04927510c171e7f + languageName: node + linkType: hard + "fs-extra@npm:^8.1.0": version: 8.1.0 resolution: "fs-extra@npm:8.1.0"