mirror of
https://github.com/cheveguerra/bot-whatsapp.git
synced 2026-04-17 19:26:23 +00:00
docs(example-app): add cli crate app
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -23,7 +23,7 @@ tmp/
|
||||
.yarn/*
|
||||
!.yarn/releases
|
||||
.fleet/
|
||||
example-app/
|
||||
example-app*/
|
||||
qr.svg
|
||||
package-lock.json
|
||||
yarn-error.log
|
||||
@@ -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 .
|
||||
|
||||
@@ -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__
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
21
packages/cli/create-app/index.js
Normal file
21
packages/cli/create-app/index.js
Normal file
@@ -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 }
|
||||
@@ -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()
|
||||
|
||||
33
starters/apps/base/app.js
Normal file
33
starters/apps/base/app.js
Normal file
@@ -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()
|
||||
15
starters/apps/base/package.json
Normal file
15
starters/apps/base/package.json
Normal file
@@ -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"
|
||||
}
|
||||
12
yarn.lock
12
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"
|
||||
|
||||
Reference in New Issue
Block a user