Compare commits

..

41 Commits

Author SHA1 Message Date
3f004d840d docs: env 2023-01-15 20:06:25 -06:00
307dd2b6a0 docs: env 2023-01-15 20:05:07 -06:00
df1fd5cb75 Update spam.json 2023-01-06 04:28:48 -06:00
c9284a9382 Update README.md 2023-01-06 04:23:27 -06:00
232b2c790a Update README.md 2023-01-06 04:10:18 -06:00
b6d272aa4f Update README.md 2023-01-06 04:09:31 -06:00
efe7a1537c Update README.md 2023-01-06 04:08:45 -06:00
2145e850f5 Update README.md 2023-01-06 04:08:11 -06:00
aaf543c3d5 Update README.md 2023-01-06 04:07:07 -06:00
cf5efe7a4b Update README.md 2023-01-06 04:04:44 -06:00
9e9f97bae8 Update README.md 2023-01-06 01:16:12 -06:00
915fbf1b8d Update README.md 2023-01-06 01:12:46 -06:00
eae1a87cd6 Update README.md 2023-01-06 01:09:30 -06:00
03c21a997a Update README.md 2023-01-06 01:06:39 -06:00
c432a97aef Update README.md 2023-01-06 01:06:03 -06:00
bc9ebc3642 Update README.md 2023-01-06 01:05:13 -06:00
b4e5c956d9 docs: cambios 2023-01-06 00:57:29 -06:00
36d0f3d0de mods a response.json 2023-01-06 00:52:45 -06:00
1f92c0802a se agregaron ejemplos de regExp 2023-01-06 00:39:46 -06:00
7b9906f18f docs: 2022-12-27 02:35:45 -06:00
629b13de23 fix: check commits and changes 2022-12-27 02:16:50 -06:00
b7d89411b3 Merge branch 'Mod-V2' of https://github.com/cheveguerra/bot-whatsapp into Mod-V2 2022-12-26 16:04:35 -06:00
2ca2eefb9a fix: fix media sin extension 2022-12-24 22:33:53 -06:00
b625787a9a Merge branch 'Mod-V2' of https://github.com/cheveguerra/bot-whatsapp into Mod-V2 2022-12-24 22:07:05 -06:00
c54111a636 feat: se agregaron ejemplos de listas y botones
Se agregaron ejemplos de listas y botones
2022-12-24 22:07:01 -06:00
dad6941a70 Merge branch 'codigoencasa:main' into Mod-V2 2022-12-23 02:55:56 -06:00
bbc6b689ac Merge branch 'codigoencasa:main' into Mod-V2 2022-12-18 12:23:32 -06:00
f8451adf94 Merge branch 'Mod-V2' of https://github.com/cheveguerra/bot-whatsapp into Mod-V2 2022-12-16 13:40:11 -06:00
aa8d8baa18 feat: se agrega %nombre% a remplazos
Se agrega %nombre% y %primer_nombre% a remplazos
2022-12-16 13:40:07 -06:00
8a678f252f Merge branch 'leifermendez:main' into Mod-V2 2022-12-15 03:59:31 -06:00
5266c7050f feat: cambios en response.json 2022-12-12 23:00:21 -06:00
a774ff23de feat: cambio en el mensaje inicial. 2022-12-12 22:56:32 -06:00
26b3fb0787 feat: cambios en response.json 2022-12-12 22:53:39 -06:00
85670e0d4e docs: cambios en README 2022-12-12 22:26:16 -06:00
ff561fce4b feat: cambios en intial y response 2022-12-12 22:16:24 -06:00
fd2954f1cd docs: cambios a README 2022-12-12 21:45:18 -06:00
9ffc9bac74 docs: cambios a README 2022-12-12 21:44:29 -06:00
ac6cba2265 Merge branch 'leifermendez:main' into Mod-V2 2022-12-12 15:23:59 -06:00
d30a44fc3e test: t1 2022-12-11 06:21:32 -06:00
ac8c09c665 Initial Mod v2 2022-12-11 03:41:41 -06:00
4334c13cca test: testting
testing
2022-12-11 03:26:08 -06:00
428 changed files with 7996 additions and 38377 deletions

View File

@@ -1,8 +0,0 @@
{
"src": "./src",
"exclude": ["**/bot/lib", "__mocks__", "**/mock"],
"reporter": ["html"],
"report-dir": "./coverage",
"check-coverage": true,
"lines": 90
}

15
.env Normal file
View File

@@ -0,0 +1,15 @@
######DATABASE: none, mysql, dialogflow
DEFAULT_MESSAGE=true
SAVE_MEDIA=true
PORT=3000
DATABASE=none
LANGUAGE=es
SQL_HOST=
SQL_USER=
SQL_PASS=
SQL_DATABASE=
KEEP_DIALOG_FLOW=false
MULTI_DEVICE=true
DIALOGFLOW_MEDIA_FOR_SLOT_FILLING=false
GDRIVE_FOLDER_ID=

View File

@@ -1,2 +0,0 @@
packages/docs/*
packages/portal/*

View File

@@ -1,18 +0,0 @@
module.exports = {
env: {
browser: true,
commonjs: true,
es2021: true,
node: true,
},
extends: 'eslint:recommended',
overrides: [],
parserOptions: {
ecmaVersion: 'latest',
},
rules: {
'no-unsafe-negation': 'off',
'no-prototype-builtins': 'off',
'no-useless-escape': 'off',
},
}

2
.gitattributes vendored Normal file
View File

@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto

5
.github/FUNDING.yml vendored
View File

@@ -1,4 +1,3 @@
# These are supported funding model platforms
open_collective: bot-whatsapp
patreon: leifermendez patreon: leifermendez
custom: https://www.buymeacoffee.com/leifermendez custom: "https://www.buymeacoffee.com/leifermendez"
open_collective: bot-whatsapp

View File

@@ -1,83 +0,0 @@
name: Build and Test
on:
pull_request:
branches:
- dev
jobs:
############ BUILD PACKAGE ############
build-package:
name: Build Package
runs-on: ubuntu-latest
needs:
- test-unit
- test-e2e
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: 'yarn'
registry-url: https://registry.npmjs.org/
- run: corepack enable
- name: Install NPM Dependencies
run: yarn install --immutable --network-timeout 300000
- name: Build Package
run: yarn build:full
- name: Build Eslint rules
run: yarn lint:fix
############ UNIT TEST ############
test-unit:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: 'yarn'
registry-url: https://registry.npmjs.org/
- run: corepack enable
- name: Install NPM Dependencies
run: yarn install --immutable --network-timeout 300000
- name: Unit Tests
run: yarn test
############ UNIT TEST ############
test-e2e:
name: e2e Tests
runs-on: ubuntu-latest
needs:
- test-unit
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: 'yarn'
registry-url: https://registry.npmjs.org/
- run: corepack enable
- name: Install NPM Dependencies
run: yarn install --immutable --network-timeout 300000
- name: e2e Tests
run: yarn test.e2e

View File

@@ -9,20 +9,19 @@
# the `language` matrix defined below to confirm you have the correct set of # the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages. # supported CodeQL languages.
# #
name: 'CodeQL' name: "CodeQL"
on: on:
push: push:
branches: [release/next] branches: [ "main", dev, next-release ]
pull_request: pull_request:
# The branches below must be a subset of the branches above # The branches below must be a subset of the branches above
branches: ['main'] branches: [ "main" ]
schedule: schedule:
- cron: '21 16 * * 5' - cron: '21 16 * * 5'
jobs: jobs:
analyze: analyze:
if: ${{ !github.event.act }}
name: Analyze name: Analyze
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
@@ -55,6 +54,7 @@ jobs:
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality # queries: security-extended,security-and-quality
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below) # If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild - name: Autobuild
@@ -73,4 +73,4 @@ jobs:
- name: Perform CodeQL Analysis - name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2 uses: github/codeql-action/analyze@v2
with: with:
category: '/language:${{matrix.language}}' category: "/language:${{matrix.language}}"

View File

@@ -1,47 +0,0 @@
name: 📄 Desplegando documentacion
on:
pull_request:
branches:
- 'feat/docs-**'
- 'fix/docs-**'
push:
branches:
- 'feat/docs-**'
- 'fix/docs-**'
jobs:
############ DOCUMENTATION BUILD ############
build-documentation:
if: ${{ !github.event.act }}
name: Build Package
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: 'yarn'
registry-url: https://registry.npmjs.org/
- run: corepack enable
- name: Install NPM Dependencies
run: yarn install --immutable --network-timeout 300000
- name: Add netlify
run: yarn add netlify-cli -D
- name: Create .env build file
run: |
touch packages/docs/.env
echo VITE_GITHUB_TOKEN=${{ secrets.COLLABORATORS_TOKEN }} >> packages/docs/.env
- name: Build and Deploy
run: |
cd packages/docs
netlify deploy --build --site ${{ secrets.NETLIFY_SITE_ID }} --auth ${{ secrets.NETLIFY_AUTH_TOKEN }}

View File

@@ -1,41 +0,0 @@
name: 📄 (PROD) Desplegando documentacion
on:
push:
branches:
- release/next
jobs:
############ DOCUMENTATION BUILD ############
build-documentation-prod:
name: Build Package
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: 'yarn'
registry-url: https://registry.npmjs.org/
- run: corepack enable
- name: Install NPM Dependencies
run: yarn install --immutable --network-timeout 300000
- name: Add netlify
run: yarn add netlify-cli -D
- name: Create .env build file
run: |
touch packages/docs/.env
echo VITE_GITHUB_TOKEN=${{ secrets.COLLABORATORS_TOKEN }} >> packages/docs/.env
- name: Build and Deploy
run: |
cd packages/docs
netlify deploy --prod --build --site ${{ secrets.NETLIFY_SITE_ID }} --auth ${{ secrets.NETLIFY_AUTH_TOKEN }}

View File

@@ -1,64 +0,0 @@
name: 🚀 (DEV) Liberando versiones
on:
push:
branches:
- release/next
jobs:
############ RELEASE ############
release:
name: Release
runs-on: ubuntu-latest
outputs:
commit: ${{ steps.vars.outputs.commit }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{github.event.after}}
persist-credentials: false
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: 'yarn'
registry-url: https://registry.npmjs.org/
- run: corepack enable
- name: Install NPM Dependencies
run: yarn install --immutable --network-timeout 300000
- name: Build Package
run: yarn build:full
- name: Release @bot-whatsapp/bot
run: yarn node ./scripts/release.js --name=bot --version= --token="${{ secrets.NPM_TOKEN }}"
- name: Release @bot-whatsapp/cli
run: yarn node ./scripts/release.js --name=cli --version= --token="${{ secrets.NPM_TOKEN }}"
- name: Release @bot-whatsapp/create-bot-whatsapp
run: yarn node ./scripts/release.js --name=create-bot-whatsapp --version= --token="${{ secrets.NPM_TOKEN }}"
- name: Release @bot-whatsapp/database
run: yarn node ./scripts/release.js --name=database --version= --token="${{ secrets.NPM_TOKEN }}"
- name: Release @bot-whatsapp/provider
run: yarn node ./scripts/release.js --name=provider --version= --token="${{ secrets.NPM_TOKEN }}"
- name: Release @bot-whatsapp/contexts
run: yarn node ./scripts/release.js --name=contexts --version= --token="${{ secrets.NPM_TOKEN }}"
- name: Release @bot-whatsapp/portal
run: yarn node ./scripts/release.js --name=portal --version= --token="${{ secrets.NPM_TOKEN }}"
- name: Commit & Push changes
uses: actions-js/push@master
with:
branch: release/next
github_token: ${{ secrets.GITHUB_TOKEN }}
force: true

View File

@@ -1,75 +0,0 @@
name: 🚀⚡ Liberando versiones
on:
push:
branches:
- release/production
jobs:
############ RELEASE ############
release-prod:
if: ${{ !github.event.act }}
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set output
id: vars
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: 'yarn'
registry-url: https://registry.npmjs.org/
- run: corepack enable
- name: Set User
run: git config --global user.email "leifer.contacto@gmail.com" && git config --global user.name "Leifer Mendez"
- name: Install NPM Dependencies
run: yarn install --immutable --network-timeout 300000
- name: Set CHANGELOG
run: yarn release
- name: get-npm-version
id: package-version
uses: martinbeentjes/npm-get-version-action@main
- name: Build Package
run: yarn build:full
- name: Release @bot-whatsapp/bot
run: yarn node ./scripts/release.js --name=bot --version="${{ steps.package-version.outputs.current-version}}" --token="${{ secrets.NPM_TOKEN }}"
- name: Release @bot-whatsapp/cli
run: yarn node ./scripts/release.js --name=cli --version="${{ steps.package-version.outputs.current-version}}" --token="${{ secrets.NPM_TOKEN }}"
- name: Release @bot-whatsapp/create-bot-whatsapp
run: yarn node ./scripts/release.js --name=create-bot-whatsapp --version="${{ steps.package-version.outputs.current-version}}" --token="${{ secrets.NPM_TOKEN }}"
- name: Release @bot-whatsapp/database
run: yarn node ./scripts/release.js --name=database --version="${{ steps.package-version.outputs.current-version}}" --token="${{ secrets.NPM_TOKEN }}"
- name: Release @bot-whatsapp/provider
run: yarn node ./scripts/release.js --name=provider --version="${{ steps.package-version.outputs.current-version}}" --token="${{ secrets.NPM_TOKEN }}"
- name: Release @bot-whatsapp/contexts
run: yarn node ./scripts/release.js --name=contexts --version="${{ steps.package-version.outputs.current-version}}" --token="${{ secrets.NPM_TOKEN }}"
- name: Release @bot-whatsapp/portal
run: yarn node ./scripts/release.js --name=portal --version="${{ steps.package-version.outputs.current-version}}" --token="${{ secrets.NPM_TOKEN }}"
- name: Release Github
run: yarn node ./scripts/github.js --version="${{ steps.package-version.outputs.current-version}}" --token="${{ secrets.OCTO_TOKEN }}"
- name: Commit & Push changes
uses: actions-js/push@master
with:
branch: release/production
github_token: ${{ secrets.GITHUB_TOKEN }}
force: true

View File

@@ -11,6 +11,7 @@ on:
jobs: jobs:
stale: stale:
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
issues: write issues: write

40
.gitignore vendored
View File

@@ -1,10 +1,5 @@
/node_modules /node_modules
/packages/repl /node_modules/*
/packages/*/starters
/packages/*/node_modules
/packages/*/dist
/packages/*/docs/dist
/packages/provider/src/venom/tokens
session.json session.json
chats/* chats/*
!chats/.gitkeep !chats/.gitkeep
@@ -13,35 +8,6 @@ media/*
mediaSend/* mediaSend/*
!mediaSend/.gitkeep !mediaSend/.gitkeep
!mediaSend/nota-de-voz.mp3 !mediaSend/nota-de-voz.mp3
.env
.wwebjs_auth .wwebjs_auth
/session backup
/session/* backup/*
/tokens
/tokens/*
packages/cli/config.json
config.json
.yarnrc.yml
coverage/
*.lcov
log
log/*
*.log
*.tgz
lib
tmp/
.yarn/*
!.yarn/releases
!.yarn/plugins/@yarnpkg/plugin-postinstall.cjs
.fleet/
example-app*/
base-*/
test-*.json
!starters/apps/base-*/
qr.svg
package-lock.json
yarn-error.log
.npmrc
# Local Netlify folder
.netlify
.secrets

View File

@@ -1,4 +0,0 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npm run lint:fix && npx --no -- commitlint --edit

View File

@@ -1,4 +0,0 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
yarn run fmt.staged

View File

@@ -1,4 +0,0 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npm run test

View File

@@ -1,9 +0,0 @@
packages/**/lib
packages/docs/
**/.git
**/.svn
**/.hg
**/node_modules
*.mjs
*.cjs
*.md

View File

@@ -1,7 +1 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"semi": false,
"singleQuote": true,
"printWidth": 120
}

View File

@@ -1,24 +0,0 @@
{
"Flow Bot (simple)": {
"scope": "javascript",
"prefix": "bot:flow",
"description": "Crear un flujo simple",
"body": [
"export const flow${1} = addKeyword(['hola', 'buenas'])",
" .addAnswer('Hola! 🚀 Bienvenido a este CHATBOT')",
" .addAnswer('¿Como puedo ayudarte?')"
]
},
"Flow Bot (completo)": {
"scope": "javascript",
"prefix": "bot:flow completo",
"description": "Crear un flujo completo",
"body": [
"export const flow${1} = addKeyword(['categorias'])",
" .addAnswer('⚡ Tenemos las siguientes categorias')",
" .addAnswer(['🚀 Computadoras', '🚀 Celulares', '🚀 Otros'], {",
" delay: 1500, //Milisegundo 1500 = 1.5segundos",
"})"
]
}
}

View File

@@ -1,3 +0,0 @@
{
"recommendations": ["xyc.vscode-mdx-preview", "vivaxy.vscode-conventional-commits", "mhutchie.git-graph"]
}

15
.vscode/launch.json vendored
View File

@@ -1,15 +0,0 @@
{
// Use IntelliSense para saber los atributos posibles.
// Mantenga el puntero para ver las descripciones de los existentes atributos.
// Para más información, visite: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Iniciar el programa",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}\\example-app\\app.js"
}
]
}

14
.vscode/settings.json vendored
View File

@@ -1,14 +0,0 @@
{
"conventionalCommits.scopes": [
"hook",
"contributing",
"cli",
"bot",
"provider",
"adapter",
"ci",
"starters",
"conflict",
"contexts"
]
}

View File

@@ -1,8 +0,0 @@
/* eslint-disable */
module.exports = {
name: "@yarnpkg/plugin-postinstall",
factory: function (require) {
var plugin;(()=>{"use strict";var e={d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{default:()=>s});const n=require("@yarnpkg/core"),o=require("clipanion"),a={postinstall:{description:"Postinstall hook that will always run in Yarn v2",type:n.SettingsType.STRING,default:""}},r=require("@yarnpkg/shell"),l=async e=>{if(e){console.log("Running postinstall command...");const t=await r.execute(e);if(0!==t)throw new Error("postinstall command failed with exit code "+t)}};var i=function(e,t,n,o){var a,r=arguments.length,l=r<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,t,n,o);else for(var i=e.length-1;i>=0;i--)(a=e[i])&&(l=(r<3?a(l):r>3?a(t,n,l):a(t,n))||l);return r>3&&l&&Object.defineProperty(t,n,l),l};class c extends o.Command{async execute(){const e=(await n.Configuration.find(this.context.cwd,this.context.plugins)).get("postinstall");await l(e)}}i([o.Command.Path("postinstall")],c.prototype,"execute",null);const s={configuration:a,commands:[c],hooks:{afterAllInstalled:async e=>{const t=e.configuration.get("postinstall");await l(t)}}};plugin=t})();
return plugin;
}
};

File diff suppressed because one or more lines are too long

View File

@@ -1,10 +0,0 @@
nodeLinker: node-modules
npmPublishRegistry: 'https://registry.npmjs.org'
plugins:
- path: .yarn/plugins/@yarnpkg/plugin-postinstall.cjs
spec: 'https://raw.githubusercontent.com/gravitywelluk/yarn-plugin-postinstall/master/bundles/%40yarnpkg/plugin-postinstall.js'
yarnPath: .yarn/releases/yarn-3.3.0.cjs
postinstall: npx husky install

View File

@@ -1,592 +1,4 @@
# 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.21](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.20...v0.1.21) (2023-02-12)
### Features
* **provider:** :bug: add_location ([a46a9ef](https://github.com/leifermendez/bot-whatsapp/commit/a46a9efd8dbd921c773395d331154dc9a8aae783))
* **provider:** :rocket: feat Instance provider ([2278149](https://github.com/leifermendez/bot-whatsapp/commit/227814929561cedc11a1f69c8029515a7f47c9ff))
* **provider:** :rocket: provider raw ([2d44a00](https://github.com/leifermendez/bot-whatsapp/commit/2d44a002ff226fb0eb7362ad49936f1e00b84242))
* **provider:** :zap: add location provider ([c7de860](https://github.com/leifermendez/bot-whatsapp/commit/c7de860803fb362f5afe06cc38ad71b2c316d524))
* **provider:** :zap: add location provider ([c0ece6f](https://github.com/leifermendez/bot-whatsapp/commit/c0ece6feb2b0325476880a604c32de341eb60544))
* **provider:** :zap: support location <20> ([a147677](https://github.com/leifermendez/bot-whatsapp/commit/a147677a26b36bba429c3dd3c2c81a44a7a4d2b6))
### Bug Fixes
* arreglando dir y varios mensajes en dialog flow essential ([01c7db8](https://github.com/leifermendez/bot-whatsapp/commit/01c7db8fe7dda2482eb0aa1fd7b3469b6ae8eae1))
### [0.1.20](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.19...v0.1.20) (2023-02-05)
### Features
* **cli:** :fire: add regex expression in addKeyworkd ([e34560c](https://github.com/leifermendez/bot-whatsapp/commit/e34560c77d4852d2e90930f0858e51aa67d4eeab))
* **provider:** :zap: possible get class provider ([76ba717](https://github.com/leifermendez/bot-whatsapp/commit/76ba717927a75b3d6299206aa0b8aee2bc25b726))
### Bug Fixes
* **cli:** :zap: working flowDynamic test ([c0113ca](https://github.com/leifermendez/bot-whatsapp/commit/c0113ca49295aff220d8defcb53f2ba7f2872d75))
* **cli:** :zap: working flowDynamic test ([aef52d2](https://github.com/leifermendez/bot-whatsapp/commit/aef52d2694fa6616d614338643db198b4f7f1fe8))
* **cli:** :zap: working flowDynamic test ([f769320](https://github.com/leifermendez/bot-whatsapp/commit/f76932021ce968d93241b55cfcdb8ae0e0e6c934))
* **cli:** :zap: working flowDynamic test ([23e09ef](https://github.com/leifermendez/bot-whatsapp/commit/23e09efaeccaf51018c55da492edff45b625f0a9))
* **database:** add support emoji in mysql ([9311aa0](https://github.com/leifermendez/bot-whatsapp/commit/9311aa0a65623a1bf40e96207a281625154dae90))
* **database:** fix naming ([cd082f2](https://github.com/leifermendez/bot-whatsapp/commit/cd082f235012cd5f5844c6437f51711beee0c865))
* **database:** fix naming ([1afc3ba](https://github.com/leifermendez/bot-whatsapp/commit/1afc3ba182070713b5bec40eaab0fa1f680830cd))
* **database:** fix naming ([c9831d2](https://github.com/leifermendez/bot-whatsapp/commit/c9831d202ab2c85f15a0247cd2a2426bc435270c))
* **provider:** :zap: baily wa.link ([96c2bff](https://github.com/leifermendez/bot-whatsapp/commit/96c2bffd093269be8e39474a84c156938504a6cb))
### [0.1.19](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.18...v0.1.19) (2023-01-29)
### Features
* :fire: bailey add media ([eab39e4](https://github.com/leifermendez/bot-whatsapp/commit/eab39e4ac06fd46f1a4671f8c15d1456b4400b97))
* :zap: more feature ([e19c3a2](https://github.com/leifermendez/bot-whatsapp/commit/e19c3a25a40259c74b4add9635af4844907eed26))
* **provider:** :rocket: fix issues in providers venom and wwebjs ([cbe438b](https://github.com/leifermendez/bot-whatsapp/commit/cbe438b77854e8df48b9dafaf7a837d21124ac5f))
* **provider:** :rocket: fix provider ([0ad4c58](https://github.com/leifermendez/bot-whatsapp/commit/0ad4c58457b548dc41c0f9e8470d59c48de7b95a))
* **provider:** :rocket: fix provider ([f8c7184](https://github.com/leifermendez/bot-whatsapp/commit/f8c7184487065443ab10f77aaf585e8bd63ca441))
* **provider:** :rocket: fix provider ([b2afa45](https://github.com/leifermendez/bot-whatsapp/commit/b2afa45352a7ab1f5d9775f3c1fde475bd8ca204))
* **provider:** :rocket: fix provider venom and wwebjs ([dcb0566](https://github.com/leifermendez/bot-whatsapp/commit/dcb0566d2bc3da40cd0c71554bb5ea0ec115d9ca))
* **provider:** :rocket: implements all send media to venom provider ([9dd7c02](https://github.com/leifermendez/bot-whatsapp/commit/9dd7c02b6a5474aff063f7d6be0ca8519504b93c))
* **provider:** :rocket: send file wwebjs ([6ff1a3a](https://github.com/leifermendez/bot-whatsapp/commit/6ff1a3a980196c01c66ed04ee07d0e7e57256504))
* **provider:** :zap: bailey add send file video audio ([14d1a61](https://github.com/leifermendez/bot-whatsapp/commit/14d1a61fa259c09135c37c55bd79e97c9c8367e4))
* **provider:** :zap: venom wweb ([fd2847a](https://github.com/leifermendez/bot-whatsapp/commit/fd2847aea0db17a0bdf33b5bca67a4cb8db2da16))
* **provider:** :zap: venom wweb ([f95331d](https://github.com/leifermendez/bot-whatsapp/commit/f95331d3dc70e76a3dfbe4c8d24059f0e7a164ef))
* **provider:** 🚀 implements all send media to venom provider ([bd7d150](https://github.com/leifermendez/bot-whatsapp/commit/bd7d150c047af41fdbb47f0a50a21e82cd79ee85))
### Bug Fixes
* **bot:** :fire: endFlow with ctx ([f6114af](https://github.com/leifermendez/bot-whatsapp/commit/f6114affadfbc324536a86167d1fdfe8da3c8de6))
* **bot:** :fire: endFlow with ctx ([b655ae4](https://github.com/leifermendez/bot-whatsapp/commit/b655ae449e7958ea940d8cc3c678fd66f60b6385))
* **bot:** :zap: endFlow butons ([87a4203](https://github.com/leifermendez/bot-whatsapp/commit/87a4203cd5b88f566387a76d586248e4265d6e4e))
* **bot:** :zap: fix fallback refactor ([e22780d](https://github.com/leifermendez/bot-whatsapp/commit/e22780d3faba94f71a70f1f201a20690608fa5bf))
* **cli:** :zap: endflow ([1c66f17](https://github.com/leifermendez/bot-whatsapp/commit/1c66f178a56d284bb8cb9df5ca17685c7e5d1ddd))
* **cli:** :zap: refactor fallback in child flow ([b33e346](https://github.com/leifermendez/bot-whatsapp/commit/b33e34692d3abcb6874308a9be79f74be4a2c3a8))
* **cli:** :zap: refactor fallback in child flow ([8da4b20](https://github.com/leifermendez/bot-whatsapp/commit/8da4b204b41125b5d0fa0aee4fa87c1f5faf5568))
### [0.1.18](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.17...v0.1.18) (2023-01-24)
### Features
* **bot:** :zap: add blacklist ([7078dc4](https://github.com/leifermendez/bot-whatsapp/commit/7078dc4c93d01bf90ef08ecb34e89a1abbe16fd2))
* **bot:** :zap: flowDynamic buttons, media ([3c4b1c0](https://github.com/leifermendez/bot-whatsapp/commit/3c4b1c0fc4b6d98d67c67806d918d3604bb2209b))
### Bug Fixes
* **bot:** :bug: body undefined ([bb6ed4a](https://github.com/leifermendez/bot-whatsapp/commit/bb6ed4a084ae98070dfdf0c4ba1eca574c4092cc))
* **bot:** :bug: body undefined ([9234cf1](https://github.com/leifermendez/bot-whatsapp/commit/9234cf1c5d00abdd35e62a826b3c450ab056987a))
* **bot:** :bug: body undefined ([a118bbb](https://github.com/leifermendez/bot-whatsapp/commit/a118bbbf7f0a7023cb7f33c23f37db72adad151f))
* **bot:** :bug: body undefined ([f54dea5](https://github.com/leifermendez/bot-whatsapp/commit/f54dea52b01063acd6122eeba1fbbe324aa7805d))
* **bot:** :bug: body undefined ([72e0a91](https://github.com/leifermendez/bot-whatsapp/commit/72e0a910503e9643db7dfbc6e09c41c96934e1f7))
* **bot:** :bug: body undefined ([70dd4d7](https://github.com/leifermendez/bot-whatsapp/commit/70dd4d73e814fc5636d19a887f3621c483b837c1))
* **bot:** :bug: body undefined ([ecf0eef](https://github.com/leifermendez/bot-whatsapp/commit/ecf0eef928917d76c59bd23886cb7a4108b421f1))
* **bot:** :bug: flowDynamic stranger behaviour ([877252b](https://github.com/leifermendez/bot-whatsapp/commit/877252bd4a8a7bbbbf083c3ceaeaeb952b0a1828))
* **bot:** :bug: flowDynamic stranger behaviour ([f5a7de3](https://github.com/leifermendez/bot-whatsapp/commit/f5a7de3a003c012e2164e51fff26892cfc3144be))
* **bot:** :memo: more docs ([98793d0](https://github.com/leifermendez/bot-whatsapp/commit/98793d0cfc1674830beaa3707f933c5a791eec14))
* **cli:** :zap: refactor ([a29b9d4](https://github.com/leifermendez/bot-whatsapp/commit/a29b9d4e1f85fc163cf1d633c0857f0c8b7f03e1))
* **cli:** :zap: refactor ([18ef4e9](https://github.com/leifermendez/bot-whatsapp/commit/18ef4e9d726575ca390ca24354825860328d3347))
* **cli:** :zap: refactor ([3648757](https://github.com/leifermendez/bot-whatsapp/commit/3648757fa083bdb88a16bf6c2e90c828c233bdb1))
* **cli:** :zap: refactor ([32f6a70](https://github.com/leifermendez/bot-whatsapp/commit/32f6a70f8f6fb26d8ea2a0f1a4aec4827b9d6a93))
* **cli:** :zap: refactor ([8c825e7](https://github.com/leifermendez/bot-whatsapp/commit/8c825e7f6b7133f7cc7f3041ce331b80a9fe60e0))
* **cli:** :zap: refactor ([0c0f437](https://github.com/leifermendez/bot-whatsapp/commit/0c0f4375b84549bee809340a85f9ce038ee2739e))
* **cli:** :zap: refactor ([039ce5d](https://github.com/leifermendez/bot-whatsapp/commit/039ce5dd7cac8115b335ad5de05f7bd871e24140))
* **cli:** :zap: refactor ([5e87918](https://github.com/leifermendez/bot-whatsapp/commit/5e879188b8bf9d486399b308a9a9c2612607d465))
* **cli:** :zap: refactor ([21a7270](https://github.com/leifermendez/bot-whatsapp/commit/21a72702817bc6b344223b34ca4513a7ff45fc93))
* **cli:** :zap: refactor ([82a99b2](https://github.com/leifermendez/bot-whatsapp/commit/82a99b2c80e6738566042ea738bbab8208a17758))
* **cli:** :zap: refactor ([cc19974](https://github.com/leifermendez/bot-whatsapp/commit/cc19974579379777b05cb69c38cec0fce6740471))
* **cli:** :zap: refactor ([56fcb8f](https://github.com/leifermendez/bot-whatsapp/commit/56fcb8fb72169bc21fce7c4fcdceccf2acd39c73))
* **cli:** :zap: refactor ([f36cff1](https://github.com/leifermendez/bot-whatsapp/commit/f36cff1eefdd96be4ab531e1cb2d3b630b1a81c3))
* **cli:** :zap: refactor ([b393c11](https://github.com/leifermendez/bot-whatsapp/commit/b393c11af6c0ebccb0a690be8b90b9df8877dad1))
* **cli:** :zap: refactor ([6683715](https://github.com/leifermendez/bot-whatsapp/commit/6683715ad617ea1075654a475a1c62ea607c733f))
* **contexts:** :bug: fixed [#524](https://github.com/leifermendez/bot-whatsapp/issues/524) issue ([79cc31a](https://github.com/leifermendez/bot-whatsapp/commit/79cc31a96f6a9836447cc4e6bb1e1521c54183fe))
* **contexts:** :bug: fixed [#524](https://github.com/leifermendez/bot-whatsapp/issues/524) issue ([7067b4a](https://github.com/leifermendez/bot-whatsapp/commit/7067b4a80b7938ccfaf1ed141a37d645a1a3a062))
* **provider:** wwebjs upgrade ([345f256](https://github.com/leifermendez/bot-whatsapp/commit/345f256a1b4a238519dafc15c9a31bc5e6bad4fe))
* se agrego @bot-whatsapp/portal a package.json ([46a9fa6](https://github.com/leifermendez/bot-whatsapp/commit/46a9fa6793e06600335de998d2bd9d0691b02ca4))
### [0.1.17](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.16...v0.1.17) (2023-01-13)
### Features
* mod de starters para habiltar portal ([eceb170](https://github.com/leifermendez/bot-whatsapp/commit/eceb170df03721dca4183b658c863b94fa04bc84))
### Bug Fixes
* **ci:** pre-release ([aaec075](https://github.com/leifermendez/bot-whatsapp/commit/aaec0751408ab49483d428810d94aaf7d46acb94))
* correccion en starters app.js para portal QR ([f430380](https://github.com/leifermendez/bot-whatsapp/commit/f430380b4f23d41702395c96c628bf13bf443278))
* **starters:** :zap: added dockerfile ([230981e](https://github.com/leifermendez/bot-whatsapp/commit/230981e2676361149cb2a99def7f705e75009260))
### [0.1.16](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.15...v0.1.16) (2023-01-11)
### [0.1.15](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.14...v0.1.15) (2023-01-11)
### [0.1.14](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.13...v0.1.14) (2023-01-11)
### [0.1.13](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.12...v0.1.13) (2023-01-11)
### [0.1.12](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.10...v0.1.12) (2023-01-11)
### [0.1.9-pre](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.9...v0.1.9-pre) (2023-01-10)
### [0.1.7-pre-1](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.7-alpha...v0.1.7-pre-1) (2023-01-10)
### [0.1.7-alpha](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.7-pre...v0.1.7-alpha) (2023-01-10)
### [0.1.11](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.10...v0.1.11) (2023-01-11)
### [0.1.9-pre](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.9...v0.1.9-pre) (2023-01-10)
### [0.1.7-pre-1](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.7-alpha...v0.1.7-pre-1) (2023-01-10)
### [0.1.7-alpha](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.7-pre...v0.1.7-alpha) (2023-01-10)
### [0.1.10](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.8...v0.1.10) (2023-01-11)
### Bug Fixes
* :fire: update qr package ([ecde23f](https://github.com/leifermendez/bot-whatsapp/commit/ecde23fdea65def209aa874af35a3f293e6b1a91))
### [0.1.8](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.7-pre...v0.1.8) (2023-01-10)
### [0.1.7](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.7-pre...v0.1.7) (2023-01-10)
### [0.1.6](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.5...v0.1.6) (2023-01-10)
### Features
* :zap: new portal web for qr scan ([cb2e869](https://github.com/leifermendez/bot-whatsapp/commit/cb2e8692a3f94c8b24993cd11dd564f094b0e4ef))
* :zap: new portal web for qr scan ([9e93795](https://github.com/leifermendez/bot-whatsapp/commit/9e93795e6fce38890045389da95184fef1fbe0da))
* :zap: new portal web for qr scan ([3c178ea](https://github.com/leifermendez/bot-whatsapp/commit/3c178ea113b140535a51f5dcd521dbb66251670e))
* :zap: new portal web for qr scan ([1f1f564](https://github.com/leifermendez/bot-whatsapp/commit/1f1f564f4e2e3aa13b84de500fe215e0c45c2770))
* :zap: new portal web for qr scan ([3de5f4b](https://github.com/leifermendez/bot-whatsapp/commit/3de5f4b77a10e30632ff7555f5af5d8e93cb2019))
* :zap: qr code filename ([d794f60](https://github.com/leifermendez/bot-whatsapp/commit/d794f604ac8a835e523709dbf18c9b1609bbd00e))
* :zap: qr portal ([246ecdc](https://github.com/leifermendez/bot-whatsapp/commit/246ecdc11a8c4e652867c842b612dc4ce73f9828))
* :zap: qr portal ([af8b401](https://github.com/leifermendez/bot-whatsapp/commit/af8b401d075e1c35065589ede61476461ce86b4d))
* agregamos dockerfile y webserver a starters ([f9e3bbc](https://github.com/leifermendez/bot-whatsapp/commit/f9e3bbc6655060408e4fdbe1d7e920c2ed4fca53))
### Bug Fixes
* :zap: add Dockerfile, starter ([4e0d33c](https://github.com/leifermendez/bot-whatsapp/commit/4e0d33c6bb46ad259774f6d0c38c6c0b5f8ca4a9))
* :zap: fix inject port args ([20f752e](https://github.com/leifermendez/bot-whatsapp/commit/20f752e6c1b1f7d11948fc4f2f8950f7834df7d9))
* :zap: fix inject port args ([7a23eb0](https://github.com/leifermendez/bot-whatsapp/commit/7a23eb0cc6f93ec21c5ab34e46981ae7a93f42ff))
* **provider:** :zap: fix send image baileys ([2ddea54](https://github.com/leifermendez/bot-whatsapp/commit/2ddea5468d235035478d4e91e63c821da19da179))
* **provider:** :zap: fix send image baileys ([391e11c](https://github.com/leifermendez/bot-whatsapp/commit/391e11ce738cd64792b5237d69f3739b0263c198))
* **provider:** :zap: fix send image baileys ([5d10cb9](https://github.com/leifermendez/bot-whatsapp/commit/5d10cb9026da60043e9a2f86117ebb04d0631a3f))
* **provider:** fix error docker as root user ([5a033da](https://github.com/leifermendez/bot-whatsapp/commit/5a033da83aee1f614120bccf27c9f330500cc7b0))
### [0.1.4](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.5...v0.1.4) (2023-01-10)
### Features
* :zap: new portal web for qr scan ([cb2e869](https://github.com/leifermendez/bot-whatsapp/commit/cb2e8692a3f94c8b24993cd11dd564f094b0e4ef))
* :zap: new portal web for qr scan ([9e93795](https://github.com/leifermendez/bot-whatsapp/commit/9e93795e6fce38890045389da95184fef1fbe0da))
* :zap: new portal web for qr scan ([3c178ea](https://github.com/leifermendez/bot-whatsapp/commit/3c178ea113b140535a51f5dcd521dbb66251670e))
* :zap: new portal web for qr scan ([1f1f564](https://github.com/leifermendez/bot-whatsapp/commit/1f1f564f4e2e3aa13b84de500fe215e0c45c2770))
* :zap: new portal web for qr scan ([3de5f4b](https://github.com/leifermendez/bot-whatsapp/commit/3de5f4b77a10e30632ff7555f5af5d8e93cb2019))
* :zap: qr code filename ([d794f60](https://github.com/leifermendez/bot-whatsapp/commit/d794f604ac8a835e523709dbf18c9b1609bbd00e))
* :zap: qr portal ([246ecdc](https://github.com/leifermendez/bot-whatsapp/commit/246ecdc11a8c4e652867c842b612dc4ce73f9828))
* :zap: qr portal ([af8b401](https://github.com/leifermendez/bot-whatsapp/commit/af8b401d075e1c35065589ede61476461ce86b4d))
* agregamos dockerfile y webserver a starters ([f9e3bbc](https://github.com/leifermendez/bot-whatsapp/commit/f9e3bbc6655060408e4fdbe1d7e920c2ed4fca53))
### Bug Fixes
* :zap: add Dockerfile, starter ([4e0d33c](https://github.com/leifermendez/bot-whatsapp/commit/4e0d33c6bb46ad259774f6d0c38c6c0b5f8ca4a9))
* :zap: fix inject port args ([20f752e](https://github.com/leifermendez/bot-whatsapp/commit/20f752e6c1b1f7d11948fc4f2f8950f7834df7d9))
* :zap: fix inject port args ([7a23eb0](https://github.com/leifermendez/bot-whatsapp/commit/7a23eb0cc6f93ec21c5ab34e46981ae7a93f42ff))
* **provider:** :zap: fix send image baileys ([2ddea54](https://github.com/leifermendez/bot-whatsapp/commit/2ddea5468d235035478d4e91e63c821da19da179))
* **provider:** :zap: fix send image baileys ([391e11c](https://github.com/leifermendez/bot-whatsapp/commit/391e11ce738cd64792b5237d69f3739b0263c198))
* **provider:** :zap: fix send image baileys ([5d10cb9](https://github.com/leifermendez/bot-whatsapp/commit/5d10cb9026da60043e9a2f86117ebb04d0631a3f))
* **provider:** fix error docker as root user ([5a033da](https://github.com/leifermendez/bot-whatsapp/commit/5a033da83aee1f614120bccf27c9f330500cc7b0))
### [0.1.3](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.2...v0.1.3) (2023-01-04)
### Features
* **adapter:** :zap: send messages with dialogflow ([c20e151](https://github.com/leifermendez/bot-whatsapp/commit/c20e151e209d33de9e7425a64f003c85360f1832))
* **baileys:** added more methods ([1b23b83](https://github.com/leifermendez/bot-whatsapp/commit/1b23b837460ce4533ff33f10f1de5e3a344a5623))
* **bot:** :zap: http responses support ([e331c2d](https://github.com/leifermendez/bot-whatsapp/commit/e331c2dcc40eeb82a93f9d29f6a82333b8465927))
* **bot:** :zap: http responses support ([2d2bb08](https://github.com/leifermendez/bot-whatsapp/commit/2d2bb085cd95604a84ca3fe5c4ddc84b3824ac1c))
* **bot:** :zap: rev-03 everything work fine ([3012e02](https://github.com/leifermendez/bot-whatsapp/commit/3012e026b77ab4e99334b992d166a89189f76503))
* **cli:** :sparkles: added bailey ([06acec2](https://github.com/leifermendez/bot-whatsapp/commit/06acec2bf29d72c2b46f4ce81fed115bab97351f))
* **cli:** :sparkles: added bailey ([c868f73](https://github.com/leifermendez/bot-whatsapp/commit/c868f7346245bec94582b25a342febc657926c9d))
* **conflict:** :zap: remove unused variable ([eba9229](https://github.com/leifermendez/bot-whatsapp/commit/eba92299cfd84c971f09697d027043f19eec2b7c))
* **contexts:** :zap: add new dialogflowcx ([4d8cf62](https://github.com/leifermendez/bot-whatsapp/commit/4d8cf623ff86b3d08c8d52293d4e289dfda68e1c))
* **contexts:** :zap: add new dialogflowcx ([9885872](https://github.com/leifermendez/bot-whatsapp/commit/98858729919b2544dace07c49badce7888ddfd82))
* **contexts:** dialogflowcx support ([9179421](https://github.com/leifermendez/bot-whatsapp/commit/917942139f9736f1c0f8ce5f07b4e12e5768b0c7))
* correccion de flujos en app.js de ejemplo ([99f508f](https://github.com/leifermendez/bot-whatsapp/commit/99f508f93889d70240861158bc304c25a3b2daef))
* **docs:** master class updated ([69fd81a](https://github.com/leifermendez/bot-whatsapp/commit/69fd81a565e61b249ac50917585293d2d84e3dd4))
* **docs:** master class updated ([d522b03](https://github.com/leifermendez/bot-whatsapp/commit/d522b03e2e6e6e3f7c467c59e3d2d6f288fe37b2))
* **provider:** :bug: dialogflow ([4ec6f1e](https://github.com/leifermendez/bot-whatsapp/commit/4ec6f1e120879e545fa111615f2d79b792d947a5))
* **provider:** :sparkles: added dialogflow ([2f633c7](https://github.com/leifermendez/bot-whatsapp/commit/2f633c72da24f98d6c318d1e725571b62e04604c))
* **provider:** :sparkles: added dialogflow ([798f1ce](https://github.com/leifermendez/bot-whatsapp/commit/798f1cebdefe43624c1698a219dcb224bb842d38))
* **provider:** :sparkles: endpoint is added to validate the webhook … ([478929d](https://github.com/leifermendez/bot-whatsapp/commit/478929d1340d46d6bf997ae8edabbaae4511172d))
* **provider:** :sparkles: endpoint is added to validate the webhook token ([1ec1564](https://github.com/leifermendez/bot-whatsapp/commit/1ec15647dc462363d5b765f42debddbe6ef6266b))
* **provider:** :zap: add new methods ([0b4e353](https://github.com/leifermendez/bot-whatsapp/commit/0b4e35308dace0ccdf618cb1d04987ed5200d58c))
* **provider:** :zap: add sendfile and sendButtons ([5433610](https://github.com/leifermendez/bot-whatsapp/commit/5433610a84d7a050a387e4daf2ded1daebfc03a4))
* **provider:** :zap: add sendfile and sendButtons ([342cbcc](https://github.com/leifermendez/bot-whatsapp/commit/342cbccff1d09f9aabe5423ad6d686d590a2448f))
* **provider:** :zap: added new venom provider ([01fe9eb](https://github.com/leifermendez/bot-whatsapp/commit/01fe9ebc9a943f2aa086ee415153d1cccdb14ec0))
* **provider:** :zap: added tamplate venom ([337c2e9](https://github.com/leifermendez/bot-whatsapp/commit/337c2e94bccd0ae173958fe2db08b494bdc93c28))
* **provider:** :zap: baileysProvider ([23b2e8e](https://github.com/leifermendez/bot-whatsapp/commit/23b2e8e439ecec24450bd5cf1a3820316e643434))
* **provider:** :zap: solution error buttons ([1b83871](https://github.com/leifermendez/bot-whatsapp/commit/1b83871cca6996c6acae3d4c8b6b42aec05ea146))
* **provider:** :zap: solution error utils venom ([31c83f5](https://github.com/leifermendez/bot-whatsapp/commit/31c83f5d689a01490d3adb96006f54c2a5d3268b))
* **provider:** :zap: update ([b62d21a](https://github.com/leifermendez/bot-whatsapp/commit/b62d21a0bf94466e43c25c6e8c0f5db9ae91c572))
* **provider:** :zap: update ([0c94647](https://github.com/leifermendez/bot-whatsapp/commit/0c94647a27747c3ddf4f02926580370f0d81bdc2))
* **provider:** meta provider is added ([b041f7d](https://github.com/leifermendez/bot-whatsapp/commit/b041f7d0c7cc6f152d3f36785d1d398a4141d57d))
* **provider:** meta provider is added ([438607c](https://github.com/leifermendez/bot-whatsapp/commit/438607c222b91d6f8814201dabe5f7c3e7ba1abb))
* **provider:** new added baileys ([4e0fcbd](https://github.com/leifermendez/bot-whatsapp/commit/4e0fcbd8347f8a430adb43351b5415098a5d10df))
* **provider:** new provider - venon:zap: configuracion inicial provi… ([66f75f8](https://github.com/leifermendez/bot-whatsapp/commit/66f75f872200334bfc9eda744bed92c509dfee56))
* **provider:** new provider - venon:zap: configuracion inicial provider venom ([fee7c2e](https://github.com/leifermendez/bot-whatsapp/commit/fee7c2e967b7fe8835b5acc243c19f7713acfbe7))
* se agregaron los datros del adapter mongo en app.js y package.json ([8160d13](https://github.com/leifermendez/bot-whatsapp/commit/8160d13c866b8ae17b0ec8e68eee1bc0373595b0))
* se agrego informacion al ejemplo en app.js ([954e751](https://github.com/leifermendez/bot-whatsapp/commit/954e751f700c6a39ec70c0bc5168637c0dc7e07c))
* se agrego informacion al ejemplo en app.js ([b2f1339](https://github.com/leifermendez/bot-whatsapp/commit/b2f13396104db9ccef5b3bad1c4e19c6a4bad2d4))
* **starters:** meta memory base template added ([11c784f](https://github.com/leifermendez/bot-whatsapp/commit/11c784f882965d6bd3a2313cf91bed9fb3aa5f26))
* **starters:** meta memory base template added ([e8d6252](https://github.com/leifermendez/bot-whatsapp/commit/e8d625201ed86e162e0b4e82100ede1d08985555))
### Bug Fixes
* :art: update ([7d6708c](https://github.com/leifermendez/bot-whatsapp/commit/7d6708c01bbdc5043a7e6ed56fe15a9618115b91))
* :sparkles: updated starters ([5da4b7a](https://github.com/leifermendez/bot-whatsapp/commit/5da4b7a4d1e5950be94361ac439938741b9d299c))
* actualizar app.js de ejemplo ([1746613](https://github.com/leifermendez/bot-whatsapp/commit/17466138ddcef60a23a0c87911f22045f26d3233))
* actualizar ejemplo app.js ([60fdbf3](https://github.com/leifermendez/bot-whatsapp/commit/60fdbf3d3cd62819e618853a9dc2fd0e23fe8752))
* **adapter:** :fire: clear log ([9ad4874](https://github.com/leifermendez/bot-whatsapp/commit/9ad4874fdafabfbf0e9e20e6b3281f702bb9fbe7))
* **adapter:** :fire: clear log ([4d34d3a](https://github.com/leifermendez/bot-whatsapp/commit/4d34d3ab1daab4e72fb5244216c78cf836d1a164))
* **adapter:** :fire: improvement baileys ([e6fefb4](https://github.com/leifermendez/bot-whatsapp/commit/e6fefb4049847f996f2a169b9acfc27c2428d3e6))
* **adapter:** :fire: improvement baileys ([2d5ac26](https://github.com/leifermendez/bot-whatsapp/commit/2d5ac2664bea09e60ac85ff2612609ae21050945))
* **adapter:** :rocket: venom update - cli - qr iamge ([041bf62](https://github.com/leifermendez/bot-whatsapp/commit/041bf6280e5f6956393716907e0669aa3ca78b4a))
* **adapter:** :rocket: venom update - cli - qr iamge ([e37fd0d](https://github.com/leifermendez/bot-whatsapp/commit/e37fd0da3635aa1041664d490d5f9803d2c441ca))
* **adapter:** :rocket: venom update - cli - qr iamge ([ca6afbb](https://github.com/leifermendez/bot-whatsapp/commit/ca6afbb87fceec12d4a383486ad693905e36881f))
* **adapter:** json db change is made ([386c1bb](https://github.com/leifermendez/bot-whatsapp/commit/386c1bbbac036aa58335fb5f62e3af2493766b6b))
* **adapter:** json db change is made ([3bdc7af](https://github.com/leifermendez/bot-whatsapp/commit/3bdc7afe8062527ff08620650d2c1177dfea83f5))
* agregamos variables para mysql ([dcf65b8](https://github.com/leifermendez/bot-whatsapp/commit/dcf65b87bc7e7e6381e6448e83118077986898e7))
* **bot:** :ambulance: fix callback functions ([d9aa97c](https://github.com/leifermendez/bot-whatsapp/commit/d9aa97c7819aca1446657bc0b75e9732f0f20c6b)), closes [#252](https://github.com/leifermendez/bot-whatsapp/issues/252)
* **bot:** :ambulance: fix callback functions ([964a074](https://github.com/leifermendez/bot-whatsapp/commit/964a074aa41324bd09d0c4e2e7aa663a0602b69c))
* **bot:** :fire: fix rev ([21407c0](https://github.com/leifermendez/bot-whatsapp/commit/21407c0e37f1ab12efecf887e699cedf05e3946a))
* **bot:** :fire: fix rev ([484c8c3](https://github.com/leifermendez/bot-whatsapp/commit/484c8c3bdefbc7824c32a86090bafae0593ecdac))
* **bot:** :zap: working callback Phase 1 ([952ce86](https://github.com/leifermendez/bot-whatsapp/commit/952ce86ffaa48a0d6fbc0a00a08c5d1efa14ee8e))
* **bot:** :zap: working nested new flow ([2cbc962](https://github.com/leifermendez/bot-whatsapp/commit/2cbc96245d795de749d894a3a0d99b6550f08d9e))
* **cli:** :art: starters ([a2be57f](https://github.com/leifermendez/bot-whatsapp/commit/a2be57f0aa42c6b5e13ad19c34abc7d9e81dc135))
* **cli:** :art: starters ([670ecf1](https://github.com/leifermendez/bot-whatsapp/commit/670ecf121babf53e76c2ea106c0710cbe59facde))
* **cli:** :fire: update instructions ([e585e2f](https://github.com/leifermendez/bot-whatsapp/commit/e585e2f5f644ed0188dc9cd2b3c697c9d6050669))
* **cli:** :fire: update instructions ([ed36ce0](https://github.com/leifermendez/bot-whatsapp/commit/ed36ce0a7796320c6a4a452f29c05a3f0f7368db))
* **cli:** :fire: update instructions ([bad1694](https://github.com/leifermendez/bot-whatsapp/commit/bad16943fc2089887d6bf0b6d90075d3bec6f9c7))
* **cli:** :fire: update instructions ([a21633f](https://github.com/leifermendez/bot-whatsapp/commit/a21633fb7cf348cc37f4e4714f51172b49b193b5))
* **cli:** :zap: updated ([a6f4aa8](https://github.com/leifermendez/bot-whatsapp/commit/a6f4aa8d1e809330c06c165aaf9a9f90b8922bb5))
* **conflict:** conflict resolution ([71d43b5](https://github.com/leifermendez/bot-whatsapp/commit/71d43b585a0ce173061c84e9879915e4602db026))
* **contexts:** :fire: added buttons ([eabef7a](https://github.com/leifermendez/bot-whatsapp/commit/eabef7a92d005cd0190196cfe75828c38885aadf))
* **contexts:** :fire: added buttons ([1b878d2](https://github.com/leifermendez/bot-whatsapp/commit/1b878d2ba0daeb3609af74a2ebae7948456e7fb0))
* **contexts:** :fire: added buttons ([78b0a9d](https://github.com/leifermendez/bot-whatsapp/commit/78b0a9dddc2a6e0fceb721ee7794efa2047f25fc))
* **contexts:** :fire: added buttons ([d8309f7](https://github.com/leifermendez/bot-whatsapp/commit/d8309f77e1d9137c0bec977ed9faef633cd90552))
* correccion en app.js para remover addChild en starters ([32db429](https://github.com/leifermendez/bot-whatsapp/commit/32db429f2946f344d949cb169a9595d657c06279))
* fix del db provider mysql ([b59d4fc](https://github.com/leifermendez/bot-whatsapp/commit/b59d4fcdd7462cde3f68ab5746d49960b547a592))
* provider equivocado en app.js de venom ([4e0a109](https://github.com/leifermendez/bot-whatsapp/commit/4e0a1091ee85cedfaa5a9c3d40e5cd50bc36cda3))
* **provider:** :bug: create static site html qr ([c7e56a4](https://github.com/leifermendez/bot-whatsapp/commit/c7e56a4b13c8829f91769eeca7f1f6b3473f68cf))
* **provider:** :bug: fix metea provider ([85f50be](https://github.com/leifermendez/bot-whatsapp/commit/85f50be9dcbf3817107898d8d2980baf05acd678))
* **provider:** :bug: fix metea provider ([a52aaa1](https://github.com/leifermendez/bot-whatsapp/commit/a52aaa11d883bbaf526cf87720d3c3fd9f89a986))
* **provider:** :bug: qr code accurate ([6c4845d](https://github.com/leifermendez/bot-whatsapp/commit/6c4845d733720d9916bb4008f9069ae4fd986a4b))
* **provider:** :bug: qr code accurate ([91bfdc4](https://github.com/leifermendez/bot-whatsapp/commit/91bfdc46301207cbc5274308da6f39c7b4652c63))
* **provider:** :fire: baileys fix ([928365d](https://github.com/leifermendez/bot-whatsapp/commit/928365dcafb3631acf6b1d0c239a906f8e1c4b0d))
* **provider:** :fire: send message togther with media ([78aa23f](https://github.com/leifermendez/bot-whatsapp/commit/78aa23fab094059145f82e6781f9366d5d582b4f))
* **provider:** :fire: send message togther with media ([b6bf43d](https://github.com/leifermendez/bot-whatsapp/commit/b6bf43d70fc28c6a229522b9b0de76cec43ac864))
* **provider:** :zap: baileys fix restart ([ae83774](https://github.com/leifermendez/bot-whatsapp/commit/ae83774365027e2e86127ab7713ae9ee2df31f33))
* **provider:** :zap: edit starter ([ff65832](https://github.com/leifermendez/bot-whatsapp/commit/ff65832012003423cc86d25cf0923452b1f8acb7))
* **provider:** :zap: edit starter ([68dd182](https://github.com/leifermendez/bot-whatsapp/commit/68dd1820f05d04780824b318072d053eaf7db654))
* **provider:** :zap: json space ([3cef741](https://github.com/leifermendez/bot-whatsapp/commit/3cef741c9ee30024eb42770a5f32931fcd372160))
* **provider:** :zap: json space ([9b087e0](https://github.com/leifermendez/bot-whatsapp/commit/9b087e071019a7b6c79195a24dc7ddec498c5716))
* **provider:** :zap: json space ([208fb4e](https://github.com/leifermendez/bot-whatsapp/commit/208fb4e9131dd5d4fd7230ba1aa11181337d9181))
* **provider:** :zap: json space ([54a59c7](https://github.com/leifermendez/bot-whatsapp/commit/54a59c7f0d4dbaab006ce7e3c74412d8d3613ecd))
* **provider:** qr-fix margin ([663641a](https://github.com/leifermendez/bot-whatsapp/commit/663641a1b8bf9234a88b0f3c38381ebc4bfa4bf9))
* se quito addChild de las constantes porque no se usa ([ba2291a](https://github.com/leifermendez/bot-whatsapp/commit/ba2291a3ddac0d4101021e11d03cb222c5a4bb3b))
* **starters:** :fire: updated staters ([4d4f15c](https://github.com/leifermendez/bot-whatsapp/commit/4d4f15ce73486d9335ad474d9e37c3b155670134))
* **starters:** :fire: updated staters ([a30eaac](https://github.com/leifermendez/bot-whatsapp/commit/a30eaac77534d17eb980f6ec126140e9d30aa06e))
* **starters:** :memo: update MIGRATION ([37fe323](https://github.com/leifermendez/bot-whatsapp/commit/37fe32322eb1bd41eecd151e52f17ec0588fb85e))
* **starters:** :memo: update MIGRATION ([9b30e7d](https://github.com/leifermendez/bot-whatsapp/commit/9b30e7dcfc30bc160b56427cc6cdc2dc982bde2a))
* **starters:** base templates are added for meta ([229e017](https://github.com/leifermendez/bot-whatsapp/commit/229e017ae20b84c9d12c7282f97b7034f5f33e6d))
* **starters:** base templates are added for meta ([20f6651](https://github.com/leifermendez/bot-whatsapp/commit/20f665175c9b47226df41ce43e05574bd6ab1930))
### [0.1.2](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.1...v0.1.2) (2022-12-12)
### Bug Fixes
* **cli:** :art: starters ([79e2318](https://github.com/leifermendez/bot-whatsapp/commit/79e231825613f33bfec2ae8e93139f885c199c7a))
* **cli:** :art: starters ([87ba43a](https://github.com/leifermendez/bot-whatsapp/commit/87ba43a5535be0893a7701a3b6a085ee5d29e7c5))
* fix dependencias ([61d0324](https://github.com/leifermendez/bot-whatsapp/commit/61d032426119341187a470035d49b8b252ca46cd))
### [0.1.1](https://github.com/leifermendez/bot-whatsapp/compare/v0.3.0...v0.1.1) (2022-12-12)
## 0.3.0 (2022-12-12)
### ⚠ BREAKING CHANGES
* 🧨 NO
### Features
* (🎸) add onClick prop to component ([4ae3898](https://github.com/leifermendez/bot-whatsapp/commit/4ae389846d38c133f6bb2129ae373eed39d9d08d))
* **adapter:** added adapter mysql ([717a7dc](https://github.com/leifermendez/bot-whatsapp/commit/717a7dc95fbc107ec6f55387aff606c47144baa4))
* **adapter:** implementation of json file adapter ([5e1a373](https://github.com/leifermendez/bot-whatsapp/commit/5e1a3737303c843095984f6357564ea18458362f))
* **adapter:** mysql adapter ([8d73c86](https://github.com/leifermendez/bot-whatsapp/commit/8d73c86946d07aa80e5b375b62b84a88b2892e03))
* **adapter:** sql is added to create the table ([4b7de0f](https://github.com/leifermendez/bot-whatsapp/commit/4b7de0f6901524fa2c09271c3a99c364e6b3c260))
* **bot:** :fire: improvement provider handler ([4154cc2](https://github.com/leifermendez/bot-whatsapp/commit/4154cc223091a46d3203d3a378cd42f61749a5fa))
* **bot:** :zap: add send image function ([ce8a96b](https://github.com/leifermendez/bot-whatsapp/commit/ce8a96b958ff814c65d8fb4dbd5eaed5cc83a1ed))
* **ci:** :art: add releases ([b115dc3](https://github.com/leifermendez/bot-whatsapp/commit/b115dc3654996f049837bfb6b5d039a2313df0ad))
* **ci:** :art: relases script ([2e906bc](https://github.com/leifermendez/bot-whatsapp/commit/2e906bce79f7d854d437334e1d0c2cd270b0bbc6))
* **ci:** update ci ([e5a9db7](https://github.com/leifermendez/bot-whatsapp/commit/e5a9db7e12340c4f5baa66e8b20585b63daa3bcf))
* **cli:** create-starter ([3977987](https://github.com/leifermendez/bot-whatsapp/commit/397798790ef5857ca758b0df8384c6a4bfacc181))
* **provider:** :fire: add twilii (weoking) ([4350dff](https://github.com/leifermendez/bot-whatsapp/commit/4350dff22a7de69ba6d35ecbdd67e59b810bd46f))
* **provider:** added twilio provider ([8dd3be9](https://github.com/leifermendez/bot-whatsapp/commit/8dd3be909b36717f6b54e141a5f48d2722d4855c))
* **release:** added ([1988948](https://github.com/leifermendez/bot-whatsapp/commit/1988948c30d922beb7b83faab96d1d59cf7f5f90))
* **release:** added ([f4ad704](https://github.com/leifermendez/bot-whatsapp/commit/f4ad7040abf619635480c30babd6f1159c7af85a))
### Bug Fixes
* **adapter:** conflict resolution ([4b307ef](https://github.com/leifermendez/bot-whatsapp/commit/4b307efe79c738a5c4e04ff1c07ca247d827593c))
* **adapter:** corrections are made to the adapter ([afa6771](https://github.com/leifermendez/bot-whatsapp/commit/afa677190392d48715930ebe2b1e15c7619d730f))
* **bot:** :zap: added delay promises ([73caf09](https://github.com/leifermendez/bot-whatsapp/commit/73caf090ba9013132e5dcb7761a10939dc9ac300))
* **bot:** :zap: fix sensitive case ([24ac9fb](https://github.com/leifermendez/bot-whatsapp/commit/24ac9fbf48f80eeb521a36bc938af3a70dd82303))
* **bot:** :zap: flow improvement + add utils ([a7b19d9](https://github.com/leifermendez/bot-whatsapp/commit/a7b19d9bff5ea66ff888555c3df37ae0e20b612a))
* **bot:** update ([49698bf](https://github.com/leifermendez/bot-whatsapp/commit/49698bfda9d2a53f7b1a7e1724a796698601fbaa))
* **ci:** :zap: balance version ([ec46cfd](https://github.com/leifermendez/bot-whatsapp/commit/ec46cfdd657c08c8e90261613f00cfc080f1e1d6))
* **ci:** :zap: github action ([b827a0a](https://github.com/leifermendez/bot-whatsapp/commit/b827a0ab225b89bb8117c82628db0679c09b4102))
* **ci:** :zap: github action ([4142ca4](https://github.com/leifermendez/bot-whatsapp/commit/4142ca4fd552e7005f3b1397a76b90a2e574d19d))
* **ci:** :zap: github action ([091544a](https://github.com/leifermendez/bot-whatsapp/commit/091544ac3fac0c16925e856e1aec64bcad0ecf6d))
* **ci:** :zap: github action ([2ce342a](https://github.com/leifermendez/bot-whatsapp/commit/2ce342a0cb15019d5084ca06dc30e342b030ea10))
* **ci:** :zap: github action ([7817793](https://github.com/leifermendez/bot-whatsapp/commit/781779328f93ef8b0e6e0f85c6cd05ae782112fb))
* **ci:** :zap: github action ([dfced8c](https://github.com/leifermendez/bot-whatsapp/commit/dfced8c594e9175c81e837af359631ba055b7e1a))
* **ci:** :zap: github action ([aaa4ce8](https://github.com/leifermendez/bot-whatsapp/commit/aaa4ce837229fd51e274de3d91e1d9d615ac69fd))
* **ci:** :zap: github action ([9ddf144](https://github.com/leifermendez/bot-whatsapp/commit/9ddf144244cd6877e7d26f576387814459f2befb))
* **ci:** :zap: github action ([b465de5](https://github.com/leifermendez/bot-whatsapp/commit/b465de55a0e511213d1a7760a74efa102172c85e))
* **ci:** :zap: github action ([cf1dc6f](https://github.com/leifermendez/bot-whatsapp/commit/cf1dc6fac810545e5a2b63f31f71322f37329e38))
* **ci:** :zap: github action ([8d897f8](https://github.com/leifermendez/bot-whatsapp/commit/8d897f824e27a55ca011163092a813a7e8f426af))
* **ci:** ci ([f55cfae](https://github.com/leifermendez/bot-whatsapp/commit/f55cfae6e4ccc1df949212999406680020d27f9c))
* **ci:** ci ([671c5b3](https://github.com/leifermendez/bot-whatsapp/commit/671c5b37f33360e8cb754625b8dd6e83bce9014d))
* **cli:** :bug: path ([32212fb](https://github.com/leifermendez/bot-whatsapp/commit/32212fb52d206bf6f8d753a86d9ce40aa0db2a5d))
* **cli:** :fire: create script - templates ([2319db3](https://github.com/leifermendez/bot-whatsapp/commit/2319db3009501fe57ae21e60ad286eb68c46f4fd))
* **cli:** :fire: create script - templates ([9cb98b5](https://github.com/leifermendez/bot-whatsapp/commit/9cb98b5e73fca3c3f5e70a8497badc31e494b943))
* **cli:** :fire: create script - templates ([2999e0e](https://github.com/leifermendez/bot-whatsapp/commit/2999e0e753f31a8b9e6d7c117e78cdb5656e203a))
* **cli:** :fire: create script - templates ([af716b7](https://github.com/leifermendez/bot-whatsapp/commit/af716b75372899877a81b528b58278376166d0ad))
* **cli:** :fire: create script - templates ([c6999c8](https://github.com/leifermendez/bot-whatsapp/commit/c6999c84931083a87b5717db58003be68244707e))
* **cli:** :fire: create script - templates ([d4b49a9](https://github.com/leifermendez/bot-whatsapp/commit/d4b49a9bd7085070f0c5964d2903f10b71bde0b3))
* **cli:** :fire: create script - templates ([eebc3c9](https://github.com/leifermendez/bot-whatsapp/commit/eebc3c980638d88f11a0d93b8344f3ff345c7ee5))
* **cli:** :zap: clean eslinter ([bfb69d9](https://github.com/leifermendez/bot-whatsapp/commit/bfb69d9a9574a757ae02748b6c5f5afa3eac68e6))
* **cli:** :zap: clean eslinter ([15f6972](https://github.com/leifermendez/bot-whatsapp/commit/15f697225775a0f0e0a440cd980f7fb8f51a1056))
* **cli:** :zap: create-starter ([d3b8310](https://github.com/leifermendez/bot-whatsapp/commit/d3b8310180d2ad813733b1d18f2c32d7d947740a))
* **cli:** :zap: update cli copy ([7797c2b](https://github.com/leifermendez/bot-whatsapp/commit/7797c2b46133697e2a591adab2b67e66b34a1cfe))
* **fix:** fix ([6483545](https://github.com/leifermendez/bot-whatsapp/commit/648354500b123f20044f5ac2e8a26b15f16d1b8d))
* **fix:** fix ([28c0480](https://github.com/leifermendez/bot-whatsapp/commit/28c0480b8bfa6b24394095f57c36ef89c9aeb566))
* **linter:** update linter and commitlint ([70a94ab](https://github.com/leifermendez/bot-whatsapp/commit/70a94ab2c6f8e4122780c77bc3a621944883e621))
* pre-copy fix ([08e2552](https://github.com/leifermendez/bot-whatsapp/commit/08e2552907c48cfeaac843457a18bf2032e6f8aa))
* pre-copy fix ([6617107](https://github.com/leifermendez/bot-whatsapp/commit/6617107ab824215c449e26eae6c2bb327ecfc092))
* **starter:** pre-copy fix ([929e74c](https://github.com/leifermendez/bot-whatsapp/commit/929e74c84b667ec13cb5490b3b951cb8df15ebd1))
* (💍) Is justa test! ([37d04e9](https://github.com/leifermendez/bot-whatsapp/commit/37d04e9e89d3f01fdc367654ba60fb11ab2614c4))
### [0.2.1](https://github.com/leifermendez/bot-whatsapp/compare/v0.2.0...v0.2.1) (2022-12-12)
## 0.2.0 (2022-12-12)
### ⚠ BREAKING CHANGES
* 🧨 NO
### Features
* (🎸) add onClick prop to component ([4ae3898](https://github.com/leifermendez/bot-whatsapp/commit/4ae389846d38c133f6bb2129ae373eed39d9d08d))
* **adapter:** added adapter mysql ([717a7dc](https://github.com/leifermendez/bot-whatsapp/commit/717a7dc95fbc107ec6f55387aff606c47144baa4))
* **adapter:** implementation of json file adapter ([5e1a373](https://github.com/leifermendez/bot-whatsapp/commit/5e1a3737303c843095984f6357564ea18458362f))
* **adapter:** mysql adapter ([8d73c86](https://github.com/leifermendez/bot-whatsapp/commit/8d73c86946d07aa80e5b375b62b84a88b2892e03))
* **adapter:** sql is added to create the table ([4b7de0f](https://github.com/leifermendez/bot-whatsapp/commit/4b7de0f6901524fa2c09271c3a99c364e6b3c260))
* **bot:** :fire: improvement provider handler ([4154cc2](https://github.com/leifermendez/bot-whatsapp/commit/4154cc223091a46d3203d3a378cd42f61749a5fa))
* **bot:** :zap: add send image function ([ce8a96b](https://github.com/leifermendez/bot-whatsapp/commit/ce8a96b958ff814c65d8fb4dbd5eaed5cc83a1ed))
* **ci:** :art: add releases ([b115dc3](https://github.com/leifermendez/bot-whatsapp/commit/b115dc3654996f049837bfb6b5d039a2313df0ad))
* **ci:** :art: relases script ([2e906bc](https://github.com/leifermendez/bot-whatsapp/commit/2e906bce79f7d854d437334e1d0c2cd270b0bbc6))
* **ci:** update ci ([e5a9db7](https://github.com/leifermendez/bot-whatsapp/commit/e5a9db7e12340c4f5baa66e8b20585b63daa3bcf))
* **cli:** create-starter ([3977987](https://github.com/leifermendez/bot-whatsapp/commit/397798790ef5857ca758b0df8384c6a4bfacc181))
* **provider:** :fire: add twilii (weoking) ([4350dff](https://github.com/leifermendez/bot-whatsapp/commit/4350dff22a7de69ba6d35ecbdd67e59b810bd46f))
* **provider:** added twilio provider ([8dd3be9](https://github.com/leifermendez/bot-whatsapp/commit/8dd3be909b36717f6b54e141a5f48d2722d4855c))
* **release:** added ([1988948](https://github.com/leifermendez/bot-whatsapp/commit/1988948c30d922beb7b83faab96d1d59cf7f5f90))
* **release:** added ([f4ad704](https://github.com/leifermendez/bot-whatsapp/commit/f4ad7040abf619635480c30babd6f1159c7af85a))
### Bug Fixes
* **adapter:** conflict resolution ([4b307ef](https://github.com/leifermendez/bot-whatsapp/commit/4b307efe79c738a5c4e04ff1c07ca247d827593c))
* **adapter:** corrections are made to the adapter ([afa6771](https://github.com/leifermendez/bot-whatsapp/commit/afa677190392d48715930ebe2b1e15c7619d730f))
* **bot:** :zap: added delay promises ([73caf09](https://github.com/leifermendez/bot-whatsapp/commit/73caf090ba9013132e5dcb7761a10939dc9ac300))
* **bot:** :zap: fix sensitive case ([24ac9fb](https://github.com/leifermendez/bot-whatsapp/commit/24ac9fbf48f80eeb521a36bc938af3a70dd82303))
* **bot:** :zap: flow improvement + add utils ([a7b19d9](https://github.com/leifermendez/bot-whatsapp/commit/a7b19d9bff5ea66ff888555c3df37ae0e20b612a))
* **bot:** update ([49698bf](https://github.com/leifermendez/bot-whatsapp/commit/49698bfda9d2a53f7b1a7e1724a796698601fbaa))
* **ci:** :zap: balance version ([ec46cfd](https://github.com/leifermendez/bot-whatsapp/commit/ec46cfdd657c08c8e90261613f00cfc080f1e1d6))
* **ci:** :zap: github action ([b827a0a](https://github.com/leifermendez/bot-whatsapp/commit/b827a0ab225b89bb8117c82628db0679c09b4102))
* **ci:** :zap: github action ([4142ca4](https://github.com/leifermendez/bot-whatsapp/commit/4142ca4fd552e7005f3b1397a76b90a2e574d19d))
* **ci:** :zap: github action ([091544a](https://github.com/leifermendez/bot-whatsapp/commit/091544ac3fac0c16925e856e1aec64bcad0ecf6d))
* **ci:** :zap: github action ([2ce342a](https://github.com/leifermendez/bot-whatsapp/commit/2ce342a0cb15019d5084ca06dc30e342b030ea10))
* **ci:** :zap: github action ([7817793](https://github.com/leifermendez/bot-whatsapp/commit/781779328f93ef8b0e6e0f85c6cd05ae782112fb))
* **ci:** :zap: github action ([dfced8c](https://github.com/leifermendez/bot-whatsapp/commit/dfced8c594e9175c81e837af359631ba055b7e1a))
* **ci:** :zap: github action ([aaa4ce8](https://github.com/leifermendez/bot-whatsapp/commit/aaa4ce837229fd51e274de3d91e1d9d615ac69fd))
* **ci:** :zap: github action ([9ddf144](https://github.com/leifermendez/bot-whatsapp/commit/9ddf144244cd6877e7d26f576387814459f2befb))
* **ci:** :zap: github action ([b465de5](https://github.com/leifermendez/bot-whatsapp/commit/b465de55a0e511213d1a7760a74efa102172c85e))
* **ci:** :zap: github action ([cf1dc6f](https://github.com/leifermendez/bot-whatsapp/commit/cf1dc6fac810545e5a2b63f31f71322f37329e38))
* **ci:** :zap: github action ([8d897f8](https://github.com/leifermendez/bot-whatsapp/commit/8d897f824e27a55ca011163092a813a7e8f426af))
* **ci:** ci ([f55cfae](https://github.com/leifermendez/bot-whatsapp/commit/f55cfae6e4ccc1df949212999406680020d27f9c))
* **ci:** ci ([671c5b3](https://github.com/leifermendez/bot-whatsapp/commit/671c5b37f33360e8cb754625b8dd6e83bce9014d))
* **cli:** :bug: path ([32212fb](https://github.com/leifermendez/bot-whatsapp/commit/32212fb52d206bf6f8d753a86d9ce40aa0db2a5d))
* **cli:** :fire: create script - templates ([2319db3](https://github.com/leifermendez/bot-whatsapp/commit/2319db3009501fe57ae21e60ad286eb68c46f4fd))
* **cli:** :fire: create script - templates ([9cb98b5](https://github.com/leifermendez/bot-whatsapp/commit/9cb98b5e73fca3c3f5e70a8497badc31e494b943))
* **cli:** :fire: create script - templates ([2999e0e](https://github.com/leifermendez/bot-whatsapp/commit/2999e0e753f31a8b9e6d7c117e78cdb5656e203a))
* **cli:** :fire: create script - templates ([af716b7](https://github.com/leifermendez/bot-whatsapp/commit/af716b75372899877a81b528b58278376166d0ad))
* **cli:** :fire: create script - templates ([c6999c8](https://github.com/leifermendez/bot-whatsapp/commit/c6999c84931083a87b5717db58003be68244707e))
* **cli:** :fire: create script - templates ([d4b49a9](https://github.com/leifermendez/bot-whatsapp/commit/d4b49a9bd7085070f0c5964d2903f10b71bde0b3))
* **cli:** :fire: create script - templates ([eebc3c9](https://github.com/leifermendez/bot-whatsapp/commit/eebc3c980638d88f11a0d93b8344f3ff345c7ee5))
* **cli:** :zap: clean eslinter ([bfb69d9](https://github.com/leifermendez/bot-whatsapp/commit/bfb69d9a9574a757ae02748b6c5f5afa3eac68e6))
* **cli:** :zap: clean eslinter ([15f6972](https://github.com/leifermendez/bot-whatsapp/commit/15f697225775a0f0e0a440cd980f7fb8f51a1056))
* **cli:** :zap: create-starter ([d3b8310](https://github.com/leifermendez/bot-whatsapp/commit/d3b8310180d2ad813733b1d18f2c32d7d947740a))
* **cli:** :zap: update cli copy ([7797c2b](https://github.com/leifermendez/bot-whatsapp/commit/7797c2b46133697e2a591adab2b67e66b34a1cfe))
* **fix:** fix ([6483545](https://github.com/leifermendez/bot-whatsapp/commit/648354500b123f20044f5ac2e8a26b15f16d1b8d))
* **fix:** fix ([28c0480](https://github.com/leifermendez/bot-whatsapp/commit/28c0480b8bfa6b24394095f57c36ef89c9aeb566))
* **linter:** update linter and commitlint ([70a94ab](https://github.com/leifermendez/bot-whatsapp/commit/70a94ab2c6f8e4122780c77bc3a621944883e621))
* pre-copy fix ([08e2552](https://github.com/leifermendez/bot-whatsapp/commit/08e2552907c48cfeaac843457a18bf2032e6f8aa))
* pre-copy fix ([6617107](https://github.com/leifermendez/bot-whatsapp/commit/6617107ab824215c449e26eae6c2bb327ecfc092))
* **starter:** pre-copy fix ([929e74c](https://github.com/leifermendez/bot-whatsapp/commit/929e74c84b667ec13cb5490b3b951cb8df15ebd1))
* (💍) Is justa test! ([37d04e9](https://github.com/leifermendez/bot-whatsapp/commit/37d04e9e89d3f01fdc367654ba60fb11ab2614c4))
### [0.0.3](https://github.com/leifermendez/bot-whatsapp/compare/v0.2.0...v0.0.3) (2022-12-12)
## 0.2.0 (2022-12-12)
### ⚠ BREAKING CHANGES
* 🧨 NO
### Features
* (🎸) add onClick prop to component ([4ae3898](https://github.com/leifermendez/bot-whatsapp/commit/4ae389846d38c133f6bb2129ae373eed39d9d08d))
* **adapter:** added adapter mysql ([717a7dc](https://github.com/leifermendez/bot-whatsapp/commit/717a7dc95fbc107ec6f55387aff606c47144baa4))
* **adapter:** implementation of json file adapter ([5e1a373](https://github.com/leifermendez/bot-whatsapp/commit/5e1a3737303c843095984f6357564ea18458362f))
* **adapter:** mysql adapter ([8d73c86](https://github.com/leifermendez/bot-whatsapp/commit/8d73c86946d07aa80e5b375b62b84a88b2892e03))
* **adapter:** sql is added to create the table ([4b7de0f](https://github.com/leifermendez/bot-whatsapp/commit/4b7de0f6901524fa2c09271c3a99c364e6b3c260))
* **bot:** :fire: improvement provider handler ([4154cc2](https://github.com/leifermendez/bot-whatsapp/commit/4154cc223091a46d3203d3a378cd42f61749a5fa))
* **bot:** :zap: add send image function ([ce8a96b](https://github.com/leifermendez/bot-whatsapp/commit/ce8a96b958ff814c65d8fb4dbd5eaed5cc83a1ed))
* **ci:** :art: add releases ([b115dc3](https://github.com/leifermendez/bot-whatsapp/commit/b115dc3654996f049837bfb6b5d039a2313df0ad))
* **ci:** :art: relases script ([2e906bc](https://github.com/leifermendez/bot-whatsapp/commit/2e906bce79f7d854d437334e1d0c2cd270b0bbc6))
* **ci:** update ci ([e5a9db7](https://github.com/leifermendez/bot-whatsapp/commit/e5a9db7e12340c4f5baa66e8b20585b63daa3bcf))
* **cli:** create-starter ([3977987](https://github.com/leifermendez/bot-whatsapp/commit/397798790ef5857ca758b0df8384c6a4bfacc181))
* **provider:** :fire: add twilii (weoking) ([4350dff](https://github.com/leifermendez/bot-whatsapp/commit/4350dff22a7de69ba6d35ecbdd67e59b810bd46f))
* **provider:** added twilio provider ([8dd3be9](https://github.com/leifermendez/bot-whatsapp/commit/8dd3be909b36717f6b54e141a5f48d2722d4855c))
* **release:** added ([1988948](https://github.com/leifermendez/bot-whatsapp/commit/1988948c30d922beb7b83faab96d1d59cf7f5f90))
* **release:** added ([f4ad704](https://github.com/leifermendez/bot-whatsapp/commit/f4ad7040abf619635480c30babd6f1159c7af85a))
### Bug Fixes
* **adapter:** conflict resolution ([4b307ef](https://github.com/leifermendez/bot-whatsapp/commit/4b307efe79c738a5c4e04ff1c07ca247d827593c))
* **adapter:** corrections are made to the adapter ([afa6771](https://github.com/leifermendez/bot-whatsapp/commit/afa677190392d48715930ebe2b1e15c7619d730f))
* **bot:** :zap: added delay promises ([73caf09](https://github.com/leifermendez/bot-whatsapp/commit/73caf090ba9013132e5dcb7761a10939dc9ac300))
* **bot:** :zap: fix sensitive case ([24ac9fb](https://github.com/leifermendez/bot-whatsapp/commit/24ac9fbf48f80eeb521a36bc938af3a70dd82303))
* **bot:** :zap: flow improvement + add utils ([a7b19d9](https://github.com/leifermendez/bot-whatsapp/commit/a7b19d9bff5ea66ff888555c3df37ae0e20b612a))
* **bot:** update ([49698bf](https://github.com/leifermendez/bot-whatsapp/commit/49698bfda9d2a53f7b1a7e1724a796698601fbaa))
* **ci:** :zap: balance version ([ec46cfd](https://github.com/leifermendez/bot-whatsapp/commit/ec46cfdd657c08c8e90261613f00cfc080f1e1d6))
* **ci:** :zap: github action ([b827a0a](https://github.com/leifermendez/bot-whatsapp/commit/b827a0ab225b89bb8117c82628db0679c09b4102))
* **ci:** :zap: github action ([4142ca4](https://github.com/leifermendez/bot-whatsapp/commit/4142ca4fd552e7005f3b1397a76b90a2e574d19d))
* **ci:** :zap: github action ([091544a](https://github.com/leifermendez/bot-whatsapp/commit/091544ac3fac0c16925e856e1aec64bcad0ecf6d))
* **ci:** :zap: github action ([2ce342a](https://github.com/leifermendez/bot-whatsapp/commit/2ce342a0cb15019d5084ca06dc30e342b030ea10))
* **ci:** :zap: github action ([7817793](https://github.com/leifermendez/bot-whatsapp/commit/781779328f93ef8b0e6e0f85c6cd05ae782112fb))
* **ci:** :zap: github action ([dfced8c](https://github.com/leifermendez/bot-whatsapp/commit/dfced8c594e9175c81e837af359631ba055b7e1a))
* **ci:** :zap: github action ([aaa4ce8](https://github.com/leifermendez/bot-whatsapp/commit/aaa4ce837229fd51e274de3d91e1d9d615ac69fd))
* **ci:** :zap: github action ([9ddf144](https://github.com/leifermendez/bot-whatsapp/commit/9ddf144244cd6877e7d26f576387814459f2befb))
* **ci:** :zap: github action ([b465de5](https://github.com/leifermendez/bot-whatsapp/commit/b465de55a0e511213d1a7760a74efa102172c85e))
* **ci:** :zap: github action ([cf1dc6f](https://github.com/leifermendez/bot-whatsapp/commit/cf1dc6fac810545e5a2b63f31f71322f37329e38))
* **ci:** :zap: github action ([8d897f8](https://github.com/leifermendez/bot-whatsapp/commit/8d897f824e27a55ca011163092a813a7e8f426af))
* **ci:** ci ([f55cfae](https://github.com/leifermendez/bot-whatsapp/commit/f55cfae6e4ccc1df949212999406680020d27f9c))
* **ci:** ci ([671c5b3](https://github.com/leifermendez/bot-whatsapp/commit/671c5b37f33360e8cb754625b8dd6e83bce9014d))
* **cli:** :bug: path ([32212fb](https://github.com/leifermendez/bot-whatsapp/commit/32212fb52d206bf6f8d753a86d9ce40aa0db2a5d))
* **cli:** :fire: create script - templates ([2319db3](https://github.com/leifermendez/bot-whatsapp/commit/2319db3009501fe57ae21e60ad286eb68c46f4fd))
* **cli:** :fire: create script - templates ([9cb98b5](https://github.com/leifermendez/bot-whatsapp/commit/9cb98b5e73fca3c3f5e70a8497badc31e494b943))
* **cli:** :fire: create script - templates ([2999e0e](https://github.com/leifermendez/bot-whatsapp/commit/2999e0e753f31a8b9e6d7c117e78cdb5656e203a))
* **cli:** :fire: create script - templates ([af716b7](https://github.com/leifermendez/bot-whatsapp/commit/af716b75372899877a81b528b58278376166d0ad))
* **cli:** :fire: create script - templates ([c6999c8](https://github.com/leifermendez/bot-whatsapp/commit/c6999c84931083a87b5717db58003be68244707e))
* **cli:** :fire: create script - templates ([d4b49a9](https://github.com/leifermendez/bot-whatsapp/commit/d4b49a9bd7085070f0c5964d2903f10b71bde0b3))
* **cli:** :fire: create script - templates ([eebc3c9](https://github.com/leifermendez/bot-whatsapp/commit/eebc3c980638d88f11a0d93b8344f3ff345c7ee5))
* **cli:** :zap: clean eslinter ([bfb69d9](https://github.com/leifermendez/bot-whatsapp/commit/bfb69d9a9574a757ae02748b6c5f5afa3eac68e6))
* **cli:** :zap: clean eslinter ([15f6972](https://github.com/leifermendez/bot-whatsapp/commit/15f697225775a0f0e0a440cd980f7fb8f51a1056))
* **cli:** :zap: create-starter ([d3b8310](https://github.com/leifermendez/bot-whatsapp/commit/d3b8310180d2ad813733b1d18f2c32d7d947740a))
* **cli:** :zap: update cli copy ([7797c2b](https://github.com/leifermendez/bot-whatsapp/commit/7797c2b46133697e2a591adab2b67e66b34a1cfe))
* **fix:** fix ([6483545](https://github.com/leifermendez/bot-whatsapp/commit/648354500b123f20044f5ac2e8a26b15f16d1b8d))
* **fix:** fix ([28c0480](https://github.com/leifermendez/bot-whatsapp/commit/28c0480b8bfa6b24394095f57c36ef89c9aeb566))
* **linter:** update linter and commitlint ([70a94ab](https://github.com/leifermendez/bot-whatsapp/commit/70a94ab2c6f8e4122780c77bc3a621944883e621))
* pre-copy fix ([08e2552](https://github.com/leifermendez/bot-whatsapp/commit/08e2552907c48cfeaac843457a18bf2032e6f8aa))
* pre-copy fix ([6617107](https://github.com/leifermendez/bot-whatsapp/commit/6617107ab824215c449e26eae6c2bb327ecfc092))
* **starter:** pre-copy fix ([929e74c](https://github.com/leifermendez/bot-whatsapp/commit/929e74c84b667ec13cb5490b3b951cb8df15ebd1))
* (💍) Is justa test! ([37d04e9](https://github.com/leifermendez/bot-whatsapp/commit/37d04e9e89d3f01fdc367654ba60fb11ab2614c4))
## 0.2.0-alpha.0 (2022-12-01)
### ⚠ 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))
* **linter:** update linter and commitlint ([70a94ab](https://github.com/leifermendez/bot-whatsapp/commit/70a94ab2c6f8e4122780c77bc3a621944883e621))
* (💍) Is justa test! ([37d04e9](https://github.com/leifermendez/bot-whatsapp/commit/37d04e9e89d3f01fdc367654ba60fb11ab2614c4))
## 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 #### Actualización 14 Ene 2022
- npm update - npm update
- remove ora and chalk - remove ora and chalk
- add env - add env

View File

@@ -1,103 +0,0 @@
# CONTRIBUTING
### 📄 Bienvenido/a
Si deseas colaborar con el proyecto existen varias maneras, la primera de ellas es aportando conocimiento y mejorando el repositorio (actualizando documentación, mejorando código, revisando __[issues](https://github.com/codigoencasa/bot-whatsapp/issues)__, etc).
También es bien recibido los aportes económicos que se utilizaran para diferentes fines __[ver más](https://opencollective.com/bot-whatsapp)__
El lenguaje principal que se utilizó para desarrollar este proyecto fue __JavaScript__ con el fin de qué personas que están iniciando en el mundo de la programación puedan entender fácilmente.
### 🤔 Preguntas frecuentes
- ¿Como puedo hacer aportaciones de código en el proyecto?: [Ver Video](https://youtu.be/Lxt8Acob6aU)
- ¿Como ejecutar el entorno de pruebas?: [Ver Video](https://youtu.be/Mf9V-dloBfk)
- ¿Como crear un nuevo proveedor?: [Ver Video](https://youtu.be/cahK9zH3SI8)
- ¿Que son los GithubActions?: [Ver Video](https://youtu.be/nYBEBFKLiqw)
- ¿Canales de comunicación?: [Discord](https://link.codigoencasa.com/DISCORD)
-----
![](https://i.giphy.com/media/ntMt6TvalpstTIx7Ak/giphy.webp)
__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.
- __[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__
```
git clone --branch dev https://github.com/codigoencasa/bot-whatsapp
```
__Instalar dependencias__
```
cd bot-whatsapp
yarn 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
```
__Example-app__
Se ejecuta el CLI (Command Line Interface) para ayudarte a crear un app-bot de ejemplo.
```
yarn 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.
Se creó un subdirecorio con el nombre del proveedor y base de datos que seleccionaste, ejemplo: `base-bailey-mysql`
Dentro de ese directorio necesitas editar el archivo package.json y borrar las siguientes lineas:
```
"@bot-whatsapp/bot": "latest",
"@bot-whatsapp/cli": "latest",
"@bot-whatsapp/database": "latest",
"@bot-whatsapp/provider": "latest",
```
Cambiate al directorio creado ejemplo: `base-bailey-mysql`
```
cd base-baileys-mysql
```
Ejecuta los comandos:
```
npm install
npm run pre-copy
npm start
```
En el caso de MySql y Mongo es necesario especificar en app.js los datos de la conexión, ejemplo de MySql:
```
const BaileysProvider = require('@bot-whatsapp/provider/baileys')
const MySQLAdapter = require('@bot-whatsapp/database/mysql')
/**
* Declaramos las conexiones de MySQL
*/
const MYSQL_DB_HOST = 'localhost'
const MYSQL_DB_USER = 'usr'
const MYSQL_DB_PASSWORD = 'pass'
const MYSQL_DB_NAME = 'bot'
```
<!-- __Seguir instrucciones__
En la consola encontraras los pasos a seguir -->
![](https://i.imgur.com/dC6lEwy.png)
> __NOTA:__ [Eres libre de aportar informacion a este documento o arreglar ortografia 🤣](
https://github.com/codigoencasa/bot-whatsapp/edit/dev/CONTRIBUTING.md)
------
- [Discord](https://link.codigoencasa.com/DISCORD)
- [Twitter](https://twitter.com/leifermendez)
- [Youtube](https://www.youtube.com/watch?v=5lEMCeWEJ8o&list=PL_WGMLcL4jzWPhdhcUyhbFU6bC0oJd2BR)
- [Telegram](https://t.me/leifermendez)

View File

@@ -1,88 +0,0 @@
```js
const {
createBot,
createProvider,
createFlow,
addKeyword,
toSerialize,
} = require('@bot-whatsapp/bot')
const WebWhatsappProvider = require('@bot-whatsapp/provider/web-whatsapp')
const MongoAdapter = require('@bot-whatsapp/database/mongo')
const flowArepa1 = toSerialize(
addKeyword(['1', 'AREPA14'])
.addAnswer('Esta es una arepa calificada ⭐⭐⭐⭐⭐')
.addAnswer(['Ingredientes:', '10g Aguacate', '20g Huevo'].join('\n'))
.toJson()
)
const flowArepa2_2 = toSerialize(
addKeyword('SI').addAnswer('te pongo huevo de mentira!').toJson()
)
const flowArepa2 = toSerialize(
addKeyword(['arepa2'])
.addAnswer('Esta es una arepa calificada ⭐⭐⭐⭐')
.addAnswer(
['Ingredientes:', '10g perico', '20g huevo', '10g queso'].join('\n')
)
.addAnswer(
'Eres Vegano SI o NO',
{
capture: true,
},
null,
[...flowArepa2_2]
)
.toJson()
)
const flowArepa3 = toSerialize(
addKeyword(['arepa3'])
.addAnswer('Esta es una arepa calificada LAMEJOR ⭐⭐⭐⭐⭐')
.toJson()
)
//////////////--MENU--PRINCIPAL--//////////////////
const flujoMenuArepa = addKeyword(['hola', 'ola', 'buenos'])
.addAnswer('Bienvenido "Arepera Aji Picante 🤯🚀😅"')
.addAnswer(
[
'El menú de hoy es el siguiente:',
'👉 [1 -AREPA14] - Arepa tradicional con Aguacate y Huevo',
'👉 [arepa2] - Arepa rellena de perico y huevo con un toque de queso',
'👉 [arepa3] - Rellena de Jamon y Queso',
].join('\n')
)
.addAnswer(
'Esperando respuesta...',
{
capture: true,
},
() => {
console.log('Enviar un mail!')
},
[...flowArepa1, ...flowArepa2, ...flowArepa3]
)
.addAnswer('Gracias!')
const main = async () => {
const adapterDB = new MongoAdapter()
const adapterFlow = createFlow([flujoMenuArepa])
const adapterProvider = createProvider(WebWhatsappProvider)
createBot({
flow: adapterFlow,
provider: adapterProvider,
database: adapterDB,
})
}
main()
```

View File

@@ -1,2 +0,0 @@
CTX: Es el objeto que representa un mensaje, con opciones, id, ref
messageInComming: Objeto entrante del provider {body, from,to,...}

View File

@@ -1,214 +0,0 @@
# Migración
#### Versión (legacy)
En la ***versión (legacy)*** se implementaban los flujos de esta manera, en dos archivos independientes.
> __`initial.json`__ para establecer las palabras claves y el flujo a responder, por otro lado tambien se necesitaba implementar
> __`response.json`__ donde se escriben los mensajes a responder.
```json
//initial.json
[
{
"keywords": [
"hola",
"ola",
"alo"
],
"key": "hola"
},
{
"keywords": ["productos", "info"],
"key": "productos"
},
{
"keywords": ["adios", "bye"],
"key": "adios"
},
{
"keywords": ["imagen", "foto"],
"key": "catalogo"
}
]
```
```json
//response.json
{
"hola":{
"replyMessage":[
"Gracias a ti! \n"
],
"media":null,
"trigger":null
},
"adios":{
"replyMessage":[
"Que te vaya bien!!"
],
},
"productos":{
"replyMessage":[
"Más productos aquí"
],
"trigger":null,
"actions":{
"title":"¿Que te interesa ver?",
"message":"Abajo unos botons",
"footer":"",
"buttons":[
{"body":"Telefonos"},
{"body":"Computadoras"},
{"body":"Otros"}
]
}
},
"catalogo":{
"replyMessage":[
"Te envio una imagen"
],
"media":"https://media2.giphy.com/media/VQJu0IeULuAmCwf5SL/giphy.gif",
"trigger":null,
},
}
```
#### Versión 2 (0.2.X)
En esta versión es mucho más sencillo, abajo encontraras un ejemplo del mismo flujo anteriormente mostrado.
```js
//app.js
const {
createBot,
createProvider,
createFlow,
addKeyword,
addChild,
} = require('@bot-whatsapp/bot')
const BaileysProvider = require('@bot-whatsapp/provider/baileys')
const MockAdapter = require('@bot-whatsapp/database/mock')
/**
* Declarando flujos principales.
*/
const flowHola = addKeyword(['hola', 'ola', 'alo'])
.addAnswer('Bienvenido a tu tienda online!')
const flowAdios = addKeyword(['adios', 'bye'])
.addAnswer('Que te vaya bien!!')
.addAnswer('Hasta luego!')
const flowProductos = addKeyword(['productos', 'info'])
.addAnswer('Te envio una imagen', {
buttons:[
{body:"Telefonos"},
{body:"Computadoras"},
{body:"Otros"}
]
})
const flowCatalogo = addKeyword(['imagen', 'foto'])
.addAnswer('Te envio una imagen', {media:'https://media2.giphy.com/media/VQJu0IeULuAmCwf5SL/giphy.gif'})
const main = async () => {
const adapterDB = new MockAdapter()
const adapterFlow = createFlow([flowHola, flowAdios, flowProductos, flowCatalogo])
const adapterProvider = createProvider(BaileysProvider)
createBot({
flow: adapterFlow,
provider: adapterProvider,
database: adapterDB,
})
}
```
#### Flujos hijos
A continuación se muestra un ejemplo de flujos hijos, estos nos sirven para crear flujos que solo se disparan cuando el flujo anterior es el especificado, ejemplo:
> Menu Principal (Escoge zapatos o bolsos)
> - SubMenu 1 (Elegiste bolsos, ahora escoge piel o tela)
> - Submenu 1.1 (piel)
> - Submenu 2 (Elegiste zapatos, ahora escoge piel o tela)
> - Submenu 2.1 (piel)
El __submenu 1__ solo se va a disparar cuando el flujo anterior sea el __principal__, e igualmente el __submenu 1.1__, solo cuando el flujo anterior sea el __submenu 1__, ejemplo:
```js
/**
* Aqui declaramos los flujos hijos, los flujos se declaran de atras para adelante, es decir que si tienes un flujo de este tipo:
*
* Menu Principal
* - SubMenu 1
* - Submenu 1.1
* - Submenu 2
* - Submenu 2.1
*
* Primero declaras los submenus 1.1 y 2.1, luego el 1 y 2 y al final el principal.
*/
const flowBolsos2 = addKeyword(['bolsos2', '2'])
.addAnswer('🤯 *MUCHOS* bolsos ...')
.addAnswer('y mas bolsos... bla bla')
const flowZapatos2 = addKeyword(['zapatos2', '2'])
.addAnswer('🤯 repito que tengo *MUCHOS* zapatos.')
.addAnswer('y algunas otras cosas.')
const flowZapatos = addKeyword(['1', 'zapatos', 'ZAPATOS'])
.addAnswer('🤯 Veo que elegiste zapatos')
.addAnswer('Tengo muchos zapatos...bla bla')
.addAnswer(
['Manda:', '*(2) Zapatos2*', 'para mas información'],
{ capture: true },
(ctx) => {
console.log('Aqui puedes ver más info del usuario...')
console.log('Puedes enviar un mail, hook, etc..')
console.log(ctx)
},
[...addChild(flowZapatos2)]
)
const flowBolsos = addKeyword(['2', 'bolsos', 'BOLSOS'])
.addAnswer('🙌 Veo que elegiste bolsos')
.addAnswer('Tengo muchos bolsos...bla bla')
.addAnswer(
['Manda:', '*(2) Bolsos2*', 'para mas información.'],
{ capture: true },
(ctx) => {
console.log('Aqui puedes ver más info del usuario...')
console.log('Puedes enviar un mail, hook, etc..')
console.log(ctx)
},
[...addChild(flowBolsos2)]
)
/**
* Declarando flujo principal
*/
const flowPrincipal = addKeyword(['hola', 'ole', 'alo'])
.addAnswer(['Hola, bienvenido a mi tienda', '¿Como puedo ayudarte?'])
.addAnswer(['Tengo:', 'Zapatos', 'Bolsos', 'etc ...'])
.addAnswer(
['Para continuar escribe:', '*(1) Zapatos*', '*(2) Bolsos*'],
{ capture: true },
(ctx) => {
console.log('Aqui puedes ver más info del usuario...')
console.log('Puedes enviar un mail, hook, etc..')
console.log(ctx)
},
[...addChild(flowBolsos), ...addChild(flowZapatos)]
)
```
> Forma parte de este proyecto.
- [Discord](https://link.codigoencasa.com/DISCORD)
- [Twitter](https://twitter.com/leifermendez)
- [Youtube](https://www.youtube.com/watch?v=5lEMCeWEJ8o&list=PL_WGMLcL4jzWPhdhcUyhbFU6bC0oJd2BR)
- [Telegram](https://t.me/leifermendez)

368
README.md
View File

@@ -1,182 +1,212 @@
# Chatbot Library ## Chatbot Whatsapp (OpenSource)
![](https://img.shields.io/npm/v/@bot-whatsapp/bot?color=%2300c200&label=%40bot-whatsapp) #### Actualizado Diciembre 2022
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![](https://img.shields.io/discord/915193197645402142?logo=discord)](https://link.codigoencasa.com/DISCORD)
<p align="center"> Este proyecto es un fork de la **version 1** (legacy) de [Leifer Mendez](https://github.com/leifermendez/bot-whatsapp) y tiene las siguientes modificaciones:
<img width="300" src="https://i.imgur.com/Oauef6t.png">
</p> - Permite **submenus**.
- Un submenú es una regla que **sólo se dispara** cuando la regla anterior es la especificada, los submenus se definen agregando el parametro "```pasoRequerido```" en el **response.json**.
```json
"menu":{
"replyMessage":[
"%saludo%\nHoy es %dia_semana%.\n"
],
"media":null,
"trigger":null
},
"submenu":{
"replyMessage":[
"Este submenu solo se dispara si **ANTES** se disparó la regla 'menu'"
],
"media":null,
"trigger":null,
"pasoRequerido":"menu"
}
```
- Permite **expresiones regulares** en las palabras predefinidas en el initial.json.
- Si queremos usar RegExp, en los "keywords" de **inital.json**, en lugar de un arreglo, debemos usar un string ( quitamos los [] )
y en él usamos "*" para significar cualquier texto y "|" para significar "OR", esto nos permite ser mas flexibles
con los "keywords", por ejemplo, si queremos que el mensaje pueda decir:
"Hola quiero info del paquete" o "Requiero más información"
Ponemos ```*info*``` y la regla se va a disparar porque los dos contienen "info".
Si queremos que se dispare con:
**Con esta librería, puedes construir flujos automatizados de conversación de manera agnóstica al proveedor de WhatsApp,** configurar respuestas automatizadas para preguntas frecuentes, recibir y responder mensajes de manera automatizada, y hacer un seguimiento de las interacciones con los clientes.  Además, puedes configurar fácilmente disparadores que te ayudaran a expandir las funcionalidades sin límites. **[Ver más informacion](https://bot-whatsapp.netlify.app/)** "Quiero info del paquete numero 3" o "Me gustó el paquete de Angular"
## Comenzar
Ponemos ```*paquete*3*|*paquete*angular*``` y la regla se va a disparar porque contiene "paquete" y "3" -O- "paquete" y "angular".
```json
{
"keywords": "*pak*3*|*pak*angular*|*paquete*3*|*paquete*angular*",
"key": "paq3"
}
```
- Permite **remplazos** en el texto de los mensajes por ejemplo:
- __%saludo%__ para que aparezca "Buenos días, tardes o noches" dependiendo de la hora.
- __%primer_nombre%__ para que aparezca el nombre (hasta el primer espacio) del remitente.
- __%dia_semana%__ para que aparezca "lunes, martes, miercoles, etc" dependiendo del día de la semana.
- __%msjant_XX%__ para que aparezca el mensaje xx anterior, es decir, si quieres mostrar el texto de 2 mensajes anteriores se pone %msjant_2%.
- etc, etc, se pueden agregar mas remplazos en la funcion "remplazos" en el archivo "adapter\index.js".
- Las modificaciones están enfocadas al uso de los archivos __initial.json__ y __response.json__, yo no uso MySQL o DialogFlow, así que no sé si las modificaciones funcionen con esos modulos, en particular el __remplazo %msjant_XX%__ depende de los archivos __JSON__ que se crean en el directorio "chats".
- Tiene agregado el parche de **botones y listas**, así que funcionan sin problema (las listas no funcionan si el bot esta ligado a un número que use **Whatsapp Business**).
- Tiene los ultimos parches de **DialogFlow** (27-dic-2022) (When Dialogflow asks for an Image, then **Upload it to Google Drive** and then generate Shared Link)
## INICIA DOCUMENTACION DEL PROYECTO ORIGINAL
El siguiente proyecto se realizó con fines educativos para el canal de [Youtube (Leifer Mendez)](https://www.youtube.com/channel/UCgrIGp5QAnC0J8LfNJxDRDw?sub_confirmation=1) donde aprendemos a crear y implementar un chatbot increíble usando [node.js](https://codigoencasa.com/tag/nodejs/) además le agregamos inteligencia artificial gracias al servicio de __dialogflow__.
[![Video](https://i.giphy.com/media/OBDi3CXC83WkNeLEZP/giphy.webp)](https://youtu.be/5lEMCeWEJ8o)
### ATENCION 🔴
> 💥💥 Si te aparece el Error Multi-device es porque tienes la cuenta de whatsapp afiliada al modo "BETA de Multi dispositivo" por el momento no se tiene soporte para esas personas si tu quieres hacer uso de este __BOT__ debes de salir del modo BETA y intentarlo de la manera tradicional
> El core de whatsapp esta en constante actualizaciones por lo cual siempre revisa la ultima fecha de la actualizacion
> [VER](https://github.com/leifermendez/bot-whatsapp/commits/main)
### Busco colaboradores ⭐
Hola amigos me gusta mucho este proyecto pero por cuestiones de tiempo se me dificulta mantener las actualizaciones si alguno quieres participar en el proyecto escribeme a leifer.contacto@gmail.com
#### Acceso rápido
> Si tienes una cuenta en __heroku__ puedes desplegar este proyecto con (1 click)
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/leifermendez/bot-whatsapp)
> Comprarme un cafe!
[![Comprar](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/leifermendez)
#### Actualización
| Feature | Status |
| ------------- | ------------- |
| Dialogflow | ✅ |
| MySQL | ✅ |
| JSON File | ✅ |
| QR Scan (route) | ✅ |
| Easy deploy heroku | ✅ |
| Buttons | ✅ℹ️ (No funciona en multi-device)|
| Send Voice Note | ✅ |
| Add support ubuntu/linux | ✅ |
## Requisitos
- node v14 o superior
- VSCode (Editor de codigo) [Descargar](https://code.visualstudio.com/download)
- MySql (opcional) solo aplica si vas a usar el modo 'mysql' [sql-bot.sql migración](https://github.com/leifermendez/bot-whatsapp/blob/main/sql-bot.sql)
- Dialogflow (opcional) solo aplica si vas a usar el modo 'dialogflow'
### (Nuevo) Botones
[![btn](https://i.imgur.com/W7oYlSu.png)](https://youtu.be/5lEMCeWEJ8o)
> Implementar los botones solo necesitas hacer uso del metodo __sendMessageButton__ que se encuentra dentro `./controllers/send` dejo un ejemplo de como usarlo.
[Ver implementación](https://github.com/leifermendez/bot-whatsapp/blob/main/app.js#L123)
``` javascript
const { sendMessageButton } = require('./controllers/send')
await sendMessageButton(
{
"title":"¿Que te interesa ver?",
"message":"Recuerda todo este contenido es gratis y estaria genial que me siguas!",
"footer":"Gracias",
"buttons":[
{"body":"😎 Cursos"},
{"body":"👉 Youtube"},
{"body":"😁 Telegram"}
]
}
)
``` ```
npm create bot-whatsapp@latest
## Notas de Voz
[![voice note](https://i.imgur.com/zq6xYDp.png)](https://i.imgur.com/zq6xYDp.png)
> Se pueden enviar notas de voz con formato nativo para que no se vea como reenviado. En este ejemplo enviare el archivo __PTT-20220223-WA0000.opus__ que se encuentra dentro de la carpeta de __/mediaSend__
``` javascript
const { sendMediaVoiceNote } = require('./controllers/send')
await sendMediaVoiceNote(client, from, 'PTT-20220223-WA0000.opus')
``` ```
Entiende más a fondo sus funcionalidades explicadas en nuestra documentación. ## Instruciones
__Descargar o Clonar repositorio__
![](https://i.imgur.com/dSpUbFz.png)
- Instalacion __Usas ¿Ubuntu / Linux?__
- Base de datos > Asegurate de instalar los siguientes paquetes
- Proveedores ```
sudo apt-get install -y libgbm-dev
sudo apt install -y gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
```
## Recursos __Instalar dependencias (npm install)__
- [📄 Documentación](https://bot-whatsapp.netlify.app/) > Ubicate en le directorio que descargaste y via consola o terminal ejecuta el siguiente comando
- [🚀 Roadmap](https://github.com/orgs/codigoencasa/projects/1)
- [💻 Discord](https://link.codigoencasa.com/DISCORD)
- [👌 Twitter](https://twitter.com/leifermendez)
- [🎥 Youtube](https://www.youtube.com/watch?v=5lEMCeWEJ8o&list=PL_WGMLcL4jzWPhdhcUyhbFU6bC0oJd2BR)
## Comunidad `npm install`
<!-- readme: collaborators,contributors -start -->
<table>
<tr>
<td align="center">
<a href="https://github.com/cheveguerra">
<img src="https://avatars.githubusercontent.com/u/5891114?v=4" width="50;" alt="cheveguerra"/>
<br />
<sub><b>Jose Alberto Guerra Ugalde</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/leifermendez">
<img src="https://avatars.githubusercontent.com/u/15802366?v=4" width="50;" alt="leifermendez"/>
<br />
<sub><b>Leifer Mendez</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/leifermendezfroged">
<img src="https://avatars.githubusercontent.com/u/97020486?v=4" width="50;" alt="leifermendezfroged"/>
<br />
<sub><b>Leifer Mendez</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/vicente1992">
<img src="https://avatars.githubusercontent.com/u/57806030?v=4" width="50;" alt="vicente1992"/>
<br />
<sub><b>Manuel Vicente Ortiz</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/danielcasta0398">
<img src="https://avatars.githubusercontent.com/u/98791147?v=4" width="50;" alt="danielcasta0398"/>
<br />
<sub><b>Juan Daniel Castaño</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/aurik3">
<img src="https://avatars.githubusercontent.com/u/37228512?v=4" width="50;" alt="aurik3"/>
<br />
<sub><b>Null</b></sub>
</a>
</td></tr>
<tr>
<td align="center">
<a href="https://github.com/marianarolfo">
<img src="https://avatars.githubusercontent.com/u/68322254?v=4" width="50;" alt="marianarolfo"/>
<br />
<sub><b>Null</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/HKong31">
<img src="https://avatars.githubusercontent.com/u/113340082?v=4" width="50;" alt="HKong31"/>
<br />
<sub><b>HLKong</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/jzvi12">
<img src="https://avatars.githubusercontent.com/u/10729787?v=4" width="50;" alt="jzvi12"/>
<br />
<sub><b>Zvi</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/JosephVTX">
<img src="https://avatars.githubusercontent.com/u/91026290?v=4" width="50;" alt="JosephVTX"/>
<br />
<sub><b>Joseph Vega Callupe</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/Gonzalito87">
<img src="https://avatars.githubusercontent.com/u/100331586?v=4" width="50;" alt="Gonzalito87"/>
<br />
<sub><b>Null</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/devrlbusiness">
<img src="https://avatars.githubusercontent.com/u/66280283?v=4" width="50;" alt="devrlbusiness"/>
<br />
<sub><b>Developer RL Business</b></sub>
</a>
</td></tr>
<tr>
<td align="center">
<a href="https://github.com/Gregoriotecnico">
<img src="https://avatars.githubusercontent.com/u/118696506?v=4" width="50;" alt="Gregoriotecnico"/>
<br />
<sub><b>Null</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/jlferrete">
<img src="https://avatars.githubusercontent.com/u/36698913?v=4" width="50;" alt="jlferrete"/>
<br />
<sub><b>Jose Luis Ferrete Olarte</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/lisandroprada">
<img src="https://avatars.githubusercontent.com/u/7232326?v=4" width="50;" alt="lisandroprada"/>
<br />
<sub><b>Null</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/6rak0">
<img src="https://avatars.githubusercontent.com/u/12260031?v=4" width="50;" alt="6rak0"/>
<br />
<sub><b>Null</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/Jhonarias13">
<img src="https://avatars.githubusercontent.com/u/19483021?v=4" width="50;" alt="Jhonarias13"/>
<br />
<sub><b>Jhon Freiman Arias</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/tonyvazgar">
<img src="https://avatars.githubusercontent.com/u/21047090?v=4" width="50;" alt="tonyvazgar"/>
<br />
<sub><b>Luis Antonio Vázquez García</b></sub>
</a>
</td></tr>
<tr>
<td align="center">
<a href="https://github.com/rrruuuyyy">
<img src="https://avatars.githubusercontent.com/u/33061671?v=4" width="50;" alt="rrruuuyyy"/>
<br />
<sub><b>Rodrigo Mendoza Cabrera</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/yond1994">
<img src="https://avatars.githubusercontent.com/u/47557263?v=4" width="50;" alt="yond1994"/>
<br />
<sub><b>Yonathan Suarez</b></sub>
</a>
</td></tr>
</table>
<!-- readme: collaborators,contributors -end -->
![](https://i.imgur.com/BJuMjGR.png)
__Configurar .env__
> Con el editor de texto crea un archivo `.env` el cual debes de guiarte del archivo `.env.example`
[Ver video explicando](https://youtu.be/5lEMCeWEJ8o?t=381)
```
######DATABASE: none, mysql, dialogflow
DEFAULT_MESSAGE=true
SAVE_MEDIA=true
PORT=3000
DATABASE=none
LANGUAGE=es
SQL_HOST=
SQL_USER=
SQL_PASS=
SQL_DATABASE=
```
![](https://i.imgur.com/9poNnW0.png)
__Ejecutar el script__
> Ubicate en le directorio que descargaste y via consola o terminal ejecuta el siguiente comando
`npm run start`
![](https://i.imgur.com/eMkBkuJ.png)
__Whatsapp en tu celular__
> Ahora abre la aplicación de Whatsapp en tu dispositivo y escanea el código QR
<img src="https://i.imgur.com/RSbPtat.png" width="500" />
Visitar la pagina
`http://localhost:3000/qr`
![](https://i.imgur.com/Q3JEDlP.png)
__Listo 😎__
> Cuando sale este mensaje tu BOT está __listo__ para trabajar!
![](https://i.imgur.com/eoJ4Ruk.png)
# ¿Quieres ver como se creó? 🤖
- [Ver Video 1](https://www.youtube.com/watch?v=A_Xu0OR_HkE)
- [¿Como instalarlo? (Actulización)](https://youtu.be/5lEMCeWEJ8o)
## ¿Como usarlo el chatbot de whatsapp?
> Escribe un mensaje al whatsapp que vinculaste con tu BOT
![](https://i.imgur.com/OSUgljQ.png)
> Ahora deberías obtener un arespuesta por parte del BOT como la siguiente, ademas de esto tambien se crea un archivo excel
con el historial de conversación con el número de tu cliente
![](https://i.imgur.com/lrMLgR8.png)
![](https://i.imgur.com/UYcoUSV.png)
## Preguntar al BOT
> Puedes interactuar con el bot ejemplo escribele __hola__ y el bot debe responderte!
![](https://i.imgur.com/cNAS51I.png)

51
TODO.md
View File

@@ -1,51 +0,0 @@
### Genral
- [X] __(doc)__ Video de como colaborar PR
- [ ] __(doc)__ Video implementación de test y cobertura
- [ ] __(doc)__ Video explicacion de github action
- [ ] Crear packages list externas
### @bot-whatsapp/bot
- [X] agregar export package
- [X] Posibilidad de en el capture meter todo un nuevo CTX de FLOW .addAnswer('Marca la opcion',{capture:true, join:CTX})
- [X] .addKeyword('1') no funciona con 1 caracter
- [X] sensitivy viene activado por defecto
- [X] fallback respuesta en hijo: Se puede colocar en option el ref de la answer fallback
- [X] Cuando Envian Sticket devuelve mensaje raro
- [x] addAnswer agregar delay
- [ ] colocar mensaje esperando conectando whatsapp (provider)
- [ ] createDatabase validar implementacion de funciones
- [ ] limitar caracteres de mensajes 4000
- [X] cuando envias numeros (5 o 1) se dispara el flujo
### @bot-whatsapp/database
- [X] agregar export package
- [X] __(doc):__ Video para explicar como implementar nuevos database
- [X] Mongo adapter
- [X] MySQL adapter
- [ ] JsonFile adapter
### @bot-whatsapp/provider
- [X] agregar export package
- [ ] __(doc):__ Video para explicar como implementar nuevos providers
- [X] WhatsappWeb provider enviar imagenes
- [X] WhatsappWeb provider enviar audio
- [X] WhatsappWeb botones (Tiene truco) github:leifermendez/whatsapp-web.js
- [ ] Twilio adapter
- [ ] Meta adapter
### @bot-whatsapp/cli
- [X] Hacer comando para crear `example-app`
### @bot-whatsapp/create-bot
- [ ]
### Starters
- [X] Base
- [X] Basico
- [ ] Enviando Imagen
- [ ] Enviando Botones
- [ ] Mezclando flujos hijos
### Extra
- [X] Crear CI mantener fork update https://stackoverflow.com/questions/23793062/can-forks-be-synced-automatically-in-github

1
Whatsapp-Bot.ps1 Normal file
View File

@@ -0,0 +1 @@
npm start

View File

@@ -1,50 +0,0 @@
const MOCK_DB = require('../packages/database/src/mock')
const PROVIDER_DB = require('../packages/provider/src/mock')
class MOCK_FLOW {
allCallbacks = { ref: () => 1 }
flowSerialize = []
flowRaw = []
find = (arg) => {
if (arg) {
return [{ answer: 'answer', ref: 'ref' }]
} else {
return null
}
}
findBySerialize = () => ({})
findIndexByRef = () => 0
}
const cleaName = (name) => {
name = name.toLowerCase()
name = name.replaceAll(' ', '-')
name = name.replaceAll(':', '-')
name = name.replaceAll('"', '-')
return name
}
/**
* Preparar env para el test
* @param {*} context
*/
const setup = async (context) => {
const name = cleaName(`${context.__suite__}-${context.__test__}`)
const filename = `test-${name}.json`
context.provider = new PROVIDER_DB()
context.database = new MOCK_DB({ filename })
context.flow = new MOCK_FLOW()
await delay(10)
}
const clear = async (context) => {
context.provider = null
context.database = null
context.flow = null
}
function delay(ms) {
return new Promise((res) => setTimeout(res, ms))
}
module.exports = { setup, clear, delay }

View File

@@ -1,21 +0,0 @@
const ProviderClass = require('../packages/bot/provider/provider.class')
class MockProvider extends ProviderClass {
constructor() {
super()
}
delaySendMessage = (miliseconds, eventName, payload) =>
new Promise((res) =>
setTimeout(() => {
this.emit(eventName, payload)
res
}, miliseconds)
)
sendMessage = async (userId, message) => {
console.log(`Enviando... ${userId}, ${message}`)
return Promise.resolve({ userId, message })
}
}
module.exports = MockProvider

View File

@@ -1,51 +0,0 @@
const { suite } = require('uvu')
const assert = require('uvu/assert')
const { addKeyword, createBot, createFlow } = require('../packages/bot/index')
const { setup, clear, delay } = require('../__mocks__/env')
const suiteCase = suite('Flujo: Simple')
suiteCase.before.each(setup)
suiteCase.after.each(clear)
suiteCase(`Responder a "hola"`, async ({ database, provider }) => {
const flow = addKeyword('hola').addAnswer('Buenas!').addAnswer('Como vamos!')
createBot({
database,
provider,
flow: createFlow([flow]),
})
await provider.delaySendMessage(0, 'message', {
from: '000',
body: 'hola',
})
await delay(10)
assert.is('Buenas!', database.listHistory[0].answer)
assert.is('Como vamos!', database.listHistory[1].answer)
assert.is(undefined, database.listHistory[2])
})
suiteCase(`NO reponder a "pepe"`, async ({ database, provider }) => {
const flow = addKeyword('hola').addAnswer('Buenas!').addAnswer('Como vamos!')
createBot({
database,
provider,
flow: createFlow([flow]),
})
await provider.delaySendMessage(0, 'message', {
from: '000',
body: 'pepe',
})
await delay(100)
assert.is(undefined, database.listHistory[0])
assert.is(undefined, database.listHistory[1])
})
suiteCase.run()

View File

@@ -1,31 +0,0 @@
const { suite } = require('uvu')
const assert = require('uvu/assert')
const { addKeyword, createBot, createFlow } = require('../packages/bot/index')
const { setup, clear, delay } = require('../__mocks__/env')
const suiteCase = suite('Flujo: Provider envia un location')
suiteCase.before.each(setup)
suiteCase.after.each(clear)
suiteCase(`Responder a "CURRENT_LOCATION"`, async ({ database, provider }) => {
const flow = addKeyword('#CURRENT_LOCATION#').addAnswer('Gracias por tu location')
createBot({
database,
provider,
flow: createFlow([flow]),
})
await provider.delaySendMessage(0, 'message', {
from: '000',
body: '#CURRENT_LOCATION#',
})
await delay(200)
const getHistory = database.listHistory.map((i) => i.answer)
assert.is('Gracias por tu location', getHistory[0])
assert.is(undefined, getHistory[1])
})
suiteCase.run()

View File

@@ -1,51 +0,0 @@
const { suite } = require('uvu')
const assert = require('uvu/assert')
const { addKeyword, createBot, createFlow } = require('../packages/bot/index')
const { setup, clear, delay } = require('../__mocks__/env')
const suiteCase = suite('Flujo: sensitive')
suiteCase.before.each(setup)
suiteCase.after.each(clear)
suiteCase(`Responder a "ole" en minuscula`, async ({ database, provider }) => {
const flow = addKeyword(['ola', 'ole'], { sensitive: true }).addAnswer('Bienvenido a la OLA')
createBot({
database,
provider,
flow: createFlow([flow]),
})
await provider.delaySendMessage(0, 'message', {
from: '000',
body: 'ole',
})
await delay(100)
assert.is('Bienvenido a la OLA', database.listHistory[0].answer)
assert.is(undefined, database.listHistory[1])
})
suiteCase(`NO Responder a "ole" en minuscula`, async ({ database, provider }) => {
const flow = addKeyword(['ola', 'ole'], { sensitive: true }).addAnswer('Bienvenido a la OLA')
createBot({
database,
provider,
flow: createFlow([flow]),
})
await provider.delaySendMessage(0, 'message', {
from: '000',
body: 'OLE',
})
await delay(100)
assert.is(undefined, database.listHistory[0])
assert.is(undefined, database.listHistory[1])
})
suiteCase.run()

View File

@@ -1,89 +0,0 @@
const { suite } = require('uvu')
const assert = require('uvu/assert')
const { addKeyword, createBot, createFlow } = require('../packages/bot/index')
const { setup, clear, delay } = require('../__mocks__/env')
const fakeHTTP = async () => {
await delay(10)
}
const suiteCase = suite('Flujo: hijos con callbacks')
suiteCase.before.each(setup)
suiteCase.after.each(clear)
suiteCase(`Debe continuar el flujo del hijo`, async ({ database, provider }) => {
const flowCash = addKeyword('cash').addAnswer('Traeme los billetes! 😎')
const flowOnline = addKeyword('paypal')
.addAnswer('Voy generar un link de paypal *escribe algo*', { capture: true }, async (_, { flowDynamic }) => {
await fakeHTTP()
await flowDynamic('Esperate.... estoy generando esto toma su tiempo')
})
.addAnswer('Aqui lo tienes 😎😎', null, async (_, { flowDynamic }) => {
await fakeHTTP()
await flowDynamic('http://paypal.com')
})
.addAnswer('Apurate!')
const flujoPrincipal = addKeyword('hola')
.addAnswer('¿Como estas todo bien?')
.addAnswer('Espero que si')
.addAnswer('¿Cual es tu email?', { capture: true }, async (ctx, { fallBack }) => {
if (!ctx.body.includes('@')) {
return fallBack('Veo que no es um mail *bien*')
}
})
.addAnswer('Voy a validar tu email...', null, async (_, { flowDynamic }) => {
await fakeHTTP()
return flowDynamic('Email validado correctamten!')
})
.addAnswer('¿Como vas a pagar *paypal* o *cash*?', { capture: true }, async () => {}, [flowCash, flowOnline])
createBot({
database,
flow: createFlow([flujoPrincipal]),
provider,
})
await provider.delaySendMessage(0, 'message', {
from: '000',
body: 'hola',
})
await provider.delaySendMessage(30, 'message', {
from: '000',
body: 'test@test.com',
})
await provider.delaySendMessage(60, 'message', {
from: '000',
body: 'paypal',
})
await provider.delaySendMessage(90, 'message', {
from: '000',
body: 'continue!',
})
await delay(800)
const getHistory = database.listHistory.map((i) => i.answer)
assert.is('¿Como estas todo bien?', getHistory[0])
assert.is('Espero que si', getHistory[1])
assert.is('¿Cual es tu email?', getHistory[2])
assert.is('test@test.com', getHistory[3])
assert.is('Voy a validar tu email...', getHistory[4])
assert.is('Email validado correctamten!', getHistory[5])
assert.is('¿Como vas a pagar *paypal* o *cash*?', getHistory[6])
assert.is('paypal', getHistory[7])
assert.is('Voy generar un link de paypal *escribe algo*', getHistory[8])
assert.is('continue!', getHistory[9])
assert.is('Esperate.... estoy generando esto toma su tiempo', getHistory[10])
assert.is('Aqui lo tienes 😎😎', getHistory[11])
assert.is('http://paypal.com', getHistory[12])
assert.is('Apurate!', getHistory[13])
assert.is(undefined, getHistory[14])
})
suiteCase.run()

View File

@@ -1,59 +0,0 @@
const { suite } = require('uvu')
const assert = require('uvu/assert')
const { addKeyword, createBot, createFlow } = require('../packages/bot/index')
const { setup, clear, delay } = require('../__mocks__/env')
const suiteCase = suite('Flujo: regex')
suiteCase.before.each(setup)
suiteCase.after.each(clear)
suiteCase(`Responder a una expresion regular`, async ({ database, provider }) => {
const REGEX_CREDIT_NUMBER = `/(^4[0-9]{12}(?:[0-9]{3})?$)|(^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$)|(3[47][0-9]{13})|(^3(?:0[0-5]|[68][0-9])[0-9]{11}$)|(^6(?:011|5[0-9]{2})[0-9]{12}$)|(^(?:2131|1800|35\d{3})\d{11}$)/gm`
const flow = addKeyword(REGEX_CREDIT_NUMBER, { regex: true })
.addAnswer(`Gracias por proporcionar un numero de tarjeta valido`)
.addAnswer('Fin!')
createBot({
database,
provider,
flow: createFlow([flow]),
})
await provider.delaySendMessage(0, 'message', {
from: '000',
body: '374245455400126',
})
await delay(100)
assert.is('Gracias por proporcionar un numero de tarjeta valido', database.listHistory[0].answer)
assert.is('Fin!', database.listHistory[1].answer)
assert.is(undefined, database.listHistory[2])
})
suiteCase(`NO Responder a una expresion regular`, async ({ database, provider }) => {
const REGEX_CREDIT_NUMBER = `/(^4[0-9]{12}(?:[0-9]{3})?$)|(^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$)|(3[47][0-9]{13})|(^3(?:0[0-5]|[68][0-9])[0-9]{11}$)|(^6(?:011|5[0-9]{2})[0-9]{12}$)|(^(?:2131|1800|35\d{3})\d{11}$)/gm`
const flow = addKeyword(REGEX_CREDIT_NUMBER, { regex: true })
.addAnswer(`Gracias por proporcionar un numero de tarjeta valido`)
.addAnswer('Fin!')
createBot({
database,
provider,
flow: createFlow([flow]),
})
await provider.delaySendMessage(0, 'message', {
from: '000',
body: 'hola',
})
await delay(100)
assert.is(undefined, database.listHistory[0])
assert.is(undefined, database.listHistory[1])
})
suiteCase.run()

View File

@@ -1,40 +0,0 @@
const { suite } = require('uvu')
const assert = require('uvu/assert')
const { addKeyword, createBot, createFlow } = require('../packages/bot/index')
const { setup, clear, delay } = require('../__mocks__/env')
const suiteCase = suite('Flujo: capture')
suiteCase.before.each(setup)
suiteCase.after.each(clear)
suiteCase(`Responder a "pregunta"`, async ({ database, provider }) => {
const flow = addKeyword(['hola'])
.addAnswer(['Hola como estas?', '¿Cual es tu edad?'], { capture: true })
.addAnswer('Gracias por tu respuesta')
createBot({
database,
provider,
flow: createFlow([flow]),
})
await provider.delaySendMessage(0, 'message', {
from: '000',
body: 'hola',
})
await provider.delaySendMessage(10, 'message', {
from: '000',
body: '90',
})
await delay(100)
assert.is(['Hola como estas?', '¿Cual es tu edad?'].join('\n'), database.listHistory[0].answer)
assert.is('90', database.listHistory[1].answer)
assert.is('Gracias por tu respuesta', database.listHistory[2].answer)
assert.is(undefined, database.listHistory[3])
})
suiteCase.run()

View File

@@ -1,162 +0,0 @@
const { suite } = require('uvu')
const assert = require('uvu/assert')
const { addKeyword, createBot, createFlow } = require('../packages/bot/index')
const { setup, clear, delay } = require('../__mocks__/env')
const fakeHTTP = async (fakeData = []) => {
await delay(50)
const data = fakeData.map((u) => ({ body: `${u}` }))
return Promise.resolve(data)
}
const suiteCase = suite('Flujo: flowDynamic')
suiteCase.before.each(setup)
suiteCase.after.each(clear)
suiteCase(`Responder con mensajes asyncronos`, async ({ database, provider }) => {
const MOCK_VALUES = [
'Bienvenido te envio muchas marcas (5510)',
'Seleccione marca del auto a cotizar, con el *número* correspondiente',
'Seleccione la sub marca del auto a cotizar, con el *número* correspondiente:',
'Los precios rondan:',
]
const flow = addKeyword(['hola'])
.addAnswer(MOCK_VALUES[0], null, async (_, { flowDynamic }) => {
const data = await fakeHTTP(['Ford', 'GM', 'BMW'])
return flowDynamic(data)
})
.addAnswer(MOCK_VALUES[1], null, async (_, { flowDynamic }) => {
const data = await fakeHTTP(['Ranger', 'Explorer'])
return flowDynamic(data)
})
.addAnswer(MOCK_VALUES[2], null, async (_, { flowDynamic }) => {
const data = await fakeHTTP(['Usado', 'Nuevos'])
return flowDynamic(data)
})
.addAnswer(MOCK_VALUES[3], null, async (_, { flowDynamic }) => {
const data = await fakeHTTP(['1000', '2000', '3000'])
return flowDynamic(data)
})
createBot({
database,
provider,
flow: createFlow([flow]),
})
await provider.delaySendMessage(0, 'message', {
from: '000',
body: 'hola',
})
await delay(1500)
const getHistory = database.listHistory.map((i) => i.answer)
assert.is(MOCK_VALUES[0], getHistory[0])
//FlowDynamic
assert.is('Ford', getHistory[1])
assert.is('GM', getHistory[2])
assert.is('BMW', getHistory[3])
assert.is(MOCK_VALUES[1], getHistory[4])
//FlowDynamic
assert.is('Ranger', getHistory[5])
assert.is('Explorer', getHistory[6])
assert.is(MOCK_VALUES[2], getHistory[7])
//FlowDynamic
assert.is('Usado', getHistory[8])
assert.is('Nuevos', getHistory[9])
assert.is(MOCK_VALUES[3], getHistory[10])
//FlowDynamic
assert.is('1000', getHistory[11])
assert.is('2000', getHistory[12])
assert.is('3000', getHistory[13])
assert.is(undefined, getHistory[14])
})
suiteCase(`Responder con un "string"`, async ({ database, provider }) => {
const flow = addKeyword(['hola'])
.addAnswer('Como vas?', null, async (_, { flowDynamic }) => {
return flowDynamic('Todo bien!')
})
.addAnswer('y vos?')
createBot({
database,
provider,
flow: createFlow([flow]),
})
await provider.delaySendMessage(0, 'message', {
from: '000',
body: 'hola',
})
await delay(100)
const getHistory = database.listHistory.map((i) => i.answer)
assert.is('Como vas?', getHistory[0])
assert.is('Todo bien!', getHistory[1])
assert.is('y vos?', getHistory[2])
assert.is(undefined, getHistory[3])
})
suiteCase(`Responder con un "array"`, async ({ database, provider }) => {
const flow = addKeyword(['hola'])
.addAnswer('Como vas?', null, async (_, { flowDynamic }) => {
return flowDynamic(['Todo bien!', 'trabajando'])
})
.addAnswer('y vos?')
createBot({
database,
provider,
flow: createFlow([flow]),
})
await provider.delaySendMessage(0, 'message', {
from: '000',
body: 'hola',
})
await delay(100)
const getHistory = database.listHistory.map((i) => i.answer)
assert.is('Como vas?', getHistory[0])
assert.is('Todo bien!', getHistory[1])
assert.is('trabajando', getHistory[2])
assert.is('y vos?', getHistory[3])
assert.is(undefined, getHistory[4])
})
suiteCase(`Responder con un "object"`, async ({ database, provider }) => {
const flow = addKeyword(['hola'])
.addAnswer('Como vas?', null, async (_, { flowDynamic }) => {
return flowDynamic([{ body: 'Todo bien!' }])
})
.addAnswer('y vos?')
createBot({
database,
provider,
flow: createFlow([flow]),
})
await provider.delaySendMessage(0, 'message', {
from: '000',
body: 'hola',
})
await delay(100)
const getHistory = database.listHistory.map((i) => i.answer)
assert.is('Como vas?', getHistory[0])
assert.is('Todo bien!', getHistory[1])
assert.is('y vos?', getHistory[2])
assert.is(undefined, getHistory[3])
})
suiteCase.run()

View File

@@ -1,167 +0,0 @@
const { suite } = require('uvu')
const assert = require('uvu/assert')
const { addKeyword, createBot, createFlow } = require('../packages/bot/index')
const { setup, clear, delay } = require('../__mocks__/env')
const fakeHTTP = async (fakeData = []) => {
await delay(50)
const data = fakeData.map((u) => ({ body: `${u}` }))
return Promise.resolve(data)
}
const suiteCase = suite('Flujo: endFlow')
suiteCase.before.each(setup)
suiteCase.after.each(clear)
suiteCase(`Detener el flujo`, async ({ database, provider }) => {
const MOCK_VALUES = [
'Bienvenido te envio muchas marcas',
'Seleccione marca del auto a cotizar, con el *número* correspondiente',
'Seleccione la sub marca del auto a cotizar, con el *número* correspondiente:',
'Los precios rondan:',
]
const flow = addKeyword(['hola'])
.addAnswer(MOCK_VALUES[0], null, async (_, { flowDynamic }) => {
const data = await fakeHTTP(['Ford', 'GM', 'BMW'])
return flowDynamic(data)
})
.addAnswer(MOCK_VALUES[1], null, async (_, { endFlow }) => {
return endFlow()
})
.addAnswer(MOCK_VALUES[2])
.addAnswer(MOCK_VALUES[3], null, async (_, { flowDynamic }) => {
const data = await fakeHTTP(['1000', '2000', '3000'])
return flowDynamic(data)
})
createBot({
database,
provider,
flow: createFlow([flow]),
})
await provider.delaySendMessage(0, 'message', {
from: '000',
body: 'hola',
})
await delay(900)
const getHistory = database.listHistory.map((i) => i.answer)
assert.is(MOCK_VALUES[0], getHistory[0])
//FlowDynamic
assert.is('Ford', getHistory[1])
assert.is('GM', getHistory[2])
assert.is('BMW', getHistory[3])
assert.is(MOCK_VALUES[1], getHistory[4])
//FlowDynamic
assert.is(undefined, getHistory[5])
assert.is(undefined, getHistory[6])
})
suiteCase(`Detener el flujo flowDynamic`, async ({ database, provider }) => {
const flow = addKeyword(['hola'])
.addAnswer('Buenas!', null, async (_, { endFlow, flowDynamic }) => {
await flowDynamic('Continuamos...')
return endFlow()
})
.addAnswer('Como estas!')
createBot({
database,
provider,
flow: createFlow([flow]),
})
await provider.delaySendMessage(0, 'message', {
from: '000',
body: 'hola',
})
await delay(100)
const getHistory = database.listHistory.map((i) => i.answer)
assert.is('Buenas!', getHistory[0])
assert.is('Continuamos...', getHistory[1])
assert.is(undefined, getHistory[2])
})
suiteCase(`flowDynamic con capture`, async ({ database, provider }) => {
const MOCK_VALUES = ['¿CUal es tu email?', 'Continuamos....', '¿Cual es tu edad?']
const flow = addKeyword(['hola'])
.addAnswer(
MOCK_VALUES[0],
{
capture: true,
},
async (ctx, { flowDynamic, fallBack }) => {
const validation = ctx.body.includes('@')
if (validation) {
const getDataFromApi = await fakeHTTP(['Gracias por tu email se ha validado de manera correcta'])
return flowDynamic(getDataFromApi)
}
return fallBack()
}
)
.addAnswer(MOCK_VALUES[1])
.addAnswer(MOCK_VALUES[2], { capture: true }, async (ctx, { flowDynamic, fallBack }) => {
if (ctx.body !== '18') {
await delay(20)
return fallBack('Ups creo que no eres mayor de edad')
}
return flowDynamic('Bien tu edad es correcta!')
})
.addAnswer('Puedes pasar')
createBot({
database,
provider,
flow: createFlow([flow]),
})
await provider.delaySendMessage(0, 'message', {
from: '000',
body: 'hola',
})
await provider.delaySendMessage(10, 'message', {
from: '000',
body: 'this is not email value',
})
await provider.delaySendMessage(20, 'message', {
from: '000',
body: 'test@test.com',
})
await provider.delaySendMessage(90, 'message', {
from: '000',
body: '20',
})
await provider.delaySendMessage(200, 'message', {
from: '000',
body: '18',
})
await delay(900)
const getHistory = database.listHistory.map((i) => i.answer)
assert.is(MOCK_VALUES[0], getHistory[0])
assert.is('this is not email value', getHistory[1])
assert.is(MOCK_VALUES[0], getHistory[2])
assert.is('test@test.com', getHistory[3])
assert.is('Gracias por tu email se ha validado de manera correcta', getHistory[4])
assert.is(MOCK_VALUES[1], getHistory[5])
assert.is(MOCK_VALUES[2], getHistory[6])
assert.is('20', getHistory[7])
assert.is('Ups creo que no eres mayor de edad', getHistory[8])
assert.is('18', getHistory[9])
assert.is('Bien tu edad es correcta!', getHistory[10])
assert.is('Puedes pasar', getHistory[11])
})
suiteCase.run()

View File

@@ -1,97 +0,0 @@
const { suite } = require('uvu')
const assert = require('uvu/assert')
const { addKeyword, createBot, createFlow } = require('../packages/bot/index')
const { setup, clear, delay } = require('../__mocks__/env')
const suiteCase = suite('Flujo: manejo de estado')
suiteCase.before.each(setup)
suiteCase.after.each(clear)
suiteCase(`Debe retornar un mensaje resumen`, async ({ database, provider }) => {
let STATE_APP = {}
const MOCK_VALUES = ['¿Cual es tu nombre?', '¿Cual es tu edad?', 'Tu datos son:']
const flujoPrincipal = addKeyword(['hola'])
.addAnswer(
MOCK_VALUES[0],
{
capture: true,
},
async (ctx, { flowDynamic }) => {
STATE_APP[ctx.from] = { ...STATE_APP[ctx.from], name: ctx.body }
flowDynamic('Gracias por tu nombre!')
}
)
.addAnswer(
MOCK_VALUES[1],
{
capture: true,
},
async (ctx, { flowDynamic }) => {
STATE_APP[ctx.from] = { ...STATE_APP[ctx.from], age: ctx.body }
await flowDynamic(`Gracias por tu edad! ${STATE_APP[ctx.from].name}`)
}
)
.addAnswer(MOCK_VALUES[2], null, async (ctx, { flowDynamic }) => {
flowDynamic(`Nombre: ${STATE_APP[ctx.from].name} Edad: ${STATE_APP[ctx.from].age}`)
})
.addAnswer('🤖🤖 Gracias por tu participacion')
createBot({
database,
flow: createFlow([flujoPrincipal]),
provider,
})
await provider.delaySendMessage(0, 'message', {
from: '000',
body: 'hola',
})
await provider.delaySendMessage(5, 'message', {
from: '001',
body: 'hola',
})
await provider.delaySendMessage(10, 'message', {
from: '000',
body: 'Leifer',
})
await provider.delaySendMessage(15, 'message', {
from: '000',
body: '90',
})
await provider.delaySendMessage(20, 'message', {
from: '001',
body: 'Maria',
})
await provider.delaySendMessage(25, 'message', {
from: '001',
body: '100',
})
await delay(1000)
const getHistory = database.listHistory.map((i) => i.answer)
assert.is(MOCK_VALUES[0], getHistory[0])
assert.is('¿Cual es tu nombre?', getHistory[1])
assert.is('Leifer', getHistory[2])
assert.is('Gracias por tu nombre!', getHistory[3])
assert.is('¿Cual es tu edad?', getHistory[4])
assert.is('90', getHistory[5])
assert.is('Gracias por tu edad! Leifer', getHistory[6])
assert.is('Tu datos son:', getHistory[7])
assert.is('Nombre: Leifer Edad: 90', getHistory[8])
assert.is('🤖🤖 Gracias por tu participacion', getHistory[9])
assert.is('Maria', getHistory[10])
assert.is('Gracias por tu nombre!', getHistory[11])
assert.is('100', getHistory[12])
assert.is(undefined, getHistory[13])
})
suiteCase.run()

81
adapter/diaglogflow.js Normal file
View File

@@ -0,0 +1,81 @@
const dialogflow = require('@google-cloud/dialogflow');
const fs = require('fs')
const {struct} = require('pb-util');
/**
* Debes de tener tu archivo con el nombre "chatbot-account.json" en la raíz del proyecto
*/
const KEEP_DIALOG_FLOW = (process.env.KEEP_DIALOG_FLOW === 'true')
let PROJECID;
let CONFIGURATION;
let sessionClient;
const checkFileCredentials = () => {
if(!fs.existsSync(`${__dirname}/../chatbot-account.json`)){
return false
}
const parseCredentials = JSON.parse(fs.readFileSync(`${__dirname}/../chatbot-account.json`));
PROJECID = parseCredentials.project_id;
CONFIGURATION = {
credentials: {
private_key: parseCredentials['private_key'],
client_email: parseCredentials['client_email']
}
}
sessionClient = new dialogflow.SessionsClient(CONFIGURATION);
}
// Create a new session
// Detect intent method
const detectIntent = async (queryText, waPhoneNumber) => {
let media = null;
let actions = null;
const sessionId = KEEP_DIALOG_FLOW ? 1 : waPhoneNumber;
const sessionPath = sessionClient.projectAgentSessionPath(PROJECID, sessionId);
const languageCode = process.env.LANGUAGE
const request = {
session: sessionPath,
queryInput: {
text: {
text: queryText,
languageCode: languageCode,
},
},
};
const responses = await sessionClient.detectIntent(request);
const [singleResponse] = responses;
const { queryResult } = singleResponse
const { intent } = queryResult || { intent: {} }
const parseIntent = intent['displayName'] || null
const parsePayload = queryResult['fulfillmentMessages'].find((a) => a.message === 'payload');
// console.log(singleResponse)
if (parsePayload && parsePayload.payload) {
const { fields } = parsePayload.payload
actions = struct.decode(fields.actions.structValue) || null;
media = fields.media.stringValue || null
}
const customPayload = parsePayload ? parsePayload['payload'] : null
const parseData = {
replyMessage: queryResult.fulfillmentText,
media,
actions,
trigger: null
}
return parseData
}
const getDataIa = (message = '', sessionId = '', cb = () => { }) => {
detectIntent(message, sessionId).then((res) => {
cb(res)
})
}
checkFileCredentials();
module.exports = { getDataIa }

103
adapter/gdrive,.js Normal file
View File

@@ -0,0 +1,103 @@
require('dotenv').config({ path: `${__dirname}/../.env` });
const { google } = require('googleapis');
const path = require('path');
const fs = require('fs');
//const clientEmail = require(`${__dirname}/../chatbot-account.json`);
/**
* La funcion 'generatePublicUrl' genera un error muy menor al enviar el 'requestBody'
* siempre y cuando necesites que el acceso sea restringido y solo ciertos usuarios puedan acceder.
* Esto se logra con la combinacion requerida: 'reader', 'user' y 'emailAddress':
* requestBody: {
* role: 'reader',
* type: 'user',
* emailAddress: usuario@gmail.com,
* },
* Segun la documentacion https://developers.google.com/drive/api/v3/reference/permissions/create#request-body,
* los datos se envian correctamente, pero la respuesta del API regresa este error:
* Bad Request. User message: "You cannot share this item because it has been flagged as inappropriate."
* Al parecer, es un error conocido en stackoverflow.com entre varios usuarios del API.
*/
if (process.env.DATABASE === 'dialogflow') {
/**
* Debes de tener tu archivo con el nombre "chatbot-account.json" en la raíz del proyecto
*/
const KEYFILEPATH = path.join(`${__dirname}/../chatbot-account.json`);
const SCOPES = ['https://www.googleapis.com/auth/drive'];
const auth = new google.auth.GoogleAuth({
keyFile: KEYFILEPATH,
scopes: SCOPES,
});
const drive = google.drive({
version: 'v3',
auth,
});
const uploadSingleFile = async (fileName, filePath) => {
const folderId = process.env.GDRIVE_FOLDER_ID;
const { data: { id, name } = {} } = await drive.files.create({
resource: {
name: fileName,
parents: [folderId],
},
media: {
mimeType: 'image/jpg',
body: fs.createReadStream(filePath),
},
fields: 'id,name',
});
generatePublicUrl(id).then(() => {
console.log(`Se generó enlace https://drive.google.com/open?id=${id} para el archivo ${name}`);
});
return `https://drive.google.com/open?id=${id}`
};
const scanFolderForFiles = async (folderPath) => {
const folder = await fs.promises.opendir(folderPath);
for await (const dirent of folder) {
if (dirent.isFile() && dirent.name.endsWith('.jpeg')) {
await uploadSingleFile(dirent.name, path.join(folderPath, dirent.name));
await fs.promises.rm(filePath);
}
}
};
async function generatePublicUrl(id) {
try {
const fileId = id;
await drive.permissions.create({
fileId: fileId,
supportsAllDrives: true,
requestBody: {
role: 'reader',
type: 'domain', // 'anyone' da acceso al publico vía enlace https://drive.google.com...
domain: 'gserviceaccount.com', // Si tu cuenta esta bajo un dominio (usuario@empresa.com) y no bajo gmail.com
allowFileDiscovery: false,
},
});
/*
webViewLink: Ver el archivo en el navegador
webContentLink: Enlace de descarga directa
*/
const result = await drive.files.get({
fileId: fileId,
fields: 'webViewLink, webContentLink',
});
console.log(result.data);
} catch (error) {
//console.log(error.message); // Imprime 'Internal Error', pero aún así genera el enlace
console.error = () => { }; // No muestra el error anterior
}
}
module.exports = { uploadSingleFile, scanFolderForFiles }
} else {
console.log(`Actualmente, la base de datos es:\n\t'DATABASE=${process.env.DATABASE}'\nPara usar Google Drive, cambiar a:\n\t'DATABASE=dialogflow'`);
}

103
adapter/gdrive.js Normal file
View File

@@ -0,0 +1,103 @@
require('dotenv').config({ path: `${__dirname}/../.env` });
const { google } = require('googleapis');
const path = require('path');
const fs = require('fs');
//const clientEmail = require(`${__dirname}/../chatbot-account.json`);
/**
* La funcion 'generatePublicUrl' genera un error muy menor al enviar el 'requestBody'
* siempre y cuando necesites que el acceso sea restringido y solo ciertos usuarios puedan acceder.
* Esto se logra con la combinacion requerida: 'reader', 'user' y 'emailAddress':
* requestBody: {
* role: 'reader',
* type: 'user',
* emailAddress: usuario@gmail.com,
* },
* Segun la documentacion https://developers.google.com/drive/api/v3/reference/permissions/create#request-body,
* los datos se envian correctamente, pero la respuesta del API regresa este error:
* Bad Request. User message: "You cannot share this item because it has been flagged as inappropriate."
* Al parecer, es un error conocido en stackoverflow.com entre varios usuarios del API.
*/
if (process.env.DATABASE === 'dialogflow') {
/**
* Debes de tener tu archivo con el nombre "chatbot-account.json" en la raíz del proyecto
*/
const KEYFILEPATH = path.join(`${__dirname}/../chatbot-account.json`);
const SCOPES = ['https://www.googleapis.com/auth/drive'];
const auth = new google.auth.GoogleAuth({
keyFile: KEYFILEPATH,
scopes: SCOPES,
});
const drive = google.drive({
version: 'v3',
auth,
});
const uploadSingleFile = async (fileName, filePath) => {
const folderId = process.env.GDRIVE_FOLDER_ID;
const { data: { id, name } = {} } = await drive.files.create({
resource: {
name: fileName,
parents: [folderId],
},
media: {
mimeType: 'image/jpg',
body: fs.createReadStream(filePath),
},
fields: 'id,name',
});
generatePublicUrl(id).then(() => {
console.log(`Se generó enlace https://drive.google.com/open?id=${id} para el archivo ${name}`);
});
return `https://drive.google.com/open?id=${id}`
};
const scanFolderForFiles = async (folderPath) => {
const folder = await fs.promises.opendir(folderPath);
for await (const dirent of folder) {
if (dirent.isFile() && dirent.name.endsWith('.jpeg')) {
await uploadSingleFile(dirent.name, path.join(folderPath, dirent.name));
await fs.promises.rm(filePath);
}
}
};
async function generatePublicUrl(id) {
try {
const fileId = id;
await drive.permissions.create({
fileId: fileId,
supportsAllDrives: true,
requestBody: {
role: 'reader',
type: 'domain', // 'anyone' da acceso al publico vía enlace https://drive.google.com...
domain: 'gserviceaccount.com', // Si tu cuenta esta bajo un dominio (usuario@empresa.com) y no bajo gmail.com
allowFileDiscovery: false,
},
});
/*
webViewLink: Ver el archivo en el navegador
webContentLink: Enlace de descarga directa
*/
const result = await drive.files.get({
fileId: fileId,
fields: 'webViewLink, webContentLink',
});
console.log(result.data);
} catch (error) {
//console.log(error.message); // Imprime 'Internal Error', pero aún así genera el enlace
console.error = () => { }; // No muestra el error anterior
}
}
module.exports = { uploadSingleFile, scanFolderForFiles }
} else {
console.log(`Actualmente, la base de datos es:\n\t'DATABASE=${process.env.DATABASE}'\nPara usar Google Drive, cambiar a:\n\t'DATABASE=dialogflow'`);
}

346
adapter/index.js Normal file
View File

@@ -0,0 +1,346 @@
const { getData, getReply, saveMessageMysql } = require('./mysql')
const { saveMessageJson } = require('./jsonDb')
const { getDataIa } = require('./diaglogflow')
const stepsInitial = require('../flow/initial.json')
const stepsReponse = require('../flow/response.json')
const { isUndefined } = require('util');
var msjsRecibidos = [];
var ultimoStep; //MOD by CHV -
var pasoAnterior = []; //MOD by CHV - Para guardar el paso anterior de cada número.
var pasoRequerido; //MOD by CHV -
var vamosA = ""; //MOD by CHV -
var VA = ""; //MOD by CHV -
var elNum; //MOD by CHV -
var cumplePasoPrevio; //MOD by CHV -
const resps = require('../flow/response.json'); //MOD by CHV - Agregamos para traer las respuestas.
const { appendFile } = require('fs')
const get = (message, num) => new Promise((resolve, reject) => { //MOD by CHV - Agregamos parametro "num" para recibir el número de "app.js"
// console.log(num)
elNum = num //MOD by CHV -
if(siguientePaso.find(k => k.numero.includes(elNum))){
console.log("siguientePaso="+siguientePaso.find(k => k.numero.includes(elNum))["numero"], siguientePaso.find(k => k.numero.includes(elNum))["va"])
// ultimoStep = siguientePaso.find(k => k.numero.includes(elNum))["va"]
pasoAnterior[elNum] = siguientePaso.find(k => k.numero.includes(elNum))["va"] //Asignamos pasoAnterior al número.
siguientePaso.splice(siguientePaso.indexOf(elNum), 1)
console.log("******************** "+siguientePaso.find(k => k.numero.includes(elNum)))
}
if(siguientePaso.length>1){console.log(siguientePaso[1]["numero"], siguientePaso[1]["va"])}
/**
* Si no estas usando un gesto de base de datos
*/
if (process.env.DATABASE === 'none') {
var { key } = stepsInitial.find(k => k.keywords.includes(message)) || { key: null }
/* ############################################### * REGEXP * ####################################################
Si queremos usar RegExp, en los "keywords" de inital.json, en lugar de un arreglo usamos un string (quitamos los [])
y en él usamos "*" para significar cualquier texto y "|" para significar "OR", esto nos permite ser mas flexibles
con los "keywords", por ejemplo, si queremos que el mensaje pueda decir:
"Hola quiero info del paquete" o "Requiero mas informacion"
ponemos "*info*" y la regla se va a disparar porque los dos contienen "info", o si queremos que se dispare con:
"Quiero info del paquete numero 3" o "Me gusto el paquete de Angular"
ponemos "paquete*3|paquete*angular" y la regla se dispara porque contiene "paquete" Y "3" -O- "paquete" Y "angular".
#####################################################################################################################
*/
var {keywords} = stepsInitial.find(k => k.key.includes(key)) || { keywords: null }
if(!Array.isArray(keywords)){key=null;}//Si "keywords" no es arreglo entonces ponemos "key" en null y usamos REGEXP para buscar reglas.
if(key == null && message.length > 0){
console.log("======= KEY ES NULO USAMOS REGEXP =======");
for (i=0; i<stepsInitial.length;i++){
// console.log(i, stepsInitial[i].keywords, message.match(stepsInitial[i].keywords.toString().replaceAll("*",".*")));
if(!Array.isArray(stepsInitial[i].keywords)){// Si "Keywords" NO es arreglo entonces ...
x = null;
console.log("KEY=|" + stepsInitial[i].key.toString() + "|" )
// if(resps[stepsInitial[i].key.toString()].pasoRequerido != undefined){pr = resps[stepsInitial[i].key].pasoRequerido};
// console.log(resps[stepsInitial[i].key.toString()].pasoRequerido== ultimoStep)
console.log("Esta Key=" + stepsInitial[i].key.toString() + " - pasoReq=" + resps[stepsInitial[i].key.toString()].pasoRequerido + " - PasoAnt=" + ultimoStep+"|"+pasoAnterior[elNum])
if(resps[stepsInitial[i].key.toString()].pasoRequerido == undefined || resps[stepsInitial[i].key.toString()].pasoRequerido == pasoAnterior[elNum]){
var tempKeyword = "";
if (stepsInitial[i].keywords == "%solo_correos%"){
console.log("solo_correos")
tempKeyword = "[a-zA-Z0-9]+[_a-zA-Z0-9\.-]*[a-zA-Z0-9]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+[\.][a-zA-Z]{2,12})"}
else{tempKeyword = stepsInitial[i].keywords.toString().replaceAll("*",".*")}
x = message.match(tempKeyword);
// console.log("Keywords="+stepsInitial[i].keywords + " - key=" + stepsInitial[i].key + " - pasoReq=" + resps[stepsInitial[i].key].pasoRequerido + " - PasoAnt=" + ultimoStep)
// console.log("x:"+x+" - ultimoStep="+ultimoStep+" - pasoReq="+resps[stepsInitial[i].key].pasoRequerido);
// console.log(resps[stepsInitial[i].key].replyMessage.toString())
if (x != null){
key = stepsInitial[i].key;
if(resps[stepsInitial[i].key].pasoRequerido != null && resps[stepsInitial[i].key].pasoRequerido != pasoAnterior[elNum]){key=null;}
// console.log("KEY="+key+" - X="+x);
if(resps[stepsInitial[i].key].replyMessage.toString().search("/URL") > -1){
console.log("**************** HAY URL ****************")
}
break;
}
else{x = null;}
} else
{ console.log("NO CUMPLE PASO REQ");
// console.log("pasoReq=" + resps[stepsInitial[i].key.toString()].pasoRequerido + " - PasoAnt=" + ultimoStep)
}
}
}
// console.log("<<<<<<<<< "+key);
// cumplePasoRequerido(key)
// ultimoPaso = pasoRequerido;
// ultimoStep = key;
}
const response = key || null
// if(key != null){remplazos(resps[key].replyMessage.join(''));}
if(resps[key]!=undefined){VA = resps[key].goto}else{VA=null}
cumplePasoRequerido(key);
vamosA = VA;
// console.log(elNum)
if(vamosA != "" && vamosA != undefined && cumplePasoPrevio == true){
console.log("ASIGNAMOS VAMOSA = " + vamosA);
pasoAnterior[elNum] = vamosA;
}
// console.log("ULTIMOSTEP="+ultimoStep)
vamosA = "";
// console.log("MESSAGE: "+message);
// console.log("KEY: "+key);
// console.log("RESPONSE: "+response);
if(cumplePasoPrevio) {resolve(response);}
}
/**
* Si usas MYSQL
*/
if (process.env.DATABASE === 'mysql') {
getData(message, (dt) => {
resolve(dt)
});
}
})
const reply = (step) => new Promise((resolve, reject) => {
/**
* Si no estas usando un gesto de base de datos
*/
if (process.env.DATABASE === 'none') {
let resData = { replyMessage: '', media: null, trigger: null }
const responseFind = stepsReponse[step] || {};
resData = {
...resData,
...responseFind,
replyMessage:responseFind.replyMessage.join('')}
resolve(resData);
return
}
/**
* Si usas MYSQL
*/
if (process.env.DATABASE === 'mysql') {
let resData = { replyMessage: '', media: null, trigger: null }
getReply(step, (dt) => {
resData = { ...resData, ...dt }
resolve(resData)
});
}
})
const getIA = (message) => new Promise((resolve, reject) => {
/**
* Si usas dialogflow
*/
if (process.env.DATABASE === 'dialogflow') {
let resData = { replyMessage: '', media: null, trigger: null }
getDataIa(message,(dt) => {
resData = { ...resData, ...dt }
resolve(resData)
})
}
})
/**
*
* @param {*} message
* @param {*} date
* @param {*} trigger
* @param {*} number
* @returns
*/
const saveMessage = ( message, trigger, number, regla ) => new Promise( async (resolve, reject) => { //MOD by CHV - Agregamos el partametro "regla" para poder guardarlo en "chats/numero.json"
switch ( process.env.DATABASE ) {
case 'mysql':
resolve( await saveMessageMysql( message, trigger, number ) )
break;
case 'none':
resolve( await saveMessageJson( message, trigger, number, regla) ) //MOD by CHV - Agregamos el paranetro "regla"
// console.log("REGLA DESDE APP.JS="+regla)
break;
default:
resolve(true)
break;
}
})
module.exports = { get, reply, getIA, saveMessage, remplazos, stepsInitial } //MOD by CHV - Agregamos "remplazos" y "stepsInitial" para usarlos en "apps.js"
/**
* Reemplaza texto en la respuesta con variables predefinidas.
*/
function remplazos(elTexto, extraInfo){
if(elTexto == null){elTexto = '';}
laLista = elTexto.toString().split(' ');
// console.log(laLista);
// console.log('============= remplazos ============');
for (var i = 0; i < laLista.length; i++) {
// console.log('Revisamos: '+laLista[i]);
if (laLista[i].search('%dia_semana%')>-1){//Remplaza con el dia de hoy.
var dia = new Date().getDay();
if(dia==0){diaSemana='domingo';}
else if(dia==1){diaSemana='lunes';}
else if(dia==2){diaSemana='martes';}
else if(dia==3){diaSemana='miercoles';}
else if(dia==4){diaSemana='jueves';}
else if(dia==5){diaSemana='viernes';}
else {diaSemana='sábado';}
elTexto = elTexto.replace('%dia_semana%', diaSemana);
}
if (laLista[i].search('%saludo%')>-1){//Remplaza con "Buenos dias, tardes o noches" dependiendo de la hora.
var hora = new Date().getHours()
if(hora>0 && hora < 12){saludo='Buenos días';}
else if(hora>11 && hora < 19){saludo='Buenas tardes';}
else {saludo='Buenas noches';}
elTexto = elTexto.toString().replace('%saludo%', saludo);
}
if (laLista[i].search('%hora24%')>-1){//Remplaza con la hora a 24 hrs.
var hora = new Date().getHours();
if (hora.toString().length < 2){hora = "0" + hora;}
elTexto = elTexto.toString().replace('%hora24%', hora);
}
if (laLista[i].search('%hora12%')>-1){//Remplaza con la hora a 12 hrs.
var hora = new Date().getHours();
var ampm = hora >= 12 ? 'pm' : 'am';
hora = hora % 12;
hora = hora ? hora : 12; // the hour '0' should be '12'
if (hora.toString().length < 2){hora = "0" + hora;}
elTexto = elTexto.toString().replace('%hora12%', hora);
}
if (laLista[i].search('%minutos%')>-1){//Remplaza con los minutos de la hora actual.
var mins = new Date().getMinutes();
if (mins.toString().length < 2){mins = "0" + mins;}
elTexto = elTexto.toString().replace('%minutos%', mins);
}
if (laLista[i].search('%ampm%')>-1){//Remplaza con am o pm.
var hours = new Date().getHours();
var ampm = hours >= 12 ? 'pm' : 'am';
elTexto = elTexto.toString().replace('%ampm%', ampm);
}
if (laLista[i].search('%rnd_')>-1){//Remplaza con opción al azar dentro de las especificadas.
var inicio = laLista[i].search('%rnd_');
var final = laLista[i].indexOf("%", inicio+1);
// console.log(inicio, final);
var subStr = laLista[i].substring(inicio, final+1);
// console.log("El substring="+subStr);
var partes = subStr.toString().split('_');
if(partes.length > 1){
var opciones = partes[1].toString().substring(0,partes[1].toString().length-1).split(",");
var elRand = Math.floor(Math.random() * (opciones.length));
if(elRand == opciones.length){elRand = elRand - 1;}
// console.log(opciones.length, elRand, opciones[elRand]);
elTexto = elTexto.toString().replace(subStr, opciones[elRand]);
}
else{
elTexto = elTexto.toString().replace(subStr, "");
}
}
if(laLista[i].search('%msjant_')>-1){//Remplaza con el mensaje anterior especificado.
var histlMsjs = {};
console.log("entramos a msjant")
// var hayHistorial = (chkFile(`${__dirname}/chats/`+from+".json"));
if(chkFile(`${__dirname}/../chats/`+elNum+".json")){
let rawdata = fs.readFileSync(`./chats/${elNum}.json`);
let elHistorial0 = JSON.parse(rawdata);
elHistorial = elHistorial0["messages"];
var inicio = laLista[i].search('%msjant_');
var final = laLista[i].indexOf("%", inicio+1);
var subStr = laLista[i].substring(inicio, final+1);
console.log("Substr = |" + subStr + "|");
var partes = subStr.toString().split('_');
if(partes.length > 1){
console.log("Partes[1] = |" + partes[1] + "|");
let posicion0 = partes[1].substring(0, partes[1].length-1)
console.log("Posicion0 = |" + posicion0 + "|");
posicion = ((posicion0*1) + 1);
console.log("Posicion = " + posicion);
console.log( elHistorial.length );
console.log((elHistorial.length*1)-posicion);
console.log("Mensaje="+elHistorial[elHistorial.length - posicion]["message"])
elTexto = elTexto.toString().replace(subStr, elHistorial[elHistorial.length - posicion]["message"]);
}
// histlMsjs = elHistorial["messages"];
// totalMsjs = histlMsjs.length-1;
// ultimoMensaje = histlMsjs[histlMsjs.length-1];
// let mensajeAnterior = elHistorial["messages"][totalMsjs-1];
// console.log("Mensajes:"+totalMsjs+", Ultimo:"+JSON.stringify(ultimoMensaje));
// console.log("Anterior:"+JSON.stringify(mensajeAnterior));
}
// return histlMsjs;
}
if (laLista[i].search('%nombre%')>-1){//Remplaza con el nombre del remitente.
if(typeof extraInfo !== undefined){
const {theMsg} = extraInfo;
if(theMsg['_data']['notifyName'] !== undefined){
elTexto = elTexto.toString().replace('%nombre%', theMsg['_data']['notifyName']);
}
}
}
if (laLista[i].search('%primer_nombre%')>-1){//Remplaza con el nombre del remitente.
if(typeof extraInfo !== undefined){
const {theMsg} = extraInfo;
if(theMsg['_data']['notifyName'] !== undefined){
elTexto = elTexto.toString().replace('%primer_nombre%', theMsg['_data']['notifyName'].split(' ')[0]);
}
}
}
}
// console.log("EL TEXTO="+elTexto);
return elTexto
}
/**
* Revisa si la regla especificada depende (es submenu) de otra regla, y cambia la variable "cumplePasoPrevio" a verdadero o falso.
*/
function cumplePasoRequerido(step){
//Traemos las respuestas para obtener el "pasoRequerido".
if(resps[step]!=undefined){pasoRequerido=resps[step].pasoRequerido}else{pasoRequerido=null}
if((pasoRequerido != null && pasoRequerido == ultimoStep)){
// console.log("REQUIERE PASO PREVIO Y CUMPLE");
cumplePasoPrevio = true;
}
else if((pasoRequerido != null && pasoRequerido != pasoAnterior[elNum])){
// console.log("REQUIERE PASO PREVIO Y NO LO CUMPLE");
cumplePasoPrevio = false;
}
else{
// console.log("NO REQUIERE PASO PREVIO")
cumplePasoPrevio = true;
}
pasoAnterior[elNum] = step
ultimoPaso = pasoRequerido;
}
const fs = require('fs');
function chkFile(theFile){ //MOD by CHV - Agregamos para revisar que exista el archivo "chats/numero.json"
if (fs.existsSync(theFile)) {
// console.log("Si existe el archivo "+ theFile);
var h = true;
}
else{
// console.log("No existe el archivo "+ theFile);
var h = false;
}
return h;
}

20
adapter/jsonDb.js Normal file
View File

@@ -0,0 +1,20 @@
const Path = require('path')
const StormDB = require("stormdb");
const date = new Date().toISOString();
const saveMessageJson = (message, trigger, number, regla) => new Promise( async(resolve,reject) =>{
try {
const engine = new StormDB.localFileEngine( Path.join(__dirname, `/../chats/${number}.json`) );
const db = new StormDB(engine);
// set default db value if db is empty
db.default({ messages: [] });
// add new users entry
db.get("messages").push({ message, date, trigger, regla});
db.save();
resolve('Saved')
} catch (error) {
console.log(error)
reject(error)
}
})
module.exports = { saveMessageJson }

74
adapter/mysql.js Normal file
View File

@@ -0,0 +1,74 @@
const {connection} = require('../config/mysql')
const DATABASE_NAME = process.env.SQL_DATABASE || 'db_test'
getData = (message = '', callback) => connection.query(
`SELECT * FROM ${DATABASE_NAME}.initial WHERE keywords LIKE '%${message}%' LIMIT 1`,
(error, results
) => {
const [response] = results
const key = response?.option_key || null
callback(key)
});
getReply = (option_key = '', callback) => connection.query(
`SELECT * FROM ${DATABASE_NAME}.response WHERE option_key = '${option_key}' LIMIT 1`,
(error, results
) => {
const [response] = results;
console.log(response)
const value = {
replyMessage:response?.replyMessage || '',
trigger:response?.trigger || '',
media:response?.media || ''
}
callback(value)
});
getMessages = ( number ) => new Promise((resolve,reejct) => {
try {
connection.query(
`SELECT * FROM ${DATABASE_NAME}.response WHERE number = '${number}'`, (error, results) => {
if(error) {
console.log(error)
}
const [response] = results;
console.log(response)
const value = {
replyMessage:response?.replyMessage || '',
trigger:response?.trigger || '',
media:response?.media || ''
}
resolve(value)
})
} catch (error) {
}
})
saveMessageMysql = ( message, date, trigger, number ) => new Promise((resolve,reejct) => {
try {
connection.query(
`INSERT INTO ${DATABASE_NAME}.messages `+"( `message`, `date`, `trigger`, `number`)"+` VALUES ('${message}','${date}','${trigger}', '${number}')` , (error, results) => {
if(error) {
//TODO esta parte es mejor incluirla directamente en el archivo .sql template
console.log('DEBES DE CREAR LA TABLA DE MESSAGE')
// if( error.code === 'ER_NO_SUCH_TABLE' ){
// connection.query( `CREATE TABLE ${DATABASE_NAME}.messages `+"( `date` DATE NOT NULL , `message` VARCHAR(450) NOT NULL , `trigger` VARCHAR(450) NOT NULL , `number` VARCHAR(50) NOT NULL ) ENGINE = InnoDB", async (error, results) => {
// setTimeout( async () => {
// return resolve( await this.saveMessageMysql( message, date, trigger, number ) )
// }, 150)
// })
// }
}
console.log('Saved')
console.log( results )
resolve(results)
})
} catch (error) {
}
})
module.exports = {getData, getReply, saveMessageMysql}

510
app.js Normal file
View File

@@ -0,0 +1,510 @@
/**
* ⚡⚡⚡ DECLARAMOS LAS LIBRERIAS y CONSTANTES A USAR! ⚡⚡⚡
*/
require('dotenv').config()
const fs = require('fs');
const express = require('express');
global.siguientePaso = [{"numero":"1", "va":"XXX"}]; //MOD by CHV - Agregamos para pasar el VAMOSA a "index.js"
const cors = require('cors')
const axios = require('axios').default;//MOD by CHV - Agregamos para el get del "/URL"
const qrcode = require('qrcode-terminal');
const { Client, LocalAuth, Buttons, List } = require('whatsapp-web.js');
const mysqlConnection = require('./config/mysql')
const { middlewareClient } = require('./middleware/client')
const { generateImage, cleanNumber, checkEnvFile, createClient, isValidNumber } = require('./controllers/handle')
const { connectionReady, connectionLost } = require('./controllers/connection')
const { saveMedia, saveMediaToGoogleDrive } = require('./controllers/save')
const { getMessages, responseMessages, bothResponse, waitFor } = require('./controllers/flows')
const { sendMedia, sendMessage, lastTrigger, sendMessageButton, sendMessageList, readChat } = require('./controllers/send');
const { remplazos, stepsInitial} = require('./adapter/index');//MOD by CHV - Agregamos para utilizar remplazos y stepsInitial
const { isUndefined } = require('util');
const { isSet } = require('util/types');
const { Console } = require('console');
const { ClientRequest } = require('http');
const app = express();
app.use(cors())
app.use(express.json())
const MULTI_DEVICE = process.env.MULTI_DEVICE || 'true';
const server = require('http').Server(app)
const port = process.env.PORT || 3000
var client;
var dialogflowFilter = false;
var totalMsjs; //MOD by CHV -
var vamosA = ""; //MOD by CHV -
var newBody; //MOD by CHV -
var nuevaRespuesta; //MOD by CHV - Se agrego para los remplazos
app.use('/', require('./routes/web'))
/**
* Escuchamos cuando entre un mensaje
*/
const listenMessage = () => client.on('message', async msg => {
const { from, body, hasMedia } = msg;
// console.log("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
console.log("+++++++++++++++++++++++++++++++++++++ INICIO +++++++++++++++++++++++++++++++++++++++");
// console.log("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
client.theMsg = msg;
console.log("HORA:"+new Date().toLocaleTimeString()+" FROM:"+from+", BODY:"+body+", HASMEDIA:"+hasMedia);
newBody = removeDiacritics(body) //MOD by CHV - Agregamos para quitar acentos
// newBody = remplazos(newBody);
vamosA = "";
if(!isValidNumber(from)){
return
}
// Este bug lo reporto Lucas Aldeco Brescia para evitar que se publiquen estados
if (from === 'status@broadcast') {
return
}
message = newBody.toLowerCase();
const number = cleanNumber(from)
var { key } = stepsInitial.find(k => k.keywords.includes(message)) || { key: null }//MOD by CHV - Se agrega para obtener KEY
await readChat(number, message, null , key) //MOD by CHV - Agregamos key/regla para guardarla en "chats/numero.json"
/**
* Guardamos el archivo multimedia que envia
*/
if (process.env.SAVE_MEDIA === 'true' && hasMedia) {
const media = await msg.downloadMedia();
saveMedia(media);
}
/**
* Si estas usando dialogflow solo manejamos una funcion todo es IA
*/
if (process.env.DATABASE === 'dialogflow') {
if (process.env.DIALOGFLOW_MEDIA_FOR_SLOT_FILLING === 'true' && dialogflowFilter) {
waitFor(_ => hasMedia, 30000)
.then(async _ => {
if (hasMedia) {
const media = await msg.downloadMedia();
message = await saveMediaToGoogleDrive(media);
const response = await bothResponse(message.substring(256, -1), number);
await sendMessage(client, from, response.replyMessage);
}
return
});
dialogflowFilter = false;
}
if (!message.length) return;
const response = await bothResponse(message.substring(256, -1), number);
await sendMessage(client, from, response.replyMessage);
if (response.actions) {
await sendMessageButton(client, from, null, response.actions);
return
}
if (response.media) {
sendMedia(client, from, response.media);
}
return
}
if(body=='/listas'){
const productList = new List(
"Here's our list of products at 50% off",
"View all products",
[
{
title: "Products list",
rows: [
{ id: "apple", title: "Apple" },
{ id: "mango", title: "Mango" },
{ id: "banana", title: "Banana" },
],
},
],
"Please select a product"
);
console.log('##################################################################################################')
// console.log(from, lista)
// let sections = [{title:'sectionTitle',rows:[{id:'ListItem1', title: 'title1'},{id:'ListItem2', title:'title2'}]}];
// let lista = new List('List body','btnText',sections,'Title','footer');
console.log("****************** productList ******************")
console.log(productList)
client.sendMessage(from, productList); //cliente.sendMessage recibe el arreglo SIN nombres (solo las secciones los necesitan)
// client.sendMessage('5215527049036@c.us', productList);
// client.sendMessage('5215554192439@c.us', productList);
// await sendMessageList(client, '5215545815654@c.us', null, lista); //sendMessageList recibe el arreglo CON nombres, como viene del response.json
// await sendMessageList(client, '5215527049036@c.us', null, lista);
// await sendMessageList(client, '5215554192439@c.us', null, lista);
// client.sendMessage(from, lista);
}
/**
* PRUEBA BOTONES NUEVOS
*/
// if(body=="579"){
// const buttons_reply = new Buttons("Por favor vuelve a intentar, mandando *SOLO* la palabra *gallina* con una diagonal al principio 👇🏽 \n\n */gallina*\n ", [{body: "/gallina", id: 'errorGallina'}], 'Error', 'O haz clic en el siguiente botón') // Reply button
// for (const component of [buttons_reply]) await client.sendMessage(from, component);
// }
/**
* Ver si viene de un paso anterior
* Aqui podemos ir agregando más pasos
* a tu gusto!
*/
const lastStep = await lastTrigger(from) || null;
// console.log("LAST STEP="+lastStep+", FROM:"+from);
if (lastStep) {
const response = await responseMessages(lastStep)
console.log("CLIENT="+client+", FROM:"+from+", REPLYMESSAGE:"+response.replyMessage);
await sendMessage(client, from, response.replyMessage, lastStep);
}
/**
* Respondemos al primero paso si encuentra palabras clave
*/
// const step = await getMessages(message, );
// console.log("STEP - "+step+"|"+message);
// console.log("****** STEP="+step);
// console.log("****** MESSAGE:"+message);
const step = await getMessages(message, from);
if (step) {
const response = await responseMessages(step);
// console.log("URL:"+nuevaRespuesta);
// console.log("HAY URL?? : "+nuevaRespuesta.search("/URL"));
var resps = require('./flow/response.json');
nuevaRespuesta = remplazos(resps[step].replyMessage.join(''), client);
var pasoRequerido = resps[step].pasoRequerido;
// var hayRequest = false;
// if(hayRequest==false && nuevaRespuesta.search("/URL")>-1){console.log("Paramos flujo para que no mande el mensaje '/URL'."); return;}//Si el trigger es desbloqueo ya no hace nada mas.
/**
* Si quieres enviar botones
*/
if (!response.delay && response.media) {
// console.log("++++++++++++++++++++++++++++ SEND MEDIA NO DELAY +++++++++++++++++++++++++++++++++++");
sendMedia(client, from, response.media, response.trigger);
}
if (response.delay && response.media) {
setTimeout(() => {
// console.log("++++++++++++++++++++++++++++ SEND MEDIA AND DELAY +++++++++++++++++++++++++++++++++++");
sendMedia(client, from, response.media, response.trigger);
}, response.delay)
}
if (response.delay){
// console.log("+++++++++++++++++++ SENDING MSG WITH DELAY ("+response.delay+") +++++++++++++++++");
setTimeout(() => {
sendMessage(client, from, nuevaRespuesta, response.trigger, step);
// console.log(" ************* Msg with delay SENT ****************")
}, response.delay)
}
else{
await sendMessage(client, from, nuevaRespuesta, response.trigger, step);
}
if(response.hasOwnProperty('actions')){
const { actions } = response;
// console.log("++++++++++++++++++++++++++++ SEND MESG BUTTON/LIST +++++++++++++++++++++++++++++++++++");
if(actions['sections'] === undefined){ //Botones
console.log("Botones")
await sendMessageButton(client, from, null, actions);
}
else{ //Listas
console.log("Listas")
// console.log(actions)
await sendMessageList(client, from, null, actions);
}
}
return
}
/**
* Regresa el mensaje enviado, con los remplazos procesados.
*/
if(message.search('/rpt') > -1){
newBody = remplazos(newBody, client);
newBody = newBody.replace("/rpt ", "");
client.sendMessage(from, newBody);
return
}
/*
============================================================================
========================== ENVIO MASIVO TEST ===========================
============================================================================
*/
if(message=='/spam'){
const masivo = require('./spam.json')
var saludo;
var caritas;
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function retardo() {
for (i=0;i<masivo.length;i++) {
console.log(masivo[i].numero+"@c.us");
var rnd = getRandomInt(1,7); // Random entre 1 y 6 segundos.
if(rnd==1||rnd==4){saludo = "Hola ";}
else if(rnd==2||rnd==5){saludo = "Saludos ";}
else {saludo = "%saludo% ";}
if(rnd==1){caritas = "👨🏻‍🦰👩🏻‍🦰";}
else if(rnd==2){caritas = "👩🏻‍🦰👨🏻‍🦰";}
else if(rnd==3){caritas = "🧔🏽👧🏽";}
else if(rnd==4){caritas = "👧🏽🧔🏽";}
else if(rnd==5){caritas = "👩🏻‍🦰🧔🏽";}
else if(rnd==6){caritas = "🧔🏽👩🏻‍🦰";}
if(i % 15 === 0){console.log("******** VAN 15, HACEMOS PAUSA DE 10 SEGUNDOS ********"); await sleep(10000);} //
console.log(`============= Mandamos el mensaje ${i} ==============`);
var elTextoDelMensaje = caritas + " *" + saludo + "amigo tendero* ❗❗👋🏻\n🕊 *GUNA* trae para ti dinámicas digitales, con las que podrás participar para ganar increíbles premios. 🏆💸💰\nSigue los siguientes pasos: 😃\n*1.* 📲Sigue la página de Yo Soy Guna en Facebook en la siguiente liga ➡️ https://www.facebook.com/yosoyguna\n*2.* 👉🏻Es importante des click en el botón Me Gusta 👍\n*3.* 🧐Sigue la dinámica que publicaremos , subiendo tu foto 📸 con los siguientes #yosoyguna #gunatenderos #gunachampions\n*4.* 🥳🎉En esta misma página , podrás ver publicados los ganadores🏅 y el tiempo en que serán elegidos. 💲 Además de tener acceso a increíbles promociones 🤑";
sendMedia(client, masivo[i].numero+"@c.us", "envioMasivoGuna.jpg");
await sleep(500);
client.sendMessage(masivo[i].numero+"@c.us", remplazos(elTextoDelMensaje, client));
// client.sendMessage(masivo[i].numero+"@c.us", "Este es un mensaje de prueba para *"+masivo[i].numero+"*, HORA:*"+new Date().toLocaleTimeString()+"*");
console.log(`Esperamos ${rnd} segundos...`);
await sleep(rnd*1000);
}
console.log('Done');
}
retardo();
}
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min); // The maximum is exclusive and the minimum is inclusive
}
//Si quieres tener un mensaje por defecto
if (process.env.DEFAULT_MESSAGE === 'true') {
const response = await responseMessages('DEFAULT')
await sendMessage(client, from, response.replyMessage, response.trigger);
/**
* Si quieres enviar botones
*/
if(response.hasOwnProperty('actions')){
const { actions } = response;
if(actions['sections'] === undefined){ //Botones
console.log("Botones")
await sendMessageButton(client, from, null, actions);
}
else{ //Listas
console.log("Listas")
await sendMessageList(client, from, null, actions);
}
}
return
}
});
/**
* Este evento es necesario para el filtro de Dialogflow
*/
const listenMessageFromBot = () => client.on('message_create', async botMsg => {
const { body } = botMsg;
const dialogflowFilterConfig = fs.readFileSync('./flow/dialogflow.json', 'utf8');
const keywords = JSON.parse(dialogflowFilterConfig);
for (i = 0; i < keywords.length; i++) {
key = keywords[i];
for (var j = 0; j < key.phrases.length; j++) {
let filters = key.phrases[j];
if (body.includes(filters)) {
dialogflowFilter = true;
//console.log(`El filtro de Dialogflow coincidió con el mensaje: ${filters}`);
}
}
}
});
client = new Client({
authStrategy: new LocalAuth(),
puppeteer: { headless: true, args: ['--no-sandbox','--disable-setuid-sandbox'] }
});
client.on('qr', qr => generateImage(qr, () => {
qrcode.generate(qr, { small: true });
console.log(`Ver QR http://localhost:${port}/qr`)
socketEvents.sendQR(qr)
}))
client.on('ready', (a) => {
connectionReady()
listenMessage()
listenMessageFromBot()
// socketEvents.sendStatus(client)
});
client.on('auth_failure', (e) => {
// console.log(e)
// connectionLost()
});
client.on('authenticated', () => {
console.log('AUTHENTICATED');
});
client.initialize();
/**
* Verificamos si tienes un gesto de db
*/
if (process.env.DATABASE === 'mysql') {
mysqlConnection.connect()
}
server.listen(port, () => {
console.log(`El server esta listo en el puerto ${port}`);
})
checkEnvFile();
function chkFile(theFile){ //MOD by CHV - Agregamos para revisar que exista el archivo "chats/numero.json"
if (fs.existsSync(theFile)) {
// console.log("Si existe el archivo "+ theFile);
var h = true;
}
else{
// console.log("No existe el archivo "+ theFile);
var h = false;
}
return h;
}
/**
* Regresa el historial de mensajes del número especificado del directorio "chats".
*/
function traeMensajes(from){ //MOD by CHV - Agregamos para traer el historial de mensajes
var histlMsjs = {};
var hayHistorial = (chkFile(`${__dirname}/chats/`+from+".json"));
if(hayHistorial){
let rawdata = fs.readFileSync(`./chats/${from}.json`);
let elHistorial = JSON.parse(rawdata);
histlMsjs = elHistorial["messages"];
// totalMsjs = histlMsjs.length-1;
ultimoMensaje = histlMsjs[histlMsjs.length-1];
// let mensajeAnterior = elHistorial["messages"][totalMsjs-1];
// console.log("Mensajes:"+totalMsjs+", Ultimo:"+JSON.stringify(ultimoMensaje));
// console.log("Anterior:"+JSON.stringify(mensajeAnterior));
}
return histlMsjs;
}
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var defaultDiacriticsRemovalMap = [ //MOD by CHV - Agregamos para eliminar acentos
{'base':'A', 'letters':'\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F'},
{'base':'AA','letters':'\uA732'},
{'base':'AE','letters':'\u00C6\u01FC\u01E2'},
{'base':'AO','letters':'\uA734'},
{'base':'AU','letters':'\uA736'},
{'base':'AV','letters':'\uA738\uA73A'},
{'base':'AY','letters':'\uA73C'},
{'base':'B', 'letters':'\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181'},
{'base':'C', 'letters':'\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E'},
{'base':'D', 'letters':'\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0'},
{'base':'DZ','letters':'\u01F1\u01C4'},
{'base':'Dz','letters':'\u01F2\u01C5'},
{'base':'E', 'letters':'\u0045\u24BA\uFF25\u00C8\u00C9\u00CA\u1EC0\u1EBE\u1EC4\u1EC2\u1EBC\u0112\u1E14\u1E16\u0114\u0116\u00CB\u1EBA\u011A\u0204\u0206\u1EB8\u1EC6\u0228\u1E1C\u0118\u1E18\u1E1A\u0190\u018E'},
{'base':'F', 'letters':'\u0046\u24BB\uFF26\u1E1E\u0191\uA77B'},
{'base':'G', 'letters':'\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E'},
{'base':'H', 'letters':'\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D'},
{'base':'I', 'letters':'\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197'},
{'base':'J', 'letters':'\u004A\u24BF\uFF2A\u0134\u0248'},
{'base':'K', 'letters':'\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2'},
{'base':'L', 'letters':'\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780'},
{'base':'LJ','letters':'\u01C7'},
{'base':'Lj','letters':'\u01C8'},
{'base':'M', 'letters':'\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C'},
{'base':'N', 'letters':'\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4'},
{'base':'NJ','letters':'\u01CA'},
{'base':'Nj','letters':'\u01CB'},
{'base':'O', 'letters':'\u004F\u24C4\uFF2F\u00D2\u00D3\u00D4\u1ED2\u1ED0\u1ED6\u1ED4\u00D5\u1E4C\u022C\u1E4E\u014C\u1E50\u1E52\u014E\u022E\u0230\u00D6\u022A\u1ECE\u0150\u01D1\u020C\u020E\u01A0\u1EDC\u1EDA\u1EE0\u1EDE\u1EE2\u1ECC\u1ED8\u01EA\u01EC\u00D8\u01FE\u0186\u019F\uA74A\uA74C'},
{'base':'OI','letters':'\u01A2'},
{'base':'OO','letters':'\uA74E'},
{'base':'OU','letters':'\u0222'},
{'base':'OE','letters':'\u008C\u0152'},
{'base':'oe','letters':'\u009C\u0153'},
{'base':'P', 'letters':'\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754'},
{'base':'Q', 'letters':'\u0051\u24C6\uFF31\uA756\uA758\u024A'},
{'base':'R', 'letters':'\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782'},
{'base':'S', 'letters':'\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784'},
{'base':'T', 'letters':'\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786'},
{'base':'TZ','letters':'\uA728'},
{'base':'U', 'letters':'\u0055\u24CA\uFF35\u00D9\u00DA\u00DB\u0168\u1E78\u016A\u1E7A\u016C\u00DC\u01DB\u01D7\u01D5\u01D9\u1EE6\u016E\u0170\u01D3\u0214\u0216\u01AF\u1EEA\u1EE8\u1EEE\u1EEC\u1EF0\u1EE4\u1E72\u0172\u1E76\u1E74\u0244'},
{'base':'V', 'letters':'\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245'},
{'base':'VY','letters':'\uA760'},
{'base':'W', 'letters':'\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72'},
{'base':'X', 'letters':'\u0058\u24CD\uFF38\u1E8A\u1E8C'},
{'base':'Y', 'letters':'\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE'},
{'base':'Z', 'letters':'\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762'},
{'base':'a', 'letters':'\u0061\u24D0\uFF41\u1E9A\u00E0\u00E1\u00E2\u1EA7\u1EA5\u1EAB\u1EA9\u00E3\u0101\u0103\u1EB1\u1EAF\u1EB5\u1EB3\u0227\u01E1\u00E4\u01DF\u1EA3\u00E5\u01FB\u01CE\u0201\u0203\u1EA1\u1EAD\u1EB7\u1E01\u0105\u2C65\u0250'},
{'base':'aa','letters':'\uA733'},
{'base':'ae','letters':'\u00E6\u01FD\u01E3'},
{'base':'ao','letters':'\uA735'},
{'base':'au','letters':'\uA737'},
{'base':'av','letters':'\uA739\uA73B'},
{'base':'ay','letters':'\uA73D'},
{'base':'b', 'letters':'\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253'},
{'base':'c', 'letters':'\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184'},
{'base':'d', 'letters':'\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A'},
{'base':'dz','letters':'\u01F3\u01C6'},
{'base':'e', 'letters':'\u0065\u24D4\uFF45\u00E8\u00E9\u00EA\u1EC1\u1EBF\u1EC5\u1EC3\u1EBD\u0113\u1E15\u1E17\u0115\u0117\u00EB\u1EBB\u011B\u0205\u0207\u1EB9\u1EC7\u0229\u1E1D\u0119\u1E19\u1E1B\u0247\u025B\u01DD'},
{'base':'f', 'letters':'\u0066\u24D5\uFF46\u1E1F\u0192\uA77C'},
{'base':'g', 'letters':'\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F'},
{'base':'h', 'letters':'\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265'},
{'base':'hv','letters':'\u0195'},
{'base':'i', 'letters':'\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131'},
{'base':'j', 'letters':'\u006A\u24D9\uFF4A\u0135\u01F0\u0249'},
{'base':'k', 'letters':'\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3'},
{'base':'l', 'letters':'\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747'},
{'base':'lj','letters':'\u01C9'},
{'base':'m', 'letters':'\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F'},
{'base':'n', 'letters':'\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5'},
{'base':'nj','letters':'\u01CC'},
{'base':'o', 'letters':'\u006F\u24DE\uFF4F\u00F2\u00F3\u00F4\u1ED3\u1ED1\u1ED7\u1ED5\u00F5\u1E4D\u022D\u1E4F\u014D\u1E51\u1E53\u014F\u022F\u0231\u00F6\u022B\u1ECF\u0151\u01D2\u020D\u020F\u01A1\u1EDD\u1EDB\u1EE1\u1EDF\u1EE3\u1ECD\u1ED9\u01EB\u01ED\u00F8\u01FF\u0254\uA74B\uA74D\u0275'},
{'base':'oi','letters':'\u01A3'},
{'base':'ou','letters':'\u0223'},
{'base':'oo','letters':'\uA74F'},
{'base':'p','letters':'\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755'},
{'base':'q','letters':'\u0071\u24E0\uFF51\u024B\uA757\uA759'},
{'base':'r','letters':'\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783'},
{'base':'s','letters':'\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B'},
{'base':'t','letters':'\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787'},
{'base':'tz','letters':'\uA729'},
{'base':'u','letters': '\u0075\u24E4\uFF55\u00F9\u00FA\u00FB\u0169\u1E79\u016B\u1E7B\u016D\u00FC\u01DC\u01D8\u01D6\u01DA\u1EE7\u016F\u0171\u01D4\u0215\u0217\u01B0\u1EEB\u1EE9\u1EEF\u1EED\u1EF1\u1EE5\u1E73\u0173\u1E77\u1E75\u0289'},
{'base':'v','letters':'\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C'},
{'base':'vy','letters':'\uA761'},
{'base':'w','letters':'\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73'},
{'base':'x','letters':'\u0078\u24E7\uFF58\u1E8B\u1E8D'},
{'base':'y','letters':'\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF'},
{'base':'z','letters':'\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763'}
];
var diacriticsMap = {};
for (var i=0; i < defaultDiacriticsRemovalMap .length; i++){
var letters = defaultDiacriticsRemovalMap [i].letters;
for (var j=0; j < letters.length ; j++){
diacriticsMap[letters[j]] = defaultDiacriticsRemovalMap [i].base;
}
}
// "what?" version ... http://jsperf.com/diacritics/12
function removeDiacritics (str) {
return str.replace(/[^\u0000-\u007E]/g, function(a){
return diacriticsMap[a] || a;
});
}
// var paragraph = "L'avantage d'utiliser le lorem ipsum est bien évidemment de pouvoir créer des maquettes ou de remplir un site internet de contenus qui présentent un rendu s'approchant un maximum du rendu final. \n Par défaut lorem ipsum ne contient pas d'accent ni de caractères spéciaux contrairement à la langue française qui en contient beaucoup. C'est sur ce critère que nous proposons une solution avec cet outil qui générant du faux-texte lorem ipsum mais avec en plus, des caractères spéciaux tel que les accents ou certains symboles utiles pour la langue française. \n L'utilisation du lorem standard est facile dutilisation mais lorsque le futur client utilisera votre logiciel il se peut que certains caractères spéciaux ou qu'un accent ne soient pas codés correctement. \n Cette page a pour but donc de pouvoir perdre le moins de temps possible et donc de tester directement si tous les encodages de base de donnée ou des sites sont les bons de plus il permet de récuperer un code css avec le texte formaté !";
// alert(removeDiacritics(paragraph));

35
app.json Normal file
View File

@@ -0,0 +1,35 @@
{
"name": "Chatbot Whatsapp (Leifer Mendez)",
"description": "El siguiente proyecto se realizó con fines educativos para el canal de Youtube (Leifer Mendez) donde aprendemos como usando node.js podemos crear un chatbot increíble que además le agregamos inteligencia artificial gracias al servicio de dialogflow",
"repository": "https://github.com/leifermendez/bot-whatsapp",
"logo": "https://avatars0.githubusercontent.com/u/15802366?s=460&u=77ec7ef359e8ed842aef769693f1675c0ed460fd&v=4",
"keywords": [
"nodejs",
"whatsapp",
"bot",
"chatbot",
"dialogflow"
],
"addons": [
],
"buildpacks": [
{
"url": "heroku/nodejs"
},
{
"url": "https://github.com/jontewks/puppeteer-heroku-buildpack"
}
],
"env": {
"SAVE_MEDIA": "false",
"DATABASE": {
"description": "'none', 'mysql', 'dialogflow' por defecto 'none' Puedes usar alguna de los siguientes opciones. Pero antes debes de saber como funciona y eso lo explico en el video. Puedes obtener más información https://github.com/leifermendez/bot-whatsapp/blob/main/README.md",
"value": "none"
},
"LANGUAGE": "es",
"SQL_HOST":"your_host",
"SQL_USER":"your_user",
"SQL_PASS":"your_password",
"SQL_DATABASE":"your_database"
}
}

View File

@@ -1,70 +0,0 @@
module.exports = {
disableEmoji: false,
format: '{type}{scope}: {emoji}{subject}',
list: ['test', 'feat', 'fix', 'chore', 'docs', 'refactor', 'style', 'ci', 'perf'],
maxMessageLength: 64,
minMessageLength: 3,
questions: ['type', 'scope', 'subject', 'body', 'breaking', 'issues', 'lerna'],
scopes: [],
types: {
chore: {
description: 'Build process or auxiliary tool changes',
emoji: '(🤖)',
value: 'chore',
},
ci: {
description: 'CI related changes',
emoji: '(🎡)',
value: 'ci',
},
docs: {
description: 'Documentation only changes',
emoji: '(✏️)',
value: 'docs',
},
feat: {
description: 'A new feature',
emoji: '(🎸)',
value: 'feat',
},
fix: {
description: 'A bug fix',
emoji: '(🐛)',
value: 'fix',
},
perf: {
description: 'A code change that improves performance',
emoji: '(⚡️)',
value: 'perf',
},
refactor: {
description: 'A code change that neither fixes a bug or adds a feature',
emoji: '(💡)',
value: 'refactor',
},
release: {
description: 'Create a release commit',
emoji: '(🏹)',
value: 'release',
},
style: {
description: 'Markup, white-space, formatting, missing semi-colons...',
emoji: '(💄)',
value: 'style',
},
test: {
description: 'Adding missing tests',
emoji: '(💍)',
value: 'test',
},
messages: {
type: "Select the type of change that you're committing:",
customScope: 'Select the scope this component affects:',
subject: 'Write a short, imperative mood description of the change:\n',
body: 'Provide a longer description of the change:\n ',
breaking: 'List any breaking changes:\n',
footer: 'Issues this commit closes, e.g #123:',
confirmCommit: 'The packages that this commit has affected\n',
},
},
}

13
chatbot-account.json Normal file
View File

@@ -0,0 +1,13 @@
{
"type": "",
"project_id": "",
"private_key_id": "",
"private_key":"",
"client_email": "",
"client_id": "",
"auth_uri": "",
"token_uri": "",
"auth_provider_x509_cert_url": "",
"client_x509_cert_url":""
}

View File

@@ -1 +0,0 @@
module.exports = { extends: ['@commitlint/config-conventional'] }

View File

@@ -1,8 +0,0 @@
{
"banner.output": [
"/** \n",
"* NO TOCAR ESTE ARCHIVO: Es generado automaticamente, si sabes lo que haces adelante ;)\n",
"* de lo contrario mejor ir a la documentacion o al servidor de discord link.codigoencasa.com/DISCORD\n",
"*/"
]
}

18
config/mysql.js Normal file
View File

@@ -0,0 +1,18 @@
const mysql = require('mysql');
const connection = mysql.createConnection({
host : process.env.SQL_HOST || 'localhost',
user : process.env.SQL_USER || 'root',
password : process.env.SQL_PASS || '',
database : process.env.SQL_DATABASE || 'pruebas'
});
const connect = () => connection.connect(function(err) {
if (err) {
console.error('error connecting: ' + err.stack);
return;
}
console.log('Conexion correcta con tu base de datos MySQL')
});
module.exports = {connect, connection}

14
controllers/connection.js Normal file
View File

@@ -0,0 +1,14 @@
const connectionReady = (cb = () =>{}) => {
console.log('Listo para escuchar mensajes')
console.log('El cliente esta listo!');
console.log('🔴 Escribe: /menu');
cb()
}
const connectionLost = (cb = () =>{}) => {
console.log('** Error de autentificacion vuelve a generar el QRCODE (Borrar el archivo session.json) **');
cb()
}
module.exports = {connectionReady, connectionLost}

37
controllers/flows.js Normal file
View File

@@ -0,0 +1,37 @@
const { get, reply, getIA } = require('../adapter')
const { saveExternalFile, checkIsUrl } = require('./handle')
const getMessages = async (message, num) => { //MOD by CHV - Agregamos el parametro "num" para recibir el numero desde "app.js"
// console.log("GETMESSAGES (flow.js)")
const data = await get(message, num) //MOD by CHV - Agregamos "num"
return data
}
const responseMessages = async (step) => {
const data = await reply(step)
if( data && data.media ){
const file = checkIsUrl(data.media) ? await saveExternalFile(data.media) : data.media;
return { ...data, ...{media:file}}
}
return data
}
const bothResponse = async (message) => {
const data = await getIA(message)
if(data && data.media){
const file = await saveExternalFile(data.media)
return {...data,...{media:file}}
}
return data
}
const waitFor = (conditionFunction, WAIT_TIME) => {
const poll = resolve => {
if (conditionFunction())
resolve();
else setTimeout(_ => poll(resolve), WAIT_TIME);
}
return new Promise(poll);
}
module.exports = { getMessages, responseMessages, bothResponse, waitFor }

83
controllers/handle.js Normal file
View File

@@ -0,0 +1,83 @@
const { Client, LegacySessionAuth, LocalAuth } = require('whatsapp-web.js');
const http = require('http'); // or 'https' for https:// URLs
const https = require('https'); // or 'https' for https:// URLs
const fs = require('fs');
const qr = require('qr-image')
const MULTI_DEVICE = process.env.MULTI_DEVICE || 'true';
const cleanNumber = (number) => {
number = number.replace('@c.us', '');
number = `${number}@c.us`;
return number
}
const saveExternalFile = (url) => new Promise((resolve, reject) => {
const ext = url.split('.').pop()
const checkProtocol = url.split('/').includes('https:');
const handleHttp = checkProtocol ? https : http;
const name = `${Date.now()}.${ext}`;
const file = fs.createWriteStream(`${__dirname}/../mediaSend/${name}`);
console.log(url)
handleHttp.get(url, function(response) {
response.pipe(file);
file.on('finish', function() {
file.close(); // close() is async, call cb after close completes.
resolve(name)
});
file.on('error', function() {
console.log('errro')
file.close(); // close() is async, call cb after close completes.
resolve(null)
});
});
})
const checkIsUrl = (path) => {
try{
regex = /^(http(s)?:\/\/)[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/i;
match = path.match(regex);
return match[0]
}catch(e){
return null
}
}
const generateImage = (base64, cb = () => {}) => {
let qr_svg = qr.image(base64, { type: 'svg', margin: 4 });
qr_svg.pipe(require('fs').createWriteStream('./mediaSend/qr-code.svg'));
console.log(`⚡ Recuerda que el QR se actualiza cada minuto ⚡'`);
console.log(`⚡ Actualiza F5 el navegador para ver el QR mas reciente⚡`);
cb()
}
const checkEnvFile = () => {
const pathEnv = `${__dirname}/../.env`;
const isExist = fs.existsSync(pathEnv);
if(!isExist){
console.log(`🆗 ATENCION! 🆗 te falta crear tu archivo .env de lo contrario no funcionara`)
}
}
/**
*
* @param {*} session
* @param {*} cb
*/
const createClient = () => {
client = new Client({
authStrategy: new LocalAuth(
{dataPath: './sessions/',
clientId: 'bot'}),
puppeteer: { headless: false, args: ['--no-sandbox','--disable-setuid-sandbox'] }
});
}
const isValidNumber = (rawNumber) => {
const regexGroup = /\@g.us\b/gm;
const exist = rawNumber.match(regexGroup);
return !exist
}
module.exports = {cleanNumber, saveExternalFile, generateImage, checkIsUrl, checkEnvFile, createClient, isValidNumber}

38
controllers/save.js Normal file
View File

@@ -0,0 +1,38 @@
const mimeDb = require('mime-db');
const { uploadSingleFile } = require('../adapter/gdrive');
const fs = require('fs');
var fileName;
/**
* Guardamos archivos multimedia que nuestro cliente nos envie!
* @param {*} media
*/
const saveMedia = (media) => {
const extensionProcess = mimeDb[media.mimetype];
let ext;
if (!extensionProcess) {
const fileType = media.mimetype.split('/');
ext = fileType[1].split(';')[0];
} else {
ext = extensionProcess.extensions[0];
}
fileName = `${Date.now()}.${ext}`;
fs.writeFile(`./media/${fileName}`, media.data, { encoding: 'base64' }, function (err) {
console.log(`** Archivo Media ${fileName} Guardado **`);
});
return fileName
}
const saveMediaToGoogleDrive = async (media) => {
fileName = saveMedia(media);
filePath = `${__dirname}/../media/${fileName}`
const googleDriveUrl = await uploadSingleFile(fileName, filePath);
return googleDriveUrl
}
module.exports = { saveMedia, saveMediaToGoogleDrive }

138
controllers/send.js Normal file
View File

@@ -0,0 +1,138 @@
const ExcelJS = require('exceljs');
const moment = require('moment');
const fs = require('fs');
const { MessageMedia, Buttons, List } = require('whatsapp-web.js');
const { cleanNumber } = require('./handle')
const { remplazos } = require('../adapter/index'); //MOD by CHV - Agregamos remplazos
const DELAY_TIME = 170; //ms
const DIR_MEDIA = `${__dirname}/../mediaSend`;
// import { Low, JSONFile } from 'lowdb'
// import { join } from 'path'
const { saveMessage } = require('../adapter')
/**
* Enviamos archivos multimedia a nuestro cliente
* @param {*} number
* @param {*} fileName
*/
const sendMedia = (client, number = null, fileName = null, trigger = null) => {
if(!client) return console.error("El objeto cliente no está definido.");
console.log("MEDIA:"+fileName);
try {
number = cleanNumber(number || 0)
const file = `${DIR_MEDIA}/${fileName}`;
console.log("FILE="+file);
if (fs.existsSync(file)) {
console.log("ARCHIVO EXISTE");
const media = MessageMedia.fromFilePath(file);
client.sendMessage(number, media, { sendAudioAsVoice: true });
}
} catch(e) {
throw e;
}
}
/**
* Enviamos archivos como notas de voz
* @param {*} number
* @param {*} fileName
*/
const sendMediaVoiceNote = (client, number = null, fileName = null) => {
if(!client) return console.error("El objeto cliente no está definido.");
try {
number = cleanNumber(number || 0)
const file = `${DIR_MEDIA}/${fileName}`;
if (fs.existsSync(file)) {
const media = MessageMedia.fromFilePath(file);
client.sendMessage(number, media ,{ sendAudioAsVoice: true });
}
}catch(e) {
throw e;
}
}
/**
* Enviamos un mensaje simple (texto) a nuestro cliente
* @param {*} number
*/
const sendMessage = async (client, number = null, text = null, trigger = null, regla) => { //MOD by CHV - Agregamos el parametro "regla" para guardarlo en "chats/numero.json"
setTimeout(async () => {
number = cleanNumber(number)
const message = text
client.sendMessage(number, message);
await readChat(number, message, trigger, regla) //MOD by CHV - Agregamos el parametro "regla"
console.log(`⚡⚡⚡ Enviando mensajes....`);
// console.log("********************* SEND MESSAGE **************************************");
},DELAY_TIME)
}
/**
* Enviamos un mensaje con buttons a nuestro cliente
* @param {*} number
*/
const sendMessageButton = async (client, number = null, text = null, actionButtons) => {
setTimeout(async () => {
number = cleanNumber(number)
const { title = null, message = null, footer = null, buttons = [] } = actionButtons;
let button = new Buttons(remplazos(message, client),[...buttons], remplazos(title, client), remplazos(footer, client));
await readChat(number, message, actionButtons)
client.sendMessage(number, button);
console.log(`⚡⚡⚡ Enviando mensajes (botones)....`);
// console.log("sendMessageButton.");
}, DELAY_TIME)
// console.log("************************ SEND MESSAGE BUTTON ***********************************");
}
/**
* Enviamos listas (con el formato de response.json)
* @param {*} number
*/
const sendMessageList = async (client, number = null, text = null, actionList) => {
setTimeout(async () => {
// console.log("********************** client **************************")
// console.log(client)
number = cleanNumber(number)
const { body = null, buttonText = null, sections = [], title = null, footer = null } = actionList;
let aList = new List( remplazos(body, client),remplazos(buttonText, client),[...sections],remplazos(title, client),remplazos(footer, client));
client.sendMessage(number, aList);
await readChat(number, message, actionList)
console.log('⚡⚡⚡ Enviando lista a '+number+' ....');
}, DELAY_TIME)
}
/**
* Opte
*/
const lastTrigger = (number) => new Promise((resolve, reject) => {
number = cleanNumber(number)
const pathExcel = `${__dirname}/../chats/${number}.xlsx`;
const workbook = new ExcelJS.Workbook();
if (fs.existsSync(pathExcel)) {
workbook.xlsx.readFile(pathExcel)
.then(() => {
const worksheet = workbook.getWorksheet(1);
const lastRow = worksheet.lastRow;
const getRowPrevStep = worksheet.getRow(lastRow.number);
const lastStep = getRowPrevStep.getCell('C').value;
resolve(lastStep)
});
} else {
resolve(null)
}
})
/**
* Guardar historial de conversacion
* @param {*} number
* @param {*} message
*/
const readChat = async (number, message, trigger = null, regla) => { //MOD by CHV - Agregamos el parametro "regla" para guardarlo en "chats/numero.json"
number = cleanNumber(number)
await saveMessage( message, trigger, number, regla ) //MOD by CHV - Agregamos "regla"
// console.log('Saved')
}
module.exports = { sendMessage, sendMedia, lastTrigger, sendMessageButton, sendMessageList, readChat, sendMediaVoiceNote }

16
controllers/socket.js Normal file
View File

@@ -0,0 +1,16 @@
module.exports = (socket) => {
return {
sendQR:(qr) => {
socket.emit('connection_qr',{
qr
})
},
sendStatus:() => {
socket.emit('connection_status',{
a:1
})
}
}
}

17
controllers/web.js Normal file
View File

@@ -0,0 +1,17 @@
const fs = require('fs')
const { sendMessage } = require('../controllers/send')
const sendMessagePost = (req, res) => {
console.log('asdasdasdasdasd')
const { message, number } = req.body
const client = req.clientWs || null;
sendMessage(client, number, message)
res.send({ status: 'Enviado!' })
}
const getQr = (req, res) => {
res.writeHead(200, { 'content-type': 'image/svg+xml' });
fs.createReadStream(`${__dirname}/../mediaSend/qr-code.svg`).pipe(res);
}
module.exports = { sendMessagePost, getQr }

View File

@@ -1,25 +0,0 @@
version: '3.3'
services:
mongo:
image: mongo
container_name: app_enviroment
restart: always
ports:
- '27019:27017'
environment:
MONGO_INITDB_DATABASE: bot
expose:
- 27019
mysql:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: example
MYSQL_DATABASE: bot
container_name: app_mysql
ports:
- '3306:3306'
expose:
- 3306

8
flow/dialogflow.json Normal file
View File

@@ -0,0 +1,8 @@
[
{
"phrases": [
"Se requiere una foto de alguna identificación por razones de seguridad.",
"Por favor envíenos una foto de su ID para completar su formulario."
]
}
]

86
flow/initial.json Normal file
View File

@@ -0,0 +1,86 @@
[
{
"keywords": [
"xmuchas gracias",
"xgracias",
"xvale gracias"
],
"key": "Gracias"
},
{
"keywords": ["/menu"],
"key": "menu"
},
{
"keywords": ["1"],
"key": "opcion1"
},
{
"keywords": ["2"],
"key": "opcion2"
},
{
"keywords": ["3"],
"key": "opcion3"
},
{
"keywords": "*",
"key": "recibenombre"
},
{
"keywords": "*",
"key": "gRevisaCliente"
},
{
"keywords": "*",
"key": "gGuardainfo"
},
{
"keywords": ["rnd"],
"key": "rnd"
},
{
"keywords": ["rnd2"],
"key": "rnd2"
},
{
"keywords": ["4"],
"key": "lista"
},
{
"keywords": ["5"],
"key": "botones"
},
{
"keywords": ["6"],
"key": "botonespaq3"
},
{
"keywords": ["cursos"],
"key": "cursos"
},
{
"keywords": ["youtube"],
"key": "youtube"
},
{
"keywords": ["telegram"],
"key": "telegram"
},
{
"keywords": ["manzana"],
"key": "manzana"
},
{
"keywords": ["mango"],
"key": "mango"
},
{
"keywords": ["platano"],
"key": "platano"
},
{
"keywords": "*pak*3*|*pak*angular*|*paquete*3*|*paquete*angular*",
"key": "paq3"
}
]

219
flow/response.json Normal file
View File

@@ -0,0 +1,219 @@
{
"DEFAULT":{
"replyMessage":[
"*Esta respuesta es un respuesta default* cuando no se consigue una palabra clave \n",
"la puedes desactivar en tu archivo .env DEFAULT_MESSAGE=false \n",
"tambien te quiero recordar que si presentas algun error pasarte por el repositorio \n",
"https://github.com/leifermendez/bot-whatsapp#chatbot-whatsapp-opensource \n",
"y recuerda tener la ultima versión del proyecto \n\n",
"Prueba escribiendo *hola* \n"
],
"media":null,
"trigger":null
},
"menu":{
"replyMessage":[
"%saludo% %primer_nombre%, este es el menú, selecciona una opción: \n",
"Pon *1* para mensajes anteriores.\n",
"Pon *2* para ver remplazos.\n",
"Pon *3* para pedir nombre (RegExp).\n",
"Pon *4* para un ejemplo de listas y expresiones regulares.\n",
"Pon *5* para un ejemplo de botones.\n",
"Pon *6* para un ejemplo de botones y regExp.\n"
],
"media":null,
"trigger":null
},
"opcion1":{
"replyMessage":[
"Seleccionaste la opción 1\n",
"*Ultimo mensaje:*\n",
"%msjant_0%\n",
"*Penultimo mensaje:*\n",
"%msjant_1%\n",
"*Antepenultimo mensaje:*\n",
"%msjant_2% \n\n",
"Automáticamente el flujo se regresa al *menú*, asi que puedes poner nuevamente un número del 1 al 3 sin necesidad de volver a iniciar con */menu*."
],
"media":null,
"pasoRequerido":"menu",
"goto":"menu"
},
"opcion2":{
"replyMessage":[
"Seleccionaste la opción 2\n",
"Remplazamos %saludo.% con *\"%saludo%\"*\n",
"Remplazamos %dia_semana.% con *\"%dia_semana%\"*\n",
"Remplazamos %hora24.%:%minutos.% con *\"%hora24%:%minutos%\"*\n",
"Remplazamos %.rnd_👍🏽,🤞🏼,🤪,🤔% con '%rnd_👍🏽,🤞🏼,🤪,🤔%'\n\n",
"Automáticamente el flujo se regresa al *menú*, asi que puedes poner nuevamente un número del 1 al 3 sin necesidad de volver a iniciar con */menu*."
],
"media":null,
"pasoRequerido":"menu",
"goto":"menu"
},
"opcion3":{
"replyMessage":[
"Seleccionaste la opción 3\n\n",
"Por favor dame tu nombre.\n\n",
"Aquí vamos a aceptar *cualquier* texto, porque en el *initial.json* tenemos keywords : \"***\" (un asterisco en expresiones regulares quiere decir *\"cualquier cosa\"*)\n",
"Y en *response.json* en la opción correspondiente tenemos \"pasoRequerido\" : \"menu\", que quiere decir que SOLO se va a disparar cuando el paso anterior sea \"menu\"."
],
"media":null,
"pasoRequerido":"menu"
},
"recibenombre":{
"replyMessage":[
"Gracias por tu nombre *%msjant_0%*.\n\n",
"Automáticamente el flujo se regresa al *menú*, asi que puedes poner nuevamente un número del 1 al 3 sin necesidad de volver a iniciar con */menu*."
],
"media":null,
"trigger":null,
"pasoRequerido":"opcion3",
"goto":"menu"
},
"gRevisaCliente":{
"replyMessage":[
"/URL=http://localhost:8888/dbrquery?j={\"query\":\"select_revisacliente_GUNA\",\"exec\":\"ExecuteQuery\",\"params\":{\"par1\":\"XXPARAM1XX\"}}"
],
"media":null,
"trigger":null,
"pasoRequerido":"gallina"
},
"gGuardainfo":{
"replyMessage":[
"/URL=http://localhost:8888/dbrquery?j={\"query\":\"insert_registroGallina_GUNA\",\"exec\":\"ExecuteCommand\",\"params\":{\"par1\":\"XXPARAM1XX\", \"par2\":\"XXPARAM2XX\", \"par3\":\"XXPARAM3XX\", \"par4\":\"XXPARAM4XX\"}}"
],
"media":null,
"trigger":null,
"pasoRequerido":"gRevisaCliente"
},
"rnd":{
"replyMessage":[
"%saludo%\nHoy es %dia_semana%.\nSon las %hora24%:%minutos% hrs.\nSon las %hora12%:%minutos% %ampm%\n*Palabra random:* %rnd_arbol,burro,cabra,dinosaurio,elefante,fuego,gorila%\n*Emoji random:* %rnd_👍🏽,😁,🤣,🤔,🤦🏽‍♂️,🙄,😎%\n*Número random:* %rnd_1,2,3,4,5,6,7%\n"
],
"media":null,
"trigger":null
},
"rnd2":{
"replyMessage":[
""
],
"media":null,
"trigger":null,
"actions":{
"title":"¿Que te interesa ver?",
"message":"%saludo%\nHoy es %dia_semana%.\nSon las %hora24%:%minutos% hrs.\nSon las %hora12%:%minutos% %ampm%\n*Palabra random:* %rnd_arbol,burro,cabra,dinosaurio,elefante,fuego,gorila%\n*Emoji random:* %rnd_👍🏽,😁,🤣,🤔,🤦🏽‍♂️,🙄,😎%\n*Número random:* %rnd_1,2,3,4,5,6,7%\n",
"footer":"Gracias",
"buttons":[
{"body":"Cursos"},
{"body":"Youtube"},
{"body":"Telegram"}
]
}
},
"lista":{
"replyMessage":[
"*%saludo%*, este es un ejemplo de listas"
],
"media":null,
"trigger":null,
"actions":{
"body":"Hola *%primer_nombre%*, estos son ejemplos del uso de expresiones regulares, todas las opciones de la lista disparan la misma regla:\n\n'*pak*3*|*pak*angular*|*paquete*3*|*paquete*angular*'\n\nAutomáticamente el flujo se regresa al *menú*, asi que puedes poner nuevamente un número del 1 al 5 sin necesidad de volver a iniciar con */menu*.",
"buttonText":"Ver los ejemplos de RegEx",
"sections": [
{"title":"Selecciona un mensaje:",
"rows":[
{"id": "paq3", "title": "Me gusta el paquete 3"},
{"id": "paqA", "title": "Por favor mas info del paquete de Angular"},
{"id": "pakA", "title": "Me gustó el pak de Angular"},
{"id": "pak3", "title": "Estoy interesado en el pak 3"}
]
}
],
"title":"Por favor selecciona un producto"
},
"pasoRequerido":"menu",
"goto":"menu"
},
"botones":{
"replyMessage":[
"*%saludo%*, este es un ejemplo de botones"
],
"media":"https://media2.giphy.com/media/VQJu0IeULuAmCwf5SL/giphy.gif",
"trigger":null,
"actions":{
"title":"¿Que te interesa ver %primer_nombre%?",
"message":"Recuerda todo este contenido es gratis y estaria genial que me sigas!",
"footer":"Automáticamente el flujo se regresa al *menú*, asi que puedes poner nuevamente un número del 1 al 5 sin necesidad de volver a iniciar con */menu*.",
"buttons":[
{"body":"Cursos"},
{"body":"Youtube"},
{"body":"Telegram"}
]
},
"pasoRequerido":"menu",
"goto":"menu"
},
"cursos":{
"replyMessage":["*%saludo% %primer_nombre%*, seleccionaste *Cursos*\n\n","Automáticamente el flujo se regresa al *menú*, asi que puedes poner nuevamente un número del 1 al 5 sin necesidad de volver a iniciar con */menu*."],
"trigger":null,
"pasoRequerido":"menu",
"goto":"menu"
},
"youtube":{
"replyMessage":["*%saludo% %primer_nombre%*, seleccionaste *YouTube*\n\n","Automáticamente el flujo se regresa al *menú*, asi que puedes poner nuevamente un número del 1 al 5 sin necesidad de volver a iniciar con */menu*."],
"trigger":null,
"pasoRequerido":"menu",
"goto":"menu"
},
"telegram":{
"replyMessage":["*%saludo% %primer_nombre%*, seleccionaste *Telegram*\n\n","Automáticamente el flujo se regresa al *menú*, asi que puedes poner nuevamente un número del 1 al 5 sin necesidad de volver a iniciar con */menu*."],
"trigger":null,
"pasoRequerido":"menu",
"goto":"menu"
},
"manzana":{
"replyMessage":["*%saludo% %primer_nombre%*, seleccionaste *manzana*\n\n","Automáticamente el flujo se regresa al *menú*, asi que puedes poner nuevamente un número del 1 al 5 sin necesidad de volver a iniciar con */menu*."],
"trigger":null,
"pasoRequerido":"menu",
"goto":"menu"
},
"mango":{
"replyMessage":["*%saludo% %primer_nombre%*, seleccionaste *mango*\n\n","Automáticamente el flujo se regresa al *menú*, asi que puedes poner nuevamente un número del 1 al 5 sin necesidad de volver a iniciar con */menu*."],
"trigger":null,
"pasoRequerido":"menu",
"goto":"menu"
},
"platano":{
"replyMessage":["*%saludo% %primer_nombre%*, seleccionaste *platano*\n\n","Automáticamente el flujo se regresa al *menú*, asi que puedes poner nuevamente un número del 1 al 5 sin necesidad de volver a iniciar con */menu*."],
"trigger":null,
"pasoRequerido":"menu",
"goto":"menu"
},
"paq3":{
"replyMessage":["*%saludo% %primer_nombre%*, seleccionaste el *paquete 3 de Angular*\n\n","Automáticamente el flujo se regresa al *menú*, asi que puedes poner nuevamente un número del 1 al 5 sin necesidad de volver a iniciar con */menu*."],
"trigger":null,
"pasoRequerido":"menu",
"goto":"menu"
},
"botonespaq3":{
"replyMessage":[
"*%saludo%*, este es un ejemplo de botones y regExp"
],
"media":null,
"trigger":null,
"actions":{
"title":"Hola %primer_nombre%, escoge un mensaje:",
"message":"Estos son ejemplos del uso de expresiones regulares, todos los botones disparan la misma regla:\n\n'*pak*3*|*pak*angular*|*paquete*3*|*paquete*angular*'\n\n",
"footer":"Automáticamente el flujo se regresa al *menú*, asi que puedes poner nuevamente un número del 1 al 5 sin necesidad de volver a iniciar con */menu*.",
"buttons":[
{"body":"Me gusta el paquete 3"},
{"body":"Mas info del paquete de Angular"},
{"body":"Quiero mas información del pak 3"}
]
},
"pasoRequerido":"menu",
"goto":"menu"
}
}

BIN
mediaSend/nota-de-voz.mp3 Normal file

Binary file not shown.

21
middleware/client.js Normal file
View File

@@ -0,0 +1,21 @@
const middlewareClient = (client = null) => async (req, res, next) => {
try {
if(!client){
res.status(409)
console.log(client)
res.send({ error: 'Error de client.' })
}else{
req.clientWs = client;
next()
}
} catch (e) {
console.log(e)
res.status(409)
res.send({ error: 'Error de client' })
}
}
module.exports = { middlewareClient }

0
middleware/db.js Normal file
View File

5405
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,104 +1,40 @@
{ {
"name": "@bot-whatsapp/root", "name": "test-ws-bot",
"version": "0.1.21", "version": "1.0.0",
"description": "Bot de wahtsapp open source para MVP o pequeños negocios", "description": "",
"main": "app.js", "main": "app.js",
"private": true,
"scripts": { "scripts": {
"commit": "git-cz", "start": "node ./app.js",
"cli:rollup": "rollup --config ./packages/cli/rollup-cli.config.js ", "test": "echo \"Error: no test specified\" && exit 1"
"create-bot:rollup": "rollup --config ./packages/create-bot-whatsapp/rollup-create.config.js ",
"bot:rollup": "rollup --config ./packages/bot/rollup-bot.config.js",
"provider:rollup": "rollup --config ./packages/provider/rollup-provider.config.js ",
"contexts:rollup": "rollup --config ./packages/contexts/rollup-contexts.config.js",
"database:rollup": "rollup --config ./packages/database/rollup-database.config.js",
"create-bot-whatsapp:rollup": "rollup --config ./packages/create-bot-whatsapp/rollup-create.config.js",
"portal:rollup": "rollup --config ./packages/portal/rollup-portal.config.js",
"format:check": "prettier --check ./packages",
"format:write": "prettier --write ./packages",
"fmt.staged": "pretty-quick --staged",
"lint:check": "eslint ./packages",
"lint:fix": "eslint --fix ./packages",
"build:portal-web": "cd ./packages/portal/ && yarn run build.types && yarn run build.client && yarn run build.server && yarn run lint --fix",
"build:full": "yarn run build:portal-web && yarn run cli:rollup && yarn run bot:rollup && yarn run provider:rollup && yarn run database:rollup && yarn run contexts:rollup && yarn run create-bot-whatsapp:rollup && yarn run portal:rollup",
"build": "yarn run cli:rollup && yarn run bot:rollup && yarn run provider:rollup && yarn run database:rollup && yarn run contexts:rollup && yarn run create-bot-whatsapp:rollup && yarn run portal:rollup",
"copy.lib": "node ./scripts/move.js",
"test.unit": "node ./node_modules/uvu/bin.js packages test",
"test.e2e": "node ./node_modules/uvu/bin.js __test__",
"test.coverage": "node ./node_modules/c8/bin/c8.js npm run test.unit",
"test": "npm run test.coverage",
"cli": "node ./packages/cli/bin/cli.js",
"create": "node ./packages/create-bot-whatsapp/bin/create.js",
"dev:debug": "node --inspect ./example-app/app.js",
"dev": "node ./example-app/app.js",
"prepare": "npx husky install",
"preinstall": "npx only-allow yarn",
"postinstall": "npx prettier --write .",
"release": "standard-version -- --prerelease --global"
}, },
"workspaces": [ "keywords": [],
"packages/create-bot-whatsapp", "author": "",
"packages/bot",
"packages/cli",
"packages/database",
"packages/provider",
"packages/contexts",
"packages/portal",
"packages/docs"
],
"keywords": [
"whatsapp",
"bot-whatsapp",
"node-bot-whatsapp"
],
"contributors": [
{
"email": "leifer33@gmail.com",
"name": "Leifer Mendez",
"url": "https://leifermendez.github.io"
},
{
"name": "aurik3",
"email": "aurik3@aurik3.com",
"url": "https://github.com/aurik3"
}
],
"repository": "https://github.com/leifermendez/bot-whatsapp",
"license": "ISC", "license": "ISC",
"dependencies": {
"@google-cloud/dialogflow": "^5.2.0",
"axios": "^0.27.2",
"cors": "^2.8.5",
"dotenv": "^16.0.1",
"exceljs": "^4.3.0",
"express": "^4.18.1",
"file-type": "^17.1.6",
"googleapis": "^109.0.1",
"mime-db": "^1.52.0",
"moment": "^2.29.4",
"mysql": "^2.18.1",
"pb-util": "^1.0.3",
"qr-image": "^3.2.0",
"qrcode-terminal": "^0.12.0",
"socket.io": "^4.5.1",
"stormdb": "^0.6.0",
"whatsapp-web.js": "github:pedroslopez/whatsapp-web.js#fix-buttons-list",
"xlsx": "^0.18.5"
},
"devDependencies": { "devDependencies": {
"@commitlint/cli": "^17.3.0", "pm2": "^5.2.0",
"@commitlint/config-conventional": "^17.3.0", "prettier": "2.7.1"
"@octokit/core": "^4.1.0",
"@rollup/plugin-commonjs": "^23.0.2",
"@rollup/plugin-json": "^5.0.1",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^5.0.1",
"c8": "^7.12.0",
"conventional-changelog": "^3.1.25",
"cross-env": "^7.0.3",
"eslint": "^8.26.0",
"eslint-config-prettier": "^8.5.0",
"fs-extra": "^11.1.0",
"git-cz": "^4.9.0",
"husky": "^8.0.2",
"mime-types": "^2.1.35",
"only-allow": "^1.1.1",
"prettier": "^2.8.0",
"pretty-quick": "^3.1.3",
"prompts": "^2.4.2",
"rimraf": "^3.0.2",
"rollup": "^3.2.3",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-copy": "^3.4.0",
"semver": "^7.3.8",
"standard-version": "^9.5.0",
"uvu": "^0.5.6"
}, },
"packageManager": "yarn@3.3.0",
"engines": { "engines": {
"node": ">=16", "node": "16.x"
"npm": "please-use-yarn", }
"yarn": ">=3"
},
"author": "Leifer Mendez <leifer33@gmail.com>"
} }

View File

@@ -1,110 +0,0 @@
# @bot-whatsapp/io
### Caso de uso
> Una persona escribe `hola`
**addKeyword** recibe `string | string[]`
> `sensitive` false _default_
- [x] addKeyword
- [x] addAnswer
- [x] addKeyword: Opciones
- [x] addAnswer: Opciones, media, buttons
- [x] Retornar JSON (options)
- [ ] Recibir JSON
```js
// bootstrap.js Como iniciar el provider
const { inout, provider, database } = require('@bot-whatsapp')
/**
* async whatsapp-web, twilio, meta
* */
const bootstrap = async () => {
console.log(`Iniciando....`)
const client = await provider.start()
/**
* - QR
* - Endpoint
* - Check Token Meta, Twilio
* - Return events? on message
* */
console.log(`Fin...`)
// Esto es opcional ? no deberia ser necesario
client.on('message', ({number, body,...}) => {
// Incoming message
})
}
```
```js
// flow.js Como agregar keywords y respuestas
const { inout, provider, database } = require('@bot-whatsapp')
await inout
.addKeyword('hola')
.addAnswer('Bienvenido a tu tienda 🥲')
.addAnswer('escribe *catalogo* o *ofertas*')
await inout
.addKeyword(['catalogo', 'ofertas'])
.addAnswer('Este es nuestro CATALOGO mas reciente!', {
buttons: [{ body: 'Xiaomi' }, { body: 'Samsung' }],
})
await inout
.addKeyword('Xiaomi')
.addAnswer('Estos son nuestro productos XIAOMI ....', {
media: 'https://....',
})
.addAnswer('Si quieres mas info escrbie *info*')
await inout
.addKeyword('chao!')
.addAnswer('bye!')
.addAnswer('Recuerda que tengo esta promo', {
media: 'https://media2.giphy.com/media/VQJu0IeULuAmCwf5SL/giphy.gif',
})
await inout
.addKeyword('Modelo C', { sensitive: false })
.addAnswer('100USD', { media: 'http//:...' })
await inout
.addKeyword('hola!', { sensitive: false })
.addAnswer('Bievenido Escribe *productos*')
await inout
.addKeyword('productos', { sensitive: false })
.addAnswer('Esto son los mas vendidos')
.addAnswer('*PC1* Precio 10USD', { media: 'https://....' })
.addAnswer('*PC2* Precio 10USD', { media: 'https://....' })
await inout
.addKeyword('PC1', { sensitive: false })
.addAnswer('Bievenido Escribe *productos*')
const answerOne = await inout.addAnswer({
message: 'Como estas!',
media: 'https://media2.giphy.com/media/VQJu0IeULuAmCwf5SL/giphy.gif',
})
const otherAnswer = await inout.addAnswer('Aprovecho para decirte!')
answerOne.push(otherAnswer)
inout.addKeywords(['hola', 'hi', 'ola'])
```
**Comunidad**
> Forma parte de este proyecto.
- [Discord](https://link.codigoencasa.com/DISCORD)
- [Twitter](https://twitter.com/leifermendez)
- [Youtube](https://www.youtube.com/watch?v=5lEMCeWEJ8o&list=PL_WGMLcL4jzWPhdhcUyhbFU6bC0oJd2BR)
- [Telegram](https://t.me/leifermendez)

View File

@@ -1,300 +0,0 @@
const { toCtx } = require('../io/methods')
const { printer } = require('../utils/interactive')
const { delay } = require('../utils/delay')
const Queue = require('../utils/queue')
const { Console } = require('console')
const { createWriteStream } = require('fs')
const logger = new Console({
stdout: createWriteStream(`${process.cwd()}/core.class.log`),
})
const QueuePrincipal = new Queue()
/**
* [ ] Escuchar eventos del provider asegurarte que los provider emitan eventos
* [ ] Guardar historial en db
* [ ] Buscar mensaje en flow
*
*/
class CoreClass {
flowClass
databaseClass
providerClass
generalArgs = { blackList: [] }
constructor(_flow, _database, _provider, _args) {
this.flowClass = _flow
this.databaseClass = _database
this.providerClass = _provider
this.generalArgs = { ...this.generalArgs, ..._args }
for (const { event, func } of this.listenerBusEvents()) {
this.providerClass.on(event, func)
}
}
/**
* Manejador de eventos
*/
listenerBusEvents = () => [
{
event: 'preinit',
func: () => printer('Iniciando proveedor, espere...'),
},
{
event: 'require_action',
func: ({ instructions, title = '⚡⚡ ACCIÓN REQUERIDA ⚡⚡' }) => printer(instructions, title),
},
{
event: 'ready',
func: () => printer('Proveedor conectado y listo'),
},
{
event: 'auth_failure',
func: ({ instructions }) => printer(instructions, '⚡⚡ ERROR AUTH ⚡⚡'),
},
{
event: 'message',
func: (msg) => this.handleMsg(msg),
},
]
/**
* GLOSSARY.md
* @param {*} messageCtxInComming
* @returns
*/
handleMsg = async (messageCtxInComming) => {
logger.log(`[handleMsg]: `, messageCtxInComming)
const { body, from } = messageCtxInComming
let msgToSend = []
let endFlowFlag = false
let fallBackFlag = false
if (this.generalArgs.blackList.includes(from)) return
if (!body) return
if (!body.length) return
let prevMsg = await this.databaseClass.getPrevByNumber(from)
const refToContinue = this.flowClass.findBySerialize(prevMsg?.refSerialize)
if (prevMsg?.ref) {
const ctxByNumber = toCtx({
body,
from,
prevRef: prevMsg.refSerialize,
})
await this.databaseClass.save(ctxByNumber)
}
// 📄 Crar CTX de mensaje (uso private)
const createCtxMessage = (payload = {}, index = 0) => {
const body = typeof payload === 'string' ? payload : payload?.body ?? payload?.answer
const media = payload?.media ?? null
const buttons = payload?.buttons ?? []
const capture = payload?.capture ?? false
return toCtx({
body,
from,
keyword: null,
index,
options: { media, buttons, capture },
})
}
// 📄 Limpiar cola de procesos
const clearQueue = () => {
QueuePrincipal.pendingPromise = false
QueuePrincipal.queue = []
}
// 📄 Finalizar flujo
const endFlow =
(flag) =>
async (message = null) => {
flag.endFlow = true
endFlowFlag = true
if (message) this.sendProviderAndSave(from, createCtxMessage(message))
clearQueue()
sendFlow([])
return
}
// 📄 Esta funcion se encarga de enviar un array de mensajes dentro de este ctx
const sendFlow = async (messageToSend, numberOrId, options = { prev: prevMsg }) => {
if (options.prev?.options?.capture) await cbEveryCtx(options.prev?.ref)
const queue = []
for (const ctxMessage of messageToSend) {
if (endFlowFlag) return
const delayMs = ctxMessage?.options?.delay || 0
if (delayMs) await delay(delayMs)
await QueuePrincipal.enqueue(() =>
this.sendProviderAndSave(numberOrId, ctxMessage).then(() => resolveCbEveryCtx(ctxMessage))
)
}
return Promise.all(queue)
}
const continueFlow = async () => {
const currentPrev = await this.databaseClass.getPrevByNumber(from)
const nextFlow = (await this.flowClass.find(refToContinue?.ref, true)) ?? []
const filterNextFlow = nextFlow.filter((msg) => msg.refSerialize !== currentPrev?.refSerialize)
const isContinueFlow = filterNextFlow.map((i) => i.keyword).includes(currentPrev?.ref)
if (!isContinueFlow) {
const refToContinueChild = this.flowClass.getRefToContinueChild(currentPrev?.keyword)
const flowStandaloneChild = this.flowClass.getFlowsChild()
const nextChildMessages =
(await this.flowClass.find(refToContinueChild?.ref, true, flowStandaloneChild)) || []
if (nextChildMessages?.length) return await sendFlow(nextChildMessages, from, { prev: undefined })
}
if (!isContinueFlow) {
await sendFlow(filterNextFlow, from, { prev: undefined })
return
}
}
// 📄 [options: fallBack]: esta funcion se encarga de repetir el ultimo mensaje
const fallBack =
(flag) =>
async (message = null) => {
QueuePrincipal.queue = []
flag.fallBack = true
await this.sendProviderAndSave(from, {
...prevMsg,
answer: typeof message === 'string' ? message : message?.body ?? prevMsg.answer,
options: {
...prevMsg.options,
buttons: prevMsg.options?.buttons,
},
})
return
}
// 📄 [options: flowDynamic]: esta funcion se encarga de responder un array de respuesta esta limitado a 5 mensajes
// para evitar bloque de whatsapp
const flowDynamic =
(flag) =>
async (listMsg = []) => {
flag.flowDynamic = true
if (!Array.isArray(listMsg)) listMsg = [listMsg]
const parseListMsg = listMsg.map((opt, index) => createCtxMessage(opt, index))
if (endFlowFlag) return
for (const msg of parseListMsg) {
await this.sendProviderAndSave(from, msg)
}
await continueFlow()
return
}
// 📄 Se encarga de revisar si el contexto del mensaje tiene callback o fallback
const resolveCbEveryCtx = async (ctxMessage) => {
if (!ctxMessage?.options?.capture) return await cbEveryCtx(ctxMessage?.ref)
}
// 📄 Se encarga de revisar si el contexto del mensaje tiene callback y ejecutarlo
const cbEveryCtx = async (inRef) => {
let flags = {
endFlow: false,
fallBack: false,
flowDynamic: false,
wait: true,
}
const provider = this.providerClass
if (!this.flowClass.allCallbacks[inRef]) return Promise.resolve()
const argsCb = {
provider,
fallBack: fallBack(flags),
flowDynamic: flowDynamic(flags),
endFlow: endFlow(flags),
}
await this.flowClass.allCallbacks[inRef](messageCtxInComming, argsCb)
const wait = !(!flags.endFlow && !flags.fallBack && !flags.flowDynamic)
if (!wait) await continueFlow()
return
}
// 📄🤘(tiene return) [options: nested(array)]: Si se tiene flujos hijos los implementa
if (!endFlowFlag && prevMsg?.options?.nested?.length) {
const nestedRef = prevMsg.options.nested
const flowStandalone = nestedRef.map((f) => ({
...nestedRef.find((r) => r.refSerialize === f.refSerialize),
}))
msgToSend = this.flowClass.find(body, false, flowStandalone) || []
await sendFlow(msgToSend, from)
return
}
// 📄🤘(tiene return) Si el mensaje previo implementa capture
if (!endFlowFlag && !prevMsg?.options?.nested?.length) {
const typeCapture = typeof prevMsg?.options?.capture
if (typeCapture === 'boolean' && fallBackFlag) {
msgToSend = this.flowClass.find(refToContinue?.ref, true) || []
await sendFlow(msgToSend, from)
return
}
}
msgToSend = this.flowClass.find(body) || []
sendFlow(msgToSend, from)
}
/**
* Enviar mensaje con contexto atraves del proveedor de whatsapp
* @param {*} numberOrId
* @param {*} ctxMessage ver más en GLOSSARY.md
* @returns
*/
sendProviderAndSave = async (numberOrId, ctxMessage) => {
const { answer } = ctxMessage
await this.providerClass.sendMessage(numberOrId, answer, ctxMessage)
await this.databaseClass.save({ ...ctxMessage, from: numberOrId })
return
}
/**
* @deprecated
* @private
* @param {*} message
* @param {*} ref
*/
continue = (message, ref = false) => {
const responde = this.flowClass.find(message, ref)
if (responde) {
this.providerClass.sendMessage(responde.answer)
this.databaseClass.saveLog(responde.answer)
this.continue(null, responde.ref)
}
}
/**
* Funcion dedicada a enviar el mensaje sin pasar por el flow
* (dialogflow)
* @param {*} messageToSend
* @param {*} numberOrId
* @returns
*/
sendFlowSimple = async (messageToSend, numberOrId) => {
const queue = []
for (const ctxMessage of messageToSend) {
const delayMs = ctxMessage?.options?.delay || 0
if (delayMs) await delay(delayMs)
QueuePrincipal.enqueue(() => this.sendProviderAndSave(numberOrId, ctxMessage))
}
return Promise.all(queue)
}
}
module.exports = CoreClass

View File

@@ -1,45 +0,0 @@
const CoreClass = require('./core/core.class')
const ProviderClass = require('./provider/provider.class')
const FlowClass = require('./io/flow.class')
const { addKeyword, addAnswer, addChild, toSerialize } = require('./io/methods')
/**
* Crear instancia de clase Bot
* @param {*} args
* @returns
*/
const createBot = async ({ flow, database, provider }, args = {}) => new CoreClass(flow, database, provider, args)
/**
* Crear instancia de clase Io (Flow)
* @param {*} args
* @returns
*/
const createFlow = (args) => {
return new FlowClass(args)
}
/**
* Crear instancia de clase Provider
* Depdendiendo del Provider puedes pasar argumentos
* Ver Documentacion
* @param {*} args
* @returns
*/
const createProvider = (providerClass = class {}, args = null) => {
const providerInstance = new providerClass(args)
if (!providerClass.prototype instanceof ProviderClass) throw new Error('El provider no implementa ProviderClass')
return providerInstance
}
module.exports = {
createBot,
createFlow,
createProvider,
addKeyword,
addAnswer,
addChild,
toSerialize,
ProviderClass,
CoreClass,
}

View File

@@ -1,95 +0,0 @@
const { toSerialize } = require('./methods/toSerialize')
const { flatObject } = require('../utils/flattener')
class FlowClass {
allCallbacks = []
flowSerialize = []
flowRaw = []
constructor(_flow) {
if (!Array.isArray(_flow)) throw new Error('Esto debe ser un ARRAY')
this.flowRaw = _flow
this.allCallbacks = flatObject(_flow)
const mergeToJsonSerialize = Object.keys(_flow)
.map((indexObjectFlow) => _flow[indexObjectFlow].toJson())
.flat(2)
this.flowSerialize = toSerialize(mergeToJsonSerialize)
}
find = (keyOrWord, symbol = false, overFlow = null) => {
keyOrWord = `${keyOrWord}`
let capture = false
let messages = []
let refSymbol = null
overFlow = overFlow ?? this.flowSerialize
const mapSensitive = (str, mapOptions = { sensitive: false, regex: false }) => {
if (mapOptions.regex) return new RegExp(str)
const regexSensitive = mapOptions.sensitive ? 'g' : 'i'
if (Array.isArray(str)) {
return new RegExp(str.join('|'), regexSensitive)
}
return new RegExp(str, regexSensitive)
}
const findIn = (keyOrWord, symbol = false, flow = overFlow) => {
capture = refSymbol?.options?.capture || false
if (capture) return messages
if (symbol) {
refSymbol = flow.find((c) => c.keyword === keyOrWord)
if (refSymbol?.answer) messages.push(refSymbol)
if (refSymbol?.ref) findIn(refSymbol.ref, true)
} else {
refSymbol = flow.find((c) => {
const sensitive = c?.options?.sensitive || false
const regex = c?.options?.regex || false
return mapSensitive(c.keyword, { sensitive, regex }).test(keyOrWord)
})
if (refSymbol?.ref) findIn(refSymbol.ref, true)
return messages
}
}
findIn(keyOrWord, symbol)
return messages
}
findBySerialize = (refSerialize) => this.flowSerialize.find((r) => r.refSerialize === refSerialize)
findIndexByRef = (ref) => this.flowSerialize.findIndex((r) => r.ref === ref)
getRefToContinueChild = (keyword) => {
try {
const flowChilds = this.flowSerialize
.reduce((acc, cur) => {
const merge = [...acc, cur?.options?.nested].flat(2)
return merge
}, [])
.filter((i) => !!i && i?.refSerialize === keyword)
.shift()
return flowChilds
} catch (e) {
return undefined
}
}
getFlowsChild = () => {
try {
const flowChilds = this.flowSerialize
.reduce((acc, cur) => {
const merge = [...acc, cur?.options?.nested].flat(2)
return merge
}, [])
.filter((i) => !!i)
return flowChilds
} catch (e) {
return []
}
}
}
module.exports = FlowClass

View File

@@ -1,105 +0,0 @@
const { flatObject } = require('../../utils/flattener')
const { generateRef } = require('../../utils/hash')
const { addChild } = require('./addChild')
const { toJson } = require('./toJson')
/**
*
* @param answer string
* @param options {media:string, buttons:[{"body":"😎 Cursos"}], delay:ms, capture:true default false}
* @returns
*/
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
*/
const getAnswerOptions = () => ({
media: typeof options?.media === 'string' ? `${options?.media}` : null,
buttons: Array.isArray(options?.buttons) ? options.buttons : [],
capture: typeof options?.capture === 'boolean' ? options?.capture : false,
child: typeof options?.child === 'string' ? `${options?.child}` : null,
delay: typeof options?.delay === 'number' ? options?.delay : 0,
})
const getNested = () => {
let flatNested = []
if (Array.isArray(nested)) {
for (const iterator of nested) {
flatNested = [...flatNested, ...addChild(iterator)]
}
return {
nested: flatNested,
}
}
return {
nested: addChild(nested),
}
}
/**
* Esta funcion aplana y busca los callback anidados de los hijos
* @returns
*/
const getCbFromNested = () => flatObject(Array.isArray(nested) ? nested : [nested])
const callback = typeof cb === 'function' ? cb : () => null
const lastCtx = inCtx.hasOwnProperty('ctx') ? inCtx.ctx : inCtx
/**
* Esta funcion se encarga de mapear y transformar todo antes
* de retornar
* @returns
*/
const ctxAnswer = () => {
const ref = `ans_${generateRef()}`
const options = {
...getAnswerOptions(),
...getNested(),
keyword: {},
callback: !!cb,
}
const json = [].concat(inCtx.json).concat([
{
ref,
keyword: lastCtx.ref,
answer,
options,
},
])
getCbFromNested()
const callbacks = {
...inCtx.callbacks,
...getCbFromNested(),
[ref]: callback,
}
return {
...lastCtx,
ref,
answer,
json,
options,
callbacks,
}
}
/// Retornar contexto no colocar nada más abajo de esto
const ctx = ctxAnswer()
return {
ctx,
ref: ctx.ref,
addAnswer: addAnswer(ctx),
toJson: toJson(ctx),
}
}
module.exports = { addAnswer }

View File

@@ -1,15 +0,0 @@
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 }

View File

@@ -1,51 +0,0 @@
const { generateRef } = require('../../utils/hash')
const { addAnswer } = require('./addAnswer')
const { toJson } = require('./toJson')
/**
*
* @param {*} message `string | string[]`
* @param {*} options {sensitive:boolean} default false
*/
const addKeyword = (keyword, options) => {
if (typeof keyword !== 'string' && !Array.isArray(keyword)) {
throw new Error('DEBE_SER_STRING_ARRAY_REGEX')
}
const parseOptions = () => {
const defaultProperties = {
sensitive: typeof options?.sensitive === 'boolean' ? options?.sensitive : false,
regex: typeof options?.regex === 'boolean' ? options?.regex : false,
}
return defaultProperties
}
const ctxAddKeyword = () => {
const ref = `key_${generateRef()}`
const options = parseOptions()
const json = [
{
ref,
keyword,
options,
},
]
/**
* Se guarda en db
*/
return { ref, keyword, options, json }
}
const ctx = ctxAddKeyword()
return {
ctx,
ref: ctx.ref,
addAnswer: addAnswer(ctx),
toJson: toJson(ctx),
}
}
module.exports = { addKeyword }

View File

@@ -1,8 +0,0 @@
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, addChild, toCtx, toJson, toSerialize }

View File

@@ -1,19 +0,0 @@
const { generateRef, generateRefSerialize } = require('../../utils/hash')
/**
* @deprecate
* @param answer string
* @param options {media:string, buttons:[], capture:true default false}
* @returns
*/
const toCtx = ({ body, from, prevRef, options = {}, index }) => {
return {
ref: generateRef(),
keyword: prevRef,
answer: body,
options: options ?? {},
from,
refSerialize: generateRefSerialize({ index, answer: body }),
}
}
module.exports = { toCtx }

View File

@@ -1,6 +0,0 @@
const toJson = (inCtx) => () => {
const lastCtx = inCtx.hasOwnProperty('ctx') ? inCtx.ctx : inCtx
return lastCtx.json
}
module.exports = { toJson }

View File

@@ -1,23 +0,0 @@
const { generateRefSerialize } = require('../../utils/hash')
/**
* Crear referencia serializada
* @param {*} flowJson
* @returns array[]
*/
const toSerialize = (flowJson) => {
if (!Array.isArray(flowJson)) throw new Error('Esto debe ser un ARRAY')
const jsonToSerialize = flowJson.map((row, index) => ({
...row,
refSerialize: `${generateRefSerialize({
index,
keyword: row.keyword,
answer: row.answer,
})}`,
}))
return jsonToSerialize
}
module.exports = { toSerialize }

View File

@@ -1,14 +0,0 @@
const commonjs = require('@rollup/plugin-commonjs')
const { nodeResolve } = require('@rollup/plugin-node-resolve')
const { join } = require('path')
const PATH = join(__dirname, 'lib', 'io', 'bundle.io.cjs')
module.exports = {
input: 'index.js',
output: {
file: PATH,
format: 'cjs',
},
plugins: [commonjs(), nodeResolve()],
}

View File

@@ -1,36 +0,0 @@
{
"name": "@bot-whatsapp/bot",
"version": "0.0.100-alpha.0",
"description": "",
"main": "./lib/bundle.bot.cjs",
"scripts": {
"bot:rollup": "node ../../node_modules/.bin/rollup index.js --config ./rollup-cli.config.js",
"format:check": "prettier --check .",
"format:write": "prettier --write .",
"lint:check": "eslint .",
"lint:fix": "eslint --fix .",
"test.unit": "cross-env NODE_ENV=test node ../../node_modules/uvu/bin.js tests"
},
"keywords": [],
"files": [
"./lib/bundle.bot.cjs",
"./provider/*",
"./core/*",
"./io/*"
],
"author": "",
"license": "ISC",
"devDependencies": {
"@bot-whatsapp/cli": "*",
"@bot-whatsapp/database": "*",
"@bot-whatsapp/provider": "*",
"kleur": "^4.1.5"
},
"dependencies": {
"dotenv": "^16.0.3"
},
"repository": {
"type": "git",
"url": "https://github.com/codigoencasa/bot-whatsapp/tree/main/packages/bot"
}
}

View File

@@ -1,30 +0,0 @@
const { EventEmitter } = require('node:events')
/**
* Esta clase debe siempre proporcionar los siguietes metodos
* sendMessage = Para enviar un mensaje
*
* @important
* Esta clase extiende de la clase del provider OJO
* Eventos
* - message
* - ready
* - error
* - require_action
*/
const NODE_ENV = process.env.NODE_ENV || 'dev'
class ProviderClass extends EventEmitter {
/**
* events: message | auth | auth_error | ...
*
*/
sendMessage = async (userId, message) => {
if (NODE_ENV !== 'production') console.log('[sendMessage]', { userId, message })
return message
}
getInstance = () => this.vendor
}
module.exports = ProviderClass

View File

@@ -1,26 +0,0 @@
const banner = require('../../config/banner.rollup.json')
const commonjs = require('@rollup/plugin-commonjs')
const { nodeResolve } = require('@rollup/plugin-node-resolve')
const { join } = require('path')
module.exports = [
{
input: join(__dirname, 'index.js'),
output: {
banner: banner['banner.output'].join(''),
file: join(__dirname, 'lib', 'bundle.bot.cjs'),
format: 'cjs',
sourcemap: true,
},
plugins: [commonjs(), nodeResolve()],
},
{
input: join(__dirname, 'index.js'),
output: {
banner: banner['banner.output'].join(''),
file: join(__dirname, 'lib', 'bundle.bot.cjs'),
format: 'cjs',
},
plugins: [commonjs(), nodeResolve()],
},
]

View File

@@ -1,227 +0,0 @@
const { test } = require('uvu')
const assert = require('uvu/assert')
const FlowClass = require('../io/flow.class')
const MockProvider = require('../../../__mocks__/mock.provider')
const { createBot, CoreClass, createFlow, createProvider, ProviderClass } = require('../index')
class MockFlow {
allCallbacks = { ref: () => 1 }
flowSerialize = []
flowRaw = []
find = (arg) => {
if (arg) {
return [{ answer: 'answer', ref: 'ref' }]
} else {
return null
}
}
findBySerialize = () => ({})
findIndexByRef = () => 0
getRefToContinueChild = () => ({})
getFlowsChild = () => []
}
class MockDBA {
listHistory = []
save = () => {}
getPrevByNumber = () => {}
}
class MockDBB {
listHistory = []
save = () => {}
getPrevByNumber = () => ({
refSerialize: 'xxxxx',
ref: 'xxxx',
options: { callback: true },
})
}
class MockDBC {
listHistory = []
save = () => {}
getPrevByNumber = () => ({
refSerialize: 'xxxxx',
ref: 'xxxx',
options: { callback: true, nested: ['1', '2'] },
})
saveLog = () => {}
}
test(`[CoreClass] Probando instanciamiento de clase`, async () => {
const setting = {
flow: new MockFlow(),
database: new MockDBA(),
provider: new MockProvider(),
}
const bot = await createBot(setting)
assert.is(bot instanceof CoreClass, true)
})
test(`[CoreClass createFlow] Probando instanciamiento de clase`, async () => {
const mockCreateFlow = createFlow([])
assert.is(mockCreateFlow instanceof FlowClass, true)
})
test(`[CoreClass createProvider] Probando instanciamiento de clase`, async () => {
const mockCreateProvider = createProvider(MockProvider)
assert.is(mockCreateProvider instanceof ProviderClass, true)
})
test(`[Bot] Eventos 'require_action,ready,auth_failure,message '`, async () => {
let responseEvents = {}
const MOCK_EVENTS = {
require_action: {
instructions: 'Debes...',
},
ready: true,
auth_failure: {
instructions: 'Error...',
},
message: {
from: 'XXXXXX',
body: 'hola',
hasMedia: false,
},
}
const mockProvider = new MockProvider()
const setting = {
flow: new MockFlow(),
database: new MockDBA(),
provider: mockProvider,
}
await createBot(setting)
/// Escuchamos eventos
mockProvider.on('require_action', (r) => (responseEvents['require_action'] = r))
mockProvider.on('ready', (r) => (responseEvents['ready'] = r))
mockProvider.on('auth_failure', (r) => (responseEvents['auth_failure'] = r))
mockProvider.on('message', (r) => (responseEvents['message'] = r))
/// Emitimos eventos
mockProvider.delaySendMessage(0, 'require_action', MOCK_EVENTS.require_action)
mockProvider.delaySendMessage(0, 'ready', MOCK_EVENTS.ready)
mockProvider.delaySendMessage(0, 'auth_failure', MOCK_EVENTS.auth_failure)
mockProvider.delaySendMessage(0, 'message', MOCK_EVENTS.message)
await delay(0)
/// Testeamos eventos
assert.is(JSON.stringify(responseEvents.require_action), JSON.stringify(MOCK_EVENTS.require_action))
assert.is(responseEvents.ready, MOCK_EVENTS.ready)
assert.is(JSON.stringify(responseEvents.auth_failure), JSON.stringify(MOCK_EVENTS.auth_failure))
assert.is(JSON.stringify(responseEvents.message), JSON.stringify(MOCK_EVENTS.message))
})
test(`[Bot] Probando Flujos Internos`, async () => {
let responseEvents = {}
const MOCK_EVENTS = {
require_action: {
instructions: 'Debes...',
},
ready: true,
auth_failure: {
instructions: 'Error...',
},
message: {
from: 'XXXXXX',
body: 'hola',
hasMedia: false,
},
}
const mockProvider = new MockProvider()
const setting = {
flow: new MockFlow(),
database: new MockDBB(),
provider: mockProvider,
}
await createBot(setting)
/// Escuchamos eventos
mockProvider.on('require_action', (r) => (responseEvents['require_action'] = r))
mockProvider.on('ready', (r) => (responseEvents['ready'] = r))
mockProvider.on('auth_failure', (r) => (responseEvents['auth_failure'] = r))
mockProvider.on('message', (r) => (responseEvents['message'] = r))
/// Emitimos eventos
mockProvider.delaySendMessage(0, 'require_action', MOCK_EVENTS.require_action)
mockProvider.delaySendMessage(0, 'ready', MOCK_EVENTS.ready)
mockProvider.delaySendMessage(0, 'auth_failure', MOCK_EVENTS.auth_failure)
mockProvider.delaySendMessage(0, 'message', MOCK_EVENTS.message)
await delay(0)
/// Testeamos eventos
assert.is(JSON.stringify(responseEvents.require_action), JSON.stringify(MOCK_EVENTS.require_action))
assert.is(responseEvents.ready, MOCK_EVENTS.ready)
assert.is(JSON.stringify(responseEvents.auth_failure), JSON.stringify(MOCK_EVENTS.auth_failure))
assert.is(JSON.stringify(responseEvents.message), JSON.stringify(MOCK_EVENTS.message))
})
test(`[Bot] Probando Flujos Nested`, async () => {
let responseEvents = {}
const MOCK_EVENTS = {
require_action: {
instructions: 'Debes...',
},
ready: true,
auth_failure: {
instructions: 'Error...',
},
message: {
from: 'XXXXXX',
body: 'hola',
hasMedia: false,
},
}
const mockProvider = new MockProvider()
const setting = {
flow: new MockFlow(),
database: new MockDBC(),
provider: mockProvider,
}
const botInstance = await createBot(setting)
botInstance.sendProviderAndSave('xxxxx', 'xxxxx')
botInstance.continue('xxxxx', 'xxxxx')
/// Escuchamos eventos
mockProvider.on('require_action', (r) => (responseEvents['require_action'] = r))
mockProvider.on('ready', (r) => (responseEvents['ready'] = r))
mockProvider.on('auth_failure', (r) => (responseEvents['auth_failure'] = r))
mockProvider.on('message', (r) => (responseEvents['message'] = r))
/// Emitimos eventos
mockProvider.delaySendMessage(0, 'require_action', MOCK_EVENTS.require_action)
mockProvider.delaySendMessage(0, 'ready', MOCK_EVENTS.ready)
mockProvider.delaySendMessage(0, 'auth_failure', MOCK_EVENTS.auth_failure)
mockProvider.delaySendMessage(0, 'message', MOCK_EVENTS.message)
await delay(0)
/// Testeamos eventos
assert.is(JSON.stringify(responseEvents.require_action), JSON.stringify(MOCK_EVENTS.require_action))
assert.is(responseEvents.ready, MOCK_EVENTS.ready)
assert.is(JSON.stringify(responseEvents.auth_failure), JSON.stringify(MOCK_EVENTS.auth_failure))
assert.is(JSON.stringify(responseEvents.message), JSON.stringify(MOCK_EVENTS.message))
})
test.run()
function delay(ms) {
return new Promise((res) => setTimeout(res, ms))
}

View File

@@ -1,28 +0,0 @@
const { test } = require('uvu')
const assert = require('uvu/assert')
const FlowClass = require('../io/flow.class')
const { addKeyword } = require('../index')
test(`[FlowClass] Probando instanciamiento de clase`, async () => {
const MOCK_FLOW = addKeyword('hola').addAnswer('Buenas!')
const flowClass = new FlowClass([MOCK_FLOW])
assert.is(flowClass instanceof FlowClass, true)
})
test(`[FlowClass] Probando find`, async () => {
const MOCK_FLOW = addKeyword('hola').addAnswer('Buenas!')
const flowClass = new FlowClass([MOCK_FLOW])
flowClass.find('hola')
assert.is(flowClass instanceof FlowClass, true)
})
test(`[FlowClass] Probando findBySerialize`, async () => {
const MOCK_FLOW = addKeyword('hola').addAnswer('Buenas!')
const flowClass = new FlowClass([MOCK_FLOW])
flowClass.findBySerialize('')
assert.is(flowClass instanceof FlowClass, true)
})
test.run()

View File

@@ -1,153 +0,0 @@
const { test } = require('uvu')
const assert = require('uvu/assert')
const { generateRefSerialize } = require('../utils/hash')
const { addKeyword, addAnswer, toSerialize } = require('../io/methods')
test('Debere probar las propeidades', () => {
const ARRANGE = {
keyword: 'hola!',
}
const MAIN_CTX = addKeyword(ARRANGE.keyword)
assert.type(MAIN_CTX.addAnswer, 'function')
assert.is(MAIN_CTX.ctx.keyword, ARRANGE.keyword)
})
test('Debere probar las propeidades array', () => {
const ARRANGE = {
keyword: ['hola!', 'ole'],
}
const MAIN_CTX = addKeyword(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', () => {
const ARRANGE = {
keyword: ['hola!', 'ole'],
}
const MAIN_CTX = addKeyword(ARRANGE.keyword).addAnswer('Segundo!').addAnswer('Segundo!').toJson()
const [ANSWER_A] = MAIN_CTX
assert.is(
toSerialize(MAIN_CTX)[0].refSerialize,
generateRefSerialize({
index: 0,
answer: ANSWER_A.answer,
keyword: ANSWER_A.keyword,
})
)
})
test('Debere probar el paso de contexto', () => {
const ARRANGE = {
keyword: 'hola!',
answer: 'Bienvenido',
}
const CTX_A = addKeyword(ARRANGE.keyword)
const CTX_B = addAnswer(CTX_A)(ARRANGE.answer)
assert.is(CTX_A.ctx.keyword, ARRANGE.keyword)
assert.is(CTX_B.ctx.keyword, ARRANGE.keyword)
assert.is(CTX_B.ctx.answer, ARRANGE.answer)
})
test('Debere probar la anidación', () => {
const ARRANGE = {
keyword: 'hola!',
answer_A: 'Bienvenido',
answer_B: 'Continuar',
}
const MAIN_CTX = addKeyword(ARRANGE.keyword).addAnswer(ARRANGE.answer_A).addAnswer(ARRANGE.answer_B)
assert.is(MAIN_CTX.ctx.answer, ARRANGE.answer_B)
})
test('Debere probar las poptions', () => {
const MAIN_CTX = addKeyword('etc', { sensitive: false })
assert.is(MAIN_CTX.ctx.options.sensitive, false)
})
test('Debere probar las addAnswer', () => {
const MOCK_OPT = {
media: 'http://image.mock/mock.png',
buttons: [1],
}
const MAIN_CTX = addKeyword('hola').addAnswer('etc', MOCK_OPT)
assert.is(MAIN_CTX.ctx.options.media, MOCK_OPT.media)
assert.is(MAIN_CTX.ctx.options.buttons.length, 1)
})
test('Debere probar error las addAnswer', () => {
const MOCK_OPT = {
media: { a: 1, b: [] },
buttons: 'test',
}
const MAIN_CTX = addKeyword('hola').addAnswer('etc', MOCK_OPT)
assert.is(MAIN_CTX.ctx.options.media, null)
assert.is(MAIN_CTX.ctx.options.buttons.length, 0)
})
test('Obtener toJson', () => {
const [ctxA, ctxB, ctxC] = addKeyword('hola').addAnswer('pera!').addAnswer('chao').toJson()
assert.is(ctxA.keyword, 'hola')
assert.match(ctxA.ref, /^key_/)
assert.is(ctxB.answer, 'pera!')
assert.match(ctxB.ref, /^ans_/)
assert.is(ctxC.answer, 'chao')
assert.match(ctxC.ref, /^ans_/)
})
test('addKeyword toJson con sensitive', () => {
const [ctxA] = addKeyword('hola').toJson()
assert.is(ctxA.options.sensitive, false)
const [ctxB] = addKeyword('hola', { sensitive: true }).toJson()
assert.is(ctxB.options.sensitive, true)
})
test('addAnswer toJson con IMG', () => {
const [, ctxB, ctxC] = addKeyword('hola')
.addAnswer('bye!', {
media: 'http://mock.img/file-a.png',
})
.addAnswer('otro!', {
media: 'http://mock.img/file-b.png',
})
.toJson()
assert.is(ctxB.options.media, 'http://mock.img/file-a.png')
assert.is(ctxC.options.media, 'http://mock.img/file-b.png')
})
test('addAnswer toJson con BUTTONS', () => {
const [, ctxB] = addKeyword('hola')
.addAnswer('mis opciones!', {
buttons: [{ body: 'BTN_1' }, { body: 'BTN_2' }],
})
.toJson()
assert.is(ctxB.options.buttons.length, 2)
const [btnA, btnB] = ctxB.options.buttons
assert.is(btnA.body, 'BTN_1')
assert.is(btnB.body, 'BTN_2')
})
test.run()

View File

@@ -1,3 +0,0 @@
const delay = (miliseconds) => new Promise((res) => setTimeout(res, miliseconds))
module.exports = { delay }

View File

@@ -1,23 +0,0 @@
const flatObject = (listArray = []) => {
const cbNestedList = Array.isArray(listArray) ? listArray : []
if (!listArray.length) return {}
const cbNestedObj = cbNestedList.map(({ ctx }) => ctx?.callbacks).filter((i) => !!i)
const queueCb = cbNestedObj.reduce((acc, current) => {
const getKeys = Object.keys(current)
const parse = getKeys.map((icb, i) => ({
[icb]: Object.values(current)[i],
}))
return [...acc, ...parse]
}, [])
const flatObj = {}
for (const iteration of queueCb) {
const [keyCb] = Object.keys(iteration)
flatObj[keyCb] = iteration[keyCb]
}
return flatObj
}
module.exports = { flatObject }

View File

@@ -1,21 +0,0 @@
const crypto = require('crypto')
/**
* Generamos un UUID unico con posibilidad de tener un prefijo
* @param {*} prefix
* @returns
*/
const generateRef = (prefix = false) => {
const id = crypto.randomUUID()
return prefix ? `${prefix}_${id}` : id
}
/**
* Genera un HASH MD5
* @param {*} param0
* @returns
*/
const generateRefSerialize = ({ index, answer, keyword }) =>
crypto.createHash('md5').update(JSON.stringify({ index, answer, keyword })).digest('hex')
module.exports = { generateRef, generateRefSerialize }

View File

@@ -1,12 +0,0 @@
const { yellow, bgRed } = require('kleur')
const NODE_ENV = process.env.NODE_ENV || 'dev'
const printer = (message, title) => {
if (NODE_ENV !== 'test') {
// console.clear()
if (title) console.log(bgRed(`${title}`))
console.log(yellow(Array.isArray(message) ? message.join('\n') : message))
console.log(``)
}
}
module.exports = { printer }

Some files were not shown because too many files have changed in this diff Show More