Compare commits

...

349 Commits

Author SHA1 Message Date
Leifer Mendez
041bf6280e fix(adapter): 🚀 venom update - cli - qr iamge 2022-12-14 13:40:52 +01:00
Leifer Mendez
ca6afbb87f fix(adapter): 🚀 venom update - cli - qr iamge 2022-12-14 13:37:57 +01:00
Leifer Mendez
66f75f8722 feat(provider): new provider - venon configuracion inicial provi…
feat(provider): new provider - venon configuracion inicial provi…
2022-12-14 11:10:19 +01:00
Juan Daniel
31c83f5d68 feat(provider): solution error utils venom 2022-12-13 19:45:55 +01:00
Juan Daniel
1b83871cca feat(provider): solution error buttons 2022-12-13 19:44:41 +01:00
Juan Daniel
337c2e94bc feat(provider): added tamplate venom 2022-12-13 16:37:44 +01:00
Juan Daniel
01fe9ebc9a feat(provider): added new venom provider 2022-12-13 14:39:51 +01:00
Leifer Mendez
f799498dec Merge pull request #200 from cheveguerra/dev
fix: actualizar ejemplo app.js
2022-12-12 23:22:04 +01:00
17466138dd fix: actualizar app.js de ejemplo
Corrige saltos de linea inecesarios.
2022-12-12 16:15:49 -06:00
63ca8e8892 Merge branch 'leifermendez:dev' into dev 2022-12-12 15:10:18 -06:00
60fdbf3d3c fix: actualizar ejemplo app.js
Se agregan flujos secundarios al app,js de ejemplo.
2022-12-12 14:42:37 -06:00
Leifer Mendez
e8c249897d docs(info): update
Docs: Cambios en la documentación
2022-12-12 19:54:36 +01:00
55d12810d9 docs: cambios en docs 2022-12-12 12:43:45 -06:00
639e2defa7 docs: cambios en la documentacion 2022-12-12 12:41:01 -06:00
b97d8ba8f1 docs: pagina de entrada 2022-12-12 12:27:33 -06:00
Leifer Mendez
f05b76936a chore(release): 0.1.2
chore(release): 0.1.2
2022-12-12 18:18:34 +01:00
Leifer Mendez
0a4e1e052a chore(release): 0.1.2 2022-12-12 18:14:32 +01:00
github-actions[bot]
28d88c282c ci(version): automatic - "${date}" updated versions every packages 2022-12-12 17:13:21 +00:00
Leifer Mendez
a2be57f0aa fix(cli): 🎨 starters
fix(cli): 🎨 starters
2022-12-12 18:12:22 +01:00
Leifer Mendez
670ecf121b fix(cli): 🎨 starters
fix(cli): 🎨 starters
2022-12-12 18:11:41 +01:00
Leifer Mendez
79e2318256 fix(cli): 🎨 starters 2022-12-12 18:09:27 +01:00
Leifer Mendez
87ba43a553 fix(cli): 🎨 starters 2022-12-12 18:04:17 +01:00
Leifer Mendez
acc1d37e4f Merge remote-tracking branch 'origin/dev' into fix/create-script 2022-12-12 17:53:13 +01:00
github-actions[bot]
c578d039c0 ci(version): automatic - "${date}" updated versions every packages 2022-12-12 16:49:37 +00:00
Leifer Mendez
162067104e Merge pull request #195 from leifermendez/dev
Dev
2022-12-12 17:48:07 +01:00
Leifer Mendez
ea677b6eea Merge pull request #193 from cheveguerra/fix/starter-app
Fix/starter app
2022-12-12 17:43:15 +01:00
Leifer Mendez
a82b1cfb57 chore(release): 0.1.1
chore(release): 0.1.1
2022-12-12 17:40:59 +01:00
61d0324261 fix: fix dependencias
Se agregaron bot, cli, database y provider a las dependencias
2022-12-12 10:37:17 -06:00
Leifer Mendez
4d692e0a26 chore(release): 0.1.1 2022-12-12 17:35:51 +01:00
Leifer Mendez
9de7eada87 chore(release): 0.1.1 2022-12-12 17:25:04 +01:00
Leifer Mendez
8f81d995a4 chore(release): 0.1.1
chore(release): 0.1.1
2022-12-12 17:19:25 +01:00
Leifer Mendez
024f13691d chore(release): 0.1.1 2022-12-12 17:18:04 +01:00
Leifer Mendez
4aa91cb22a chore(release): 0.1.1
chore(release): 0.1.1
2022-12-12 17:12:51 +01:00
Leifer Mendez
9ecafe5fc8 chore(release): 0.1.1 2022-12-12 17:03:30 +01:00
Leifer Mendez
d039e2aacd chore(release): 0.3.0 2022-12-12 17:03:06 +01:00
Leifer Mendez
5173a6c467 chore(release): 0.2.1 2022-12-12 17:02:37 +01:00
Leifer Mendez
1d08682393 chore(release): 0.2.0 2022-12-12 17:01:41 +01:00
Leifer Mendez
0bb251b4d5 chore(release): 0.0.3 2022-12-12 17:00:43 +01:00
Leifer Mendez
04baa7f6fd chore(release): 0.2.0 2022-12-12 16:58:06 +01:00
Leifer Mendez
32212fb52d fix(cli): 🐛 path 2022-12-12 16:50:15 +01:00
Leifer Mendez
aa61a1e1b5 Merge branch 'dev' into fix/create-script 2022-12-12 16:47:55 +01:00
Leifer Mendez
5ecf9c6ba7 Merge branch 'fix/version' into dev 2022-12-12 15:13:02 +01:00
Leifer Mendez
d233cbac22 Merge remote-tracking branch 'origin/dev' into fix/version 2022-12-12 15:12:01 +01:00
github-actions[bot]
10098f018f ci(version): automatic - ${date} updated versions every packages 2022-12-12 14:02:54 +00:00
Leifer Mendez
70de13ef6a Merge pull request #190 from leifermendez/dev
action update
2022-12-12 15:00:24 +01:00
Leifer Mendez
f912fd328f Merge pull request #189 from leifermendez:fix/version
done ci
2022-12-12 14:56:31 +01:00
Leifer Mendez
6a86da2851 ci(ci): releases action 2022-12-12 14:55:40 +01:00
Leifer Mendez
1a2a246bf8 ci(ci): releases action
ci(ci):  releases action
2022-12-12 14:51:49 +01:00
Leifer Mendez
248d04b666 ci(ci): releases action 2022-12-12 14:50:45 +01:00
Leifer Mendez
41e96ad027 fix(ci): github action
fix(ci):  github action
2022-12-12 14:48:40 +01:00
Leifer Mendez
f2fd254d17 ci(ci): releases action
ci(ci):  releases action
2022-12-12 14:46:50 +01:00
Leifer Mendez
7790391b50 ci(ci): releases action 2022-12-12 14:43:38 +01:00
Leifer Mendez
b827a0ab22 fix(ci): github action
fix(ci):  github action
2022-12-12 14:37:15 +01:00
Leifer Mendez
4142ca4fd5 fix(ci): github action 2022-12-12 14:36:32 +01:00
Juan Daniel
fee7c2e967 feat(provider): new provider - venon configuracion inicial provider venom 2022-12-12 13:12:29 +01:00
Leifer Mendez
091544ac3f fix(ci): github action
fix(ci):  github action
2022-12-12 12:11:40 +01:00
Leifer Mendez
2ce342a0cb fix(ci): github action 2022-12-12 12:10:15 +01:00
Leifer Mendez
781779328f fix(ci): github action
fix(ci):  github action
2022-12-12 11:59:43 +01:00
Leifer Mendez
dfced8c594 fix(ci): github action 2022-12-12 11:59:09 +01:00
Leifer Mendez
aaa4ce8372 fix(ci): github action
fix(ci):  github action
2022-12-12 11:07:02 +01:00
Leifer Mendez
9ddf144244 fix(ci): github action 2022-12-12 11:06:25 +01:00
Leifer Mendez
b465de55a0 fix(ci): github action 2022-12-12 11:02:50 +01:00
Leifer Mendez
cf1dc6fac8 fix(ci): github action
fix(ci):  github action
2022-12-12 10:54:07 +01:00
Leifer Mendez
739c63d025 Merge branch 'fix/version' of github.com:leifermendez/bot-whatsapp into fix/version 2022-12-12 10:46:15 +01:00
Leifer Mendez
8d897f824e fix(ci): github action 2022-12-12 10:46:02 +01:00
Leifer Mendez
aad129ea94 Create FUNDING.yml 2022-12-12 00:31:06 +01:00
Leifer Mendez (githubaction)
e48b29ed29 ci(version): updated versions every packages 2022-12-11 21:35:22 +00:00
Leifer Mendez
c64560bfc3 ci(version): updated versions every packages
ci(version):  updated versions every packages
2022-12-11 22:31:51 +01:00
Leifer Mendez
255ba86506 ci(version): updated versions every packages 2022-12-11 22:31:21 +01:00
Leifer Mendez
cd2dad9d26 ci(version): updated versions every packages
ci(version):  updated versions every packages
2022-12-11 22:27:02 +01:00
Leifer Mendez
c7ff6b4794 ci(version): updated versions every packages 2022-12-11 22:26:29 +01:00
Leifer Mendez
628d55df37 ci(version): updated versions every packages
ci(version):  updated versions every packages
2022-12-11 22:18:46 +01:00
Leifer Mendez
0059a1e7fb ci(version): updated versions every packages 2022-12-11 22:18:01 +01:00
Leifer Mendez
73ea7c0063 ci(version): updated versions every packages 2022-12-11 22:16:09 +01:00
Leifer Mendez
cb9f4befa0 fix/version
fix/version
2022-12-11 22:11:24 +01:00
Leifer Mendez
decccb672a ci(ci): push 2022-12-11 22:10:42 +01:00
Leifer Mendez
51466bf1c7 ci(ci): push 2022-12-11 22:09:29 +01:00
Leifer Mendez
397798790e feat(cli): create-starter
feat(cli): create-starter
2022-12-11 22:00:53 +01:00
Leifer Mendez
d3b8310180 fix(cli): create-starter 2022-12-11 21:58:13 +01:00
Leifer Mendez
7797c2b461 fix(cli): update cli copy 2022-12-11 20:59:28 +01:00
Leifer Mendez
929e74c84b fix(starter): pre-copy fix
pre-copy fix
2022-12-11 13:46:52 +01:00
08e2552907 fix: pre-copy fix 2022-12-11 05:55:31 -06:00
6617107ab8 fix: pre-copy fix 2022-12-11 05:48:51 -06:00
Leifer Mendez
8921959ea0 Merge pull request #165 from leifermendez:fix/version
fix(ci):  balance version
2022-12-10 21:49:33 +01:00
Leifer Mendez
ec46cfdd65 fix(ci): balance version 2022-12-10 21:48:55 +01:00
Leifer Mendez
bfb69d9a95 fix(cli): clean eslinter
fix(cli):  clean eslinter
2022-12-10 21:40:20 +01:00
Leifer Mendez
15f6972257 fix(cli): clean eslinter 2022-12-10 21:38:23 +01:00
Leifer Mendez
2319db3009 fix(cli): 🔥 create script - templates
fix(cli): 🔥 create script - templates
2022-12-10 21:33:07 +01:00
Leifer Mendez
9cb98b5e73 fix(cli): 🔥 create script - templates 2022-12-10 21:27:58 +01:00
Leifer Mendez
2999e0e753 fix(cli): 🔥 create script - templates
fix(cli): 🔥 create script - templates
2022-12-10 21:22:48 +01:00
Leifer Mendez
af716b7537 fix(cli): 🔥 create script - templates 2022-12-10 21:20:57 +01:00
Leifer Mendez
c6999c8493 fix(cli): 🔥 create script - templates
fix(cli): 🔥 create script - templates
2022-12-10 21:20:07 +01:00
Leifer Mendez
d4b49a9bd7 fix(cli): 🔥 create script - templates 2022-12-10 21:19:38 +01:00
Leifer Mendez
eebc3c9806 fix(cli): 🔥 create script - templates 2022-12-10 21:17:29 +01:00
Leifer Mendez
257f1cc12d ci(ci): update ci
ci(ci):  update ci
2022-12-09 15:00:05 +01:00
Leifer Mendez
1036273a28 ci(ci): update ci 2022-12-09 14:59:21 +01:00
Leifer Mendez
1b8ed93367 ci(ci): update ci
ci(ci):  update ci
2022-12-09 14:18:06 +01:00
Leifer Mendez
8c1820c879 ci(ci): update ci 2022-12-09 14:17:26 +01:00
Leifer Mendez
e5a9db7e12 feat(ci): update ci
feat(ci): update ci
2022-12-09 14:13:43 +01:00
Leifer Mendez
9d5aa7db5d ci(ci): update ci 2022-12-09 14:12:38 +01:00
Leifer Mendez
40b0d9691e chore(ci): script releases 2022-12-09 13:50:01 +01:00
Leifer Mendez
2e906bce79 feat(ci): 🎨 relases script 2022-12-09 12:17:29 +01:00
Leifer Mendez
f05ff4cf88 style: ✏️ fixed typos
style: ✏️ fixed typos
2022-12-08 22:48:12 +01:00
Leifer Mendez
5735b49e25 Merge pull request #155 from leifermendez/feat/releases
feat(release): added
2022-12-08 22:23:03 +01:00
Leifer Mendez
1988948c30 feat(release): added 2022-12-08 22:22:04 +01:00
Leifer Mendez
cb33c0df68 Merge pull request #154 from leifermendez/feat/releases
feat(relases): added
2022-12-08 22:19:25 +01:00
Leifer Mendez
f4ad7040ab feat(release): added 2022-12-08 22:15:46 +01:00
Leifer Mendez
b115dc3654 feat(ci): 🎨 add releases 2022-12-08 21:56:34 +01:00
6rak0
8c6023e93b style: ✏️ fixed typos
fixed typos
2022-12-08 14:34:41 -06:00
Leifer Mendez
5d7c297f2f Merge pull request #150 from leifermendez/fix/ci-yarn
ci(action): update
2022-12-08 20:17:46 +01:00
Leifer Mendez
04f99d5ed2 ci(action): update 2022-12-08 20:16:31 +01:00
Leifer Mendez
bb3f21b056 Merge pull request #149 from leifermendez/fix/ci-yarn
fix(ci): update yarn
2022-12-08 20:13:02 +01:00
Leifer Mendez
cf6188d860 ci(action): update 2022-12-08 20:12:11 +01:00
Leifer Mendez
294bfbb35f ci(action): update 2022-12-08 20:11:33 +01:00
github-actions[bot]
230538bcea docs(contributor): contrib-readme-action has updated readme 2022-12-07 22:43:36 +00:00
Leifer Mendez
5e7aa72494 Merge pull request #138 from vicente1992/feat-jsonfile-adapter
feat(adapter): implementation of json file adapter
2022-12-07 23:43:21 +01:00
vicente1992
3159ea5665 Merge branch 'dev' of https://github.com/vicente1992/bot-whatsapp into feat-jsonfile-adapter 2022-12-07 17:18:36 -05:00
vicente1992
4b307efe79 fix(adapter): conflict resolution 2022-12-07 17:14:16 -05:00
github-actions[bot]
0105dab2c4 docs(contributor): contrib-readme-action has updated readme 2022-12-07 22:10:34 +00:00
github-actions[bot]
6e8e16c9a4 docs(contributor): contrib-readme-action has updated readme 2022-12-07 20:33:21 +00:00
Leifer Mendez
8d73c86946 feat(adapter): mysql adapter
feat(adapter): mysql adapter
2022-12-07 21:33:05 +01:00
Leifer Mendez
a7b19d9bff fix(bot): flow improvement + add utils 2022-12-07 21:29:48 +01:00
vicente1992
4b7de0f690 feat(adapter): sql is added to create the table 2022-12-07 15:07:38 -05:00
github-actions[bot]
520145bf7d docs(contributor): contrib-readme-action has updated readme 2022-12-07 19:54:07 +00:00
Leifer Mendez
2253d57fed Merge branch 'dev' of github.com:leifermendez/bot-whatsapp into dev 2022-12-07 18:13:00 +01:00
Leifer Mendez
0fb93f66a3 Merge branch 'fix/webwhatsapp' into dev 2022-12-07 18:12:45 +01:00
Leifer Mendez
501887300d Merge branch 'fix/delay-message' into dev 2022-12-07 18:11:49 +01:00
Leifer Mendez
14b6247106 Merge pull request #137 from vicente1992/feat-mysql-adapter
feat(adapter): added adapter mysql
2022-12-07 18:09:13 +01:00
Leifer Mendez
eda8a67718 refactor(provider): twilio + hook 2022-12-07 18:06:27 +01:00
Leifer Mendez
73caf090ba fix(bot): added delay promises 2022-12-07 16:20:56 +01:00
vicente1992
afa6771903 fix(adapter): corrections are made to the adapter 2022-12-06 15:48:25 -05:00
Leifer Mendez
8dd3be909b feat(provider): added twilio provider 2022-12-06 21:28:52 +01:00
github-actions[bot]
88af2469cb docs(contributor): contrib-readme-action has updated readme 2022-12-06 18:36:55 +00:00
Leifer Mendez
999d6742b4 Merge pull request #141 from leifermendez:feature/twilio
Feature/twilio
2022-12-06 19:36:42 +01:00
Leifer Mendez
24ac9fbf48 fix(bot): fix sensitive case 2022-12-06 19:35:21 +01:00
Leifer Mendez
4350dff22a feat(provider): 🔥 add twilii (weoking) 2022-12-05 20:45:05 +01:00
github-actions[bot]
30e3d443bb docs(contributor): contrib-readme-action has updated readme 2022-12-05 15:47:15 +00:00
Leifer Mendez
f5ea7fe2c4 Merge branch 'dev' of github.com:leifermendez/bot-whatsapp into dev 2022-12-05 16:46:47 +01:00
Leifer Mendez
94d139e484 ci(contributors): add username avatar 2022-12-05 16:46:29 +01:00
github-actions[bot]
8049241f3f docs(contributor): contrib-readme-action has updated readme 2022-12-05 15:45:01 +00:00
Leifer Mendez
28d308ed4b ci(contributors): add username avatar 2022-12-05 16:44:36 +01:00
Leifer Mendez
e0862053d0 Merge branch 'feature/fallback' into dev 2022-12-05 16:35:05 +01:00
Leifer Mendez
e0e76d3a56 ci(contributors): add username avatar 2022-12-05 16:33:22 +01:00
Leifer Mendez
242e44315b Merge pull request #139 from leifermendez/feature/fallback
Feature/fallback
2022-12-05 16:32:02 +01:00
Leifer Mendez
6b53ed13e2 docs(contributors): add username avatar 2022-12-05 16:15:21 +01:00
Leifer Mendez
fafccbcecc Merge commit 'f2533f1ed5c0078be59938720f2ecf96c616b843' into feature/fallback 2022-12-05 16:05:49 +01:00
Leifer Mendez
49698bfda9 fix(bot): update 2022-12-05 16:02:23 +01:00
Leifer Mendez
4154cc2230 feat(bot): 🔥 improvement provider handler 2022-12-05 14:49:23 +01:00
Leifer Mendez
ce8a96b958 feat(bot): add send image function 2022-12-05 13:01:32 +01:00
Leifer Mendez
f373a3abc7 chore(bot): fallback done 2022-12-05 09:59:40 +01:00
Leifer Mendez
371ee0a780 chore(bot): update fallback function 2022-12-04 16:01:52 +01:00
Leifer Mendez
327cf5730b Merge pull request #137 from vicente1992/feat-mysql-adapter
feat(adapter): added adapter mysql
2022-12-03 12:06:03 +01:00
vicente1992
5e1a373730 feat(adapter): implementation of json file adapter 2022-12-02 22:27:31 -05:00
vicente1992
717a7dc95f feat(adapter): added adapter mysql 2022-12-02 09:41:57 -05:00
Leifer Mendez
aa2417af12 chore(bot): added new fallback option 2022-12-02 15:22:13 +01:00
Leifer Mendez
f2533f1ed5 Merge pull request #136 from leifermendez/feature/monorepo
docs(contributing):  update
2022-12-01 21:34:54 +01:00
Leifer Mendez
7d41699207 docs(contributing): update 2022-12-01 21:33:50 +01:00
Leifer Mendez
f9ccfef8e0 Merge pull request #135 from leifermendez/feature/monorepo
chore(cli): 🔥 fix
2022-12-01 21:07:48 +01:00
Leifer Mendez
468a2ba251 chore(cli): 🔥 fix 2022-12-01 21:07:00 +01:00
Leifer Mendez
08dbdcf4ae Merge pull request #134 from leifermendez/feature/monorepo
chore(cli): 🎨 remove uneccesary steps
2022-12-01 20:59:57 +01:00
Leifer Mendez
50d73f7bc8 chore(cli): 🎨 remove uneccesary steps 2022-12-01 20:58:58 +01:00
Leifer Mendez
d7ed9ff592 Merge pull request #133 from leifermendez/feature/monorepo
chore(cli):  added new function
2022-12-01 20:45:34 +01:00
Leifer Mendez
05c6fd4528 chore(cli): added new function 2022-12-01 20:44:12 +01:00
Leifer Mendez
a99f424901 Merge pull request #132 from leifermendez/feature/monorepo
Feature/monorepo
2022-12-01 18:43:03 +01:00
Leifer Mendez
648354500b fix(fix): fix 2022-12-01 18:42:18 +01:00
Leifer Mendez
28c0480b8b fix(fix): fix 2022-12-01 18:39:49 +01:00
Leifer Mendez
f29ed6e29b Merge pull request #131 from leifermendez/feature/monorepo
Merge pull request #130 from leifermendez/dev
2022-12-01 18:38:03 +01:00
Leifer Mendez
903b4d79ac docs(contributing): 📝 added more example 2022-12-01 18:17:19 +01:00
Leifer Mendez
026c189901 Merge pull request #130 from leifermendez/dev
Dev
2022-12-01 12:52:46 +01:00
Leifer
f2b30ee349 docs: 📝 update CONTRIBUTING 2022-12-01 12:46:49 +01:00
Leifer
5c02a9325a chore(release): 0.2.0-alpha.0 2022-12-01 12:38:17 +01:00
Leifer
7645c8642f test 2022-12-01 12:33:18 +01:00
Leifer
c5ebbe319f refactor(hook): added new improvement 2022-12-01 12:32:45 +01:00
Leifer
6f36eb1690 test 2022-12-01 10:35:41 +01:00
Leifer
18f9e006a3 test 2022-12-01 10:34:30 +01:00
Leifer
a7e334ebe9 add banner 2022-12-01 10:27:18 +01:00
Leifer
a5e15d9d84 edit hook 2022-12-01 10:17:19 +01:00
Leifer
b3173517b4 add pretty-quick 2022-12-01 10:16:06 +01:00
Leifer Mendez
06d2963163 Merge pull request #129 from leifermendez/feature/monorepo
Feature/monorepo
2022-12-01 09:53:28 +01:00
Leifer Mendez
df8282015d docs(example-app): add cli crate app 2022-11-30 21:39:30 +01:00
Leifer Mendez
81b0aab850 refactor(io): added new method addChild 2022-11-30 21:06:26 +01:00
Leifer Mendez
a8705c5b44 refactor(io): added new method addChild 2022-11-30 21:05:32 +01:00
Leifer Mendez
efe739f9fc refactor(io): added new method addChild 2022-11-30 21:04:45 +01:00
Leifer Mendez
2e83a0508a docs(contribuiting): update 2022-11-30 17:14:50 +01:00
Leifer Mendez
d66adb2a1f Merge pull request #126 from leifermendez/feature/monorepo
Feature/monorepo
2022-11-29 22:14:56 +01:00
Leifer
e5cecdee03 docs(contributin): added more info 2022-11-29 22:13:58 +01:00
Leifer
9351af16b7 docs(contributing): added more info 2022-11-29 22:04:46 +01:00
Leifer
ad8831a75a f 2022-11-29 22:00:05 +01:00
Leifer
c63018ff08 f 2022-11-29 21:55:39 +01:00
Leifer
131bce3898 . 2022-11-29 21:45:44 +01:00
Leifer
fff9316030 . 2022-11-29 21:44:04 +01:00
Leifer
2b3148dc3c update documenta 2022-11-29 21:43:11 +01:00
Leifer Mendez
13a4202f08 docs(contributing): added main readme 2022-11-29 11:33:33 +01:00
Leifer Mendez
f0df143aaf Merge pull request #125 from leifermendez/feature/monorepo
Feature/monorepo
2022-11-29 11:23:07 +01:00
Leifer Mendez
70a94ab2c6 fix(linter): update linter and commitlint 2022-11-29 10:47:12 +01:00
Leifer Mendez
e6d18d1a72 chore(release): 0.1.1 2022-11-29 10:36:23 +01:00
Leifer Mendez
46cd57fb36 chore(release): 0.1.0 2022-11-29 10:33:25 +01:00
Leifer Mendez
4ae389846d feat: (🎸) add onClick prop to component 2022-11-29 10:22:37 +01:00
Leifer Mendez
37d04e9e89 test: (💍) Is justa test!
nothing

BREAKING CHANGE: 🧨 NO
2022-11-29 10:17:32 +01:00
Leifer Mendez
39d141ca67 refactor: (💡) change emoji 2022-11-28 21:20:48 +01:00
Leifer Mendez
befcc169e0 refactor: 💡 pkgmanager
Upgrade Yarn v3
2022-11-28 21:19:00 +01:00
Leifer Mendez
6bbb9c1b81 docs(main documentation): es una mejora 2022-11-28 19:44:20 +01:00
Leifer Mendez
bb77afc4d2 test 2022-11-28 19:40:53 +01:00
Leifer Mendez
b43697fd68 docs(mocks): add mock 2022-11-28 19:02:40 +01:00
Leifer Mendez
86eebbead6 docs(example): example bot 2022-11-28 19:01:03 +01:00
Leifer Mendez
7463b8badc refactor(ci): Remove CI post doc 2022-11-28 17:01:18 +01:00
Leifer Mendez
37e857f093 refactor(husky): improved Husky 2022-11-28 16:53:05 +01:00
Leifer Mendez
2db240b32e ♻️ 2022-11-28 16:43:12 +01:00
Leifer Mendez
3c5f6031e1 ♻️ (husky) 2022-11-28 16:42:28 +01:00
Leifer Mendez
b25fee0d86 update husky 2022-11-28 16:35:09 +01:00
Leifer Mendez
a6ee58ff28 fix 2022-11-28 16:32:12 +01:00
Leifer Mendez
fdb083f2a3 test 2022-11-28 16:30:48 +01:00
Leifer Mendez
ee32a35a42 change 2022-11-28 16:01:33 +01:00
Leifer Mendez
d17b41da38 update 2022-11-28 15:55:37 +01:00
Leifer Mendez
870184b2a5 add video 2022-11-28 15:51:32 +01:00
Leifer Mendez
e787691efc docs(docs): update doc 2022-11-28 14:44:44 +01:00
Leifer Mendez
859716e6c7 test 2022-11-28 14:42:48 +01:00
Leifer Mendez
aab91b3842 docs(clean): clean 2022-11-28 14:06:01 +01:00
Leifer Mendez
f9dd0a6b03 docs(docs website): docwebsite 2022-11-28 13:56:39 +01:00
Leifer Mendez
f55cfae6e4 fix(ci): ci 2022-11-28 13:05:50 +01:00
Leifer Mendez
671c5b37f3 fix(ci): ci 2022-11-28 12:59:56 +01:00
Leifer Mendez
46c4ec7ab9 docs(websitedoc): added new website 2022-11-28 12:55:30 +01:00
Leifer Mendez
1856bd5022 style: added commitizen flag 2022-11-28 12:10:06 +01:00
Leifer Mendez
21cfc498e8 docs: doc 2022-11-28 12:05:09 +01:00
Leifer Mendez
ec7007071e update ci 2022-11-28 11:54:22 +01:00
Leifer Mendez
e33509789c update ci 2022-11-28 11:53:35 +01:00
Leifer Mendez
9fddcef271 update ci 2022-11-28 11:51:40 +01:00
Leifer Mendez
d2acb641c5 increase 95% coverage 2022-11-28 11:49:28 +01:00
Leifer Mendez
82a6b634a9 increase 95% coverage 2022-11-28 11:48:25 +01:00
Leifer Mendez
f466b0cf7b added video to explain 2022-11-28 10:31:44 +01:00
Leifer Mendez
b3f6fc852b added video to explain 2022-11-28 10:29:30 +01:00
Leifer Mendez
976d892061 added video to explain 2022-11-28 10:13:01 +01:00
Leifer Mendez
2a0a9e79da added video to explain 2022-11-28 10:11:10 +01:00
Leifer Mendez
8d24093aec added mor doc 2022-11-28 09:52:17 +01:00
Leifer Mendez
c6b23d353a add todo 2022-11-24 16:54:07 +01:00
Leifer Mendez
b6a21b9c12 Sensitive case 2022-11-24 14:52:57 +01:00
Leifer Mendez
14fbae3c86 Increase Coverage 2022-11-23 23:16:54 +01:00
Leifer Mendez
1dd88d117d test pass ok 2022-11-23 21:00:25 +01:00
Leifer Mendez
f6d70b4f7d working child flow 2022-11-23 20:56:17 +01:00
Leifer Mendez
368bf29e63 almost work it 2022-11-22 21:45:00 +01:00
Leifer Mendez
c40c0c54bd nothing 2022-11-19 21:17:18 +01:00
Leifer Mendez
0c850d47d7 removed ctx 2022-11-19 21:09:26 +01:00
Leifer Mendez
4879df040f i need remove ctx stranger 2022-11-19 21:07:41 +01:00
Leifer Mendez
7cf013e52b Next 2022-11-18 20:05:11 +01:00
Leifer Mendez
4e0a1a59e0 . 2022-11-18 19:56:50 +01:00
Leifer Mendez
6953c954a8 restore flow working! 2022-11-18 19:55:57 +01:00
Leifer Mendez
e3664cc973 . 2022-11-18 18:38:05 +01:00
Leifer Mendez
417d938677 . 2022-11-18 18:37:25 +01:00
Leifer Mendez
2042abb045 . 2022-11-18 18:36:03 +01:00
Leifer Mendez
0f5efa9852 . 2022-11-18 18:35:49 +01:00
Leifer Mendez
76968ded02 UUID memory without relation UUID DB 2022-11-16 23:16:54 +01:00
Leifer Mendez
ce8e7be9d7 mongo adapter:next step, continue conversation from db 2022-11-16 20:41:36 +01:00
Leifer Mendez
1290d6b478 next save conversation 2022-11-15 20:47:12 +01:00
Leifer Mendez
a5c38658a8 work flow 2022-11-15 19:52:57 +01:00
Leifer Mendez
5797beb0ca improve 2022-11-14 20:52:38 +01:00
Leifer Mendez
9178bc083e fix rollup 2022-11-14 19:44:58 +01:00
Leifer Mendez
878840fc06 must split adapter 2022-11-13 20:06:22 +01:00
Leifer Mendez
716f0587c3 issue rollup 2022-11-13 15:13:05 +01:00
Leifer Mendez
03eed5131a move io into bot 2022-11-13 14:41:25 +01:00
Leifer Mendez
3946c88ed7 rename core to bot 2022-11-13 14:18:20 +01:00
Leifer Mendez
59182f20f3 Test (core) OK 2022-11-13 14:08:33 +01:00
Leifer Mendez
a20b128ee8 working pkgs 2022-11-11 20:28:49 +01:00
Leifer Mendez
1edd9ab371 working ws provider 2022-11-11 17:56:35 +01:00
Leifer Mendez
da8defc517 test and work 2022-11-11 15:10:34 +01:00
Leifer Mendez
45272fb34f test pass 2022-11-11 13:31:43 +01:00
Leifer Mendez
a8dc44b41e working 2022-11-11 12:12:19 +01:00
Leifer Mendez
1954a5a90a issue 2022-11-10 22:59:08 +01:00
Leifer Mendez
228530a454 continue 2022-11-10 21:16:22 +01:00
Leifer Mendez
4216cdd1e5 . 2022-11-10 20:17:38 +01:00
Leifer Mendez
6afb019f9d web-whatsapp work 2022-11-10 20:17:07 +01:00
Leifer Mendez
8410309e38 continue 2022-11-09 20:07:52 +01:00
Leifer Mendez
ceb6faa5af fix 2022-11-09 13:23:07 +01:00
Leifer Mendez
9de4777cdb pass test 2022-11-09 12:52:45 +01:00
Leifer Mendez
83df967247 adapter provider 2022-11-09 12:42:01 +01:00
Leifer Mendez
39e2356feb extends conditional class 2022-11-09 12:28:20 +01:00
Leifer Mendez
24484015b3 before lerna 2022-11-09 11:27:01 +01:00
Leifer Mendez
30e7b220cd update 2022-11-08 21:46:41 +01:00
Leifer Mendez
576092fc96 . 2022-11-08 21:41:16 +01:00
Leifer Mendez
2114800b84 mock BotClass 2022-11-08 19:17:28 +01:00
Leifer Mendez
d9492eeee6 add class 2022-11-08 15:46:38 +01:00
Leifer Mendez
2442b59a5f example bot 2022-11-05 11:44:43 +01:00
Leifer Mendez
1c01e27a65 add method 2022-11-05 11:32:08 +01:00
Leifer Mendez
0a9b1907d7 fix 2022-11-05 11:24:22 +01:00
Leifer Mendez
0a9e14c460 toJson 2022-11-02 21:10:18 +01:00
Leifer Mendez
33797ce9de add c8 coverage 2022-11-02 20:26:56 +01:00
Leifer Mendez
97ff1402f8 add c8 coverage 2022-11-02 20:24:26 +01:00
Leifer Mendez
5fa6660afd add answer options 2022-11-02 20:15:14 +01:00
Leifer Mendez
c05470c045 update 2022-10-29 20:17:01 +02:00
Leifer Mendez
e24e648e07 update 2022-10-29 20:15:00 +02:00
Leifer Mendez
a4d51304b9 update 2022-10-29 20:14:18 +02:00
Leifer Mendez
4210214735 update 2022-10-29 20:13:15 +02:00
Leifer Mendez
403dea665d update 2022-10-29 20:12:08 +02:00
Leifer Mendez
5704300d75 update 2022-10-29 20:10:39 +02:00
Leifer Mendez
deb238d423 update 2022-10-29 19:21:00 +02:00
Leifer Mendez
b678041e68 update 2022-10-29 19:17:33 +02:00
Leifer Mendez
df5fe085a8 update 2022-10-29 19:15:39 +02:00
Leifer Mendez
46ee2c6dd0 ci 2022-10-29 19:12:27 +02:00
Leifer Mendez
eccbe59a1a ci 2022-10-29 19:11:44 +02:00
Leifer Mendez
3e2869b54a unit test methods 2022-10-29 18:11:55 +02:00
Leifer Mendez
96b8a7626c uvu test:io 2022-10-29 14:47:42 +02:00
Leifer Mendez
7593d6e564 rollup 2022-10-29 13:18:20 +02:00
Leifer Mendez
e00aacfe3e io improvement 2022-10-29 13:07:58 +02:00
Leifer Mendez
860c2bc8fb Merge branch 'feature/monorepo' of github.com:leifermendez/bot-whatsapp into feature/monorepo 2022-10-29 12:16:21 +02:00
Leifer Mendez
710f1b9f90 before 2022-10-29 12:16:16 +02:00
Leifer
4e87ca790e ... 2022-10-29 12:15:54 +02:00
Leifer
5974f3c9f2 ... 2022-10-29 12:15:05 +02:00
Leifer Mendez
62f1b7eb88 fix dependencies 2022-10-28 20:53:32 +02:00
Leifer
1e9574e740 TODO provider 2022-10-27 14:04:29 +02:00
Leifer
b6207ba447 readme inout 2022-10-27 14:00:36 +02:00
Leifer
7fe2611aed continue 2022-10-27 11:21:11 +02:00
Leifer
860bd8539f generate json file 2022-10-27 11:10:04 +02:00
Leifer
ceade85334 add validation cli 2022-10-25 13:43:17 +02:00
Leifer
5dc81f60c0 cli update 2022-10-24 17:55:07 +02:00
Leifer
40b08622ec monorepo/cli 2022-10-24 14:37:20 +02:00
Leifer
a12d5dbb78 first 2022-10-24 13:22:12 +02:00
Leifer
663fcafc9c update 2022-10-24 09:39:38 +02:00
Leifer
f36ddd3014 update 2022-10-20 13:51:43 +02:00
Leifer Mendez
3fadaaaf13 Merge pull request #82 from Gonzalito87/patch-7
Update de librerias
2022-08-09 20:57:57 +02:00
Leifer Mendez
dfa569f29d Merge pull request #83 from aurik3/dev-pull
coreccion nanoid y send.js
2022-08-09 20:57:41 +02:00
Leifer Mendez
601508f379 Merge branch 'main' into dev-pull 2022-08-09 20:57:29 +02:00
aurik3
e7ad205268 coreccion nanoid y send.js
se corrigen errores en el codigo
2022-08-09 13:43:28 -05:00
Gonzalito87
f62ba0a076 Update de librerias 2022-08-08 15:19:13 -03:00
Leifer Mendez
a9efa0aa58 Merge pull request #71 from ulisesvina/main
Arreglado: comprobación de parámetros en funciones y problemas de inconsistencia.
2022-08-08 14:47:33 +02:00
Leifer Mendez
3276c21bc3 Merge pull request #75 from aurik3/dev-pull
Update Julio 2022
2022-07-22 12:57:14 +02:00
aurik3
1114f25a71 Update Julio 2022
Se añade localAuth para mantener la session despues de escanear el codigo y se hace un code fix al api rest

Co-Authored-By: Leifer Mendez <15802366+leifermendez@users.noreply.github.com>
2022-07-19 18:15:12 -05:00
Ulises Viña
f13a34ff75 Update send.js 2022-07-05 20:59:06 -05:00
Leifer Mendez
d45ea85e7d Merge pull request #57 from leifermendez/rev-global
rex
2022-04-27 21:33:51 +02:00
Leifer Mendez
10e2b138d3 rex 2022-04-27 21:32:29 +02:00
Leifer Mendez
a1bf5ba5c2 Merge pull request #55 from Gonzalito87/patch-3
Update package.json
2022-04-27 21:03:06 +02:00
Gonzalito87
19102b7b3a Update package.json
actualizacion de repositorio de whats app
2022-04-26 11:12:35 -03:00
Leifer Mendez
5efcc2a9a6 Merge pull request #54 from Gonzalito87/patch-1
Update diaglogflow.js
2022-04-25 19:33:28 +02:00
Gonzalito87
8279c07a88 Update diaglogflow.js 2022-04-25 13:42:12 -03:00
Leifer Mendez
02d7b3bd98 Merge pull request #50 from leifermendez/update
Update
2022-04-20 14:17:02 +02:00
Leifer Mendez
f8f6a3000d Merge branch 'update' of github.com:leifermendez/bot-whatsapp into update 2022-04-20 14:16:46 +02:00
Leifer Mendez
9a92b152a4 fix 2022-04-20 14:16:42 +02:00
Leifer Mendez
f86700deaf Update README.md 2022-04-15 12:03:22 +02:00
Leifer Mendez
4ba259b46c Update README.md 2022-04-15 12:02:59 +02:00
Leifer Mendez
cf459e94d2 Update README.md 2022-04-15 12:01:29 +02:00
Leifer Mendez
4f8ed1361c Merge pull request #47 from leifermendez/update
Update
2022-04-15 12:00:43 +02:00
Leifer Mendez
bad8802241 Merge branch 'main' into update 2022-04-15 12:00:37 +02:00
Leifer Mendez
f09ac862d5 clean credentials 2022-04-15 11:58:09 +02:00
Leifer Mendez
fe7567e1a9 update many stuff 2022-04-15 11:57:32 +02:00
Leifer Mendez
9b0b7f4d54 befor update 2022-04-15 11:02:12 +02:00
Leifer Mendez
3ddbf462a8 Update package.json 2022-03-29 17:02:09 +02:00
Leifer Mendez
e6043c99a7 Merge pull request #35 from leifermendez/dev
update
2022-03-23 09:41:38 +01:00
Leifer Mendez
b1daa0020e update 2022-03-23 09:41:18 +01:00
Leifer Mendez
190d35c9a5 Merge pull request #30 from leifermendez/dev
Dev
2022-03-16 10:05:54 +01:00
Leifer Mendez
e4378fe848 se agego multi-device .env 2022-03-16 10:05:13 +01:00
Leifer Mendez
676e48021f Merge pull request #28 from leifermendez/dev
Dev
2022-03-15 10:22:38 +01:00
195 changed files with 24993 additions and 4955 deletions

8
.c8rc.json Normal file
View File

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

View File

@@ -1,11 +0,0 @@
######DATABASE: none, mysql, dialogflow
DEFAULT_MESSAGE=true
SAVE_MEDIA=true
PORT=3000
DATABASE=none
LANGUAGE=es
SQL_HOST=
SQL_USER=
SQL_PASS=
SQL_DATABASE=

1
.eslintignore Normal file
View File

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

18
.eslintrc.js Normal file
View File

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

9
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1,9 @@
# These are supported funding model platforms
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: leifermendez
open_collective: bot-whatsapp
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
custom: https://www.buymeacoffee.com/leifermendez

58
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,58 @@
name: BotWhatsapp Build-Test
on:
pull_request:
branches:
- dev
jobs:
############ BUILD PACKAGE ############
build-package:
name: Build Package
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: Build Package
run: yarn build
- 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

19
.github/workflows/contributors.yml vendored Normal file
View File

@@ -0,0 +1,19 @@
name: Add contributors
on:
pull_request:
branches:
- dev
- main
types: [closed]
jobs:
contrib-readme-job:
runs-on: ubuntu-latest
name: A job to automate contrib in readme
steps:
- name: Contribute List
uses: akhilmhdh/contributors-readme-action@v2.3.6
with:
image_size: 50
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

56
.github/workflows/releases-dev.yml vendored Normal file
View File

@@ -0,0 +1,56 @@
name: BotWhatsapp Releases(DEV)
on:
push:
branches:
- next-release
jobs:
############ RELEASE ############
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
persist-credentials: false
fetch-depth: 0
- 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
- 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: Commit Versioning & Push changes
uses: actions-js/push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
message: 'ci(version): :zap: automatic - "${date}" updated versions every packages'
branch: 'dev'

60
.github/workflows/releases.yml vendored Normal file
View File

@@ -0,0 +1,60 @@
name: BotWhatsapp Releases(Prod)
on:
push:
tags:
- 'v*.*.*'
jobs:
############ RELEASE ############
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
persist-credentials: false
fetch-depth: 0
- 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: Install NPM Dependencies
run: yarn install --immutable --network-timeout 300000
- name: Build Package
run: yarn build
- name: Release @bot-whatsapp/bot
run: yarn node ./scripts/release.js --name=bot --version="${{ steps.vars.outputs.tag }}" --token="${{ secrets.NPM_TOKEN }}"
- name: Release @bot-whatsapp/cli
run: yarn node ./scripts/release.js --name=cli --version="${{ steps.vars.outputs.tag }}" --token="${{ secrets.NPM_TOKEN }}"
- name: Release @bot-whatsapp/create-bot-whatsapp
run: yarn node ./scripts/release.js --name=create-bot-whatsapp --version="${{ steps.vars.outputs.tag }}" --token="${{ secrets.NPM_TOKEN }}"
- name: Release @bot-whatsapp/database
run: yarn node ./scripts/release.js --name=database --version="${{ steps.vars.outputs.tag }}" --token="${{ secrets.NPM_TOKEN }}"
- name: Release @bot-whatsapp/provider
run: yarn node ./scripts/release.js --name=provider --version="${{ steps.vars.outputs.tag }}" --token="${{ secrets.NPM_TOKEN }}"
- name: Commit Versioning & Push changes
uses: actions-js/push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
message: 'ci(version): :zap: automatic - "${date}" updated versions every packages'
branch: 'dev'

30
.gitignore vendored
View File

@@ -1,5 +1,9 @@
/node_modules
/node_modules/*
/packages/*/starters
/packages/*/node_modules
/packages/*/dist
/packages/*/docs/dist
/packages/provider/src/venom/tokens
session.json
chats/*
!chats/.gitkeep
@@ -9,4 +13,26 @@ mediaSend/*
!mediaSend/.gitkeep
!mediaSend/nota-de-voz.mp3
.env
.wwebjs_auth
.wwebjs_auth
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-*/
!starters/apps/base-*/
qr.svg
package-lock.json
yarn-error.log
.npmrc

4
.husky/commit-msg Executable file
View File

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

4
.husky/pre-commit Executable file
View File

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

4
.husky/pre-push Executable file
View File

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

9
.prettierignore Normal file
View File

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

View File

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

15
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,15 @@
{
// 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"
}
]
}

11
.vscode/settings.json vendored Normal file
View File

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

View File

@@ -0,0 +1,8 @@
/* 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;
}
};

807
.yarn/releases/yarn-3.3.0.cjs vendored Normal file

File diff suppressed because one or more lines are too long

10
.yarnrc.yml Normal file
View File

@@ -0,0 +1,10 @@
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,14 +1,285 @@
#### Actualización 14 Ene 2022
- npm update
- remove ora and chalk
- add env
- add mysql
- add dialogflow
- add scan qr from webpage
- update route with middleware
- fix send message to story
- external download
- easy deploy heroku
- add support for ubuntu/linux
# Changelog
https://stackoverflow.com/questions/51855169/dialogflow-403-iam-permission-dialogflow-sessions-detectintent
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.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
- npm update
- remove ora and chalk
- add env
- add mysql
- add dialogflow
- add scan qr from webpage
- update route with middleware
- fix send message to story
- external download
- easy deploy heroku
- add support for ubuntu/linux
https://stackoverflow.com/questions/51855169/dialogflow-403-iam-permission-dialogflow-sessions-detectintent

60
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,60 @@
# CONTRIBUTING
![](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/leifermendez/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
```
Abrir carpeta __example-app-base__ y ejecutar
```
cd example-app-base
npm i
npm run pre-copy
npm start
```
### __Commit y Push__
El proyecto tiene implementado __[husky](https://typicode.github.io/husky/#/)__, es una herramienta que dispara unas acciones al momento de hacer commit y hacer push.
__commit:__ Los commit son semánticos, esto quiere decir que deben cumplir un standar al momento de escribirlos ejemplo: ` feat(adapter): new adapter myqsl ` puede ver más info sobre esto __[aquí](https://github.com/conventional-changelog/commitlint/#what-is-commitlint)__
__push:__ Cada push ejecutar `yarn run test` el cual realiza los test internos que tienen que cumplir con __95% de cobertura__.
> Documento en constante actualización....
------
- [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)

88
EXAMPLE.md Normal file
View File

@@ -0,0 +1,88 @@
```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()
```

2
GLOSSARY.md Normal file
View File

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

247
README.md
View File

@@ -1,154 +1,93 @@
## Chatbot Whatsapp (OpenSource)
#### Actualizado Enero 2022
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 1 🔴
> 💥💥 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
### ATENCION 2 🔴
> 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)
#### 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 | ✅ |
| 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"}
]
}
)
```
## 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')
```
## Instruciones
__Descargar o Clonar repositorio__
![](https://i.imgur.com/dSpUbFz.png)
__Usas ¿Ubuntu / Linux?__
> Asegurate de instalar los siguientes paquetes
```
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
```
__Instalar dependencias (npm install)__
> Ubicate en le directorio que descargaste y via consola o terminal ejecuta el siguiente comando
`npm install`
![](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)
[![Test / Coverage](https://github.com/leifermendez/bot-whatsapp/actions/workflows/ci.yml/badge.svg)](https://github.com/leifermendez/bot-whatsapp/actions/workflows/ci.yml)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
--------
🦊 Documentación: [https://bot-whatsapp.pages.dev/](https://bot-whatsapp.pages.dev/)
Video como hacer PR: https://youtu.be/Lxt8Acob6aU
🚀 __Roadmap:__ [https://github.com/users/leifermendez/projects/4/views/1](https://github.com/users/leifermendez/projects/4/views/1)
**Comunidad**
<!-- readme: collaborators,contributors -start -->
<table>
<tr>
<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/aurik3">
<img src="https://avatars.githubusercontent.com/u/37228512?v=4" width="50;" alt="aurik3"/>
<br />
<sub><b>Null</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/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/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/jzvi12">
<img src="https://avatars.githubusercontent.com/u/10729787?v=4" width="50;" alt="jzvi12"/>
<br />
<sub><b>Null</b></sub>
</a>
</td></tr>
<tr>
<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>
<td align="center">
<a href="https://github.com/ulisesvina">
<img src="https://avatars.githubusercontent.com/u/20508563?v=4" width="50;" alt="ulisesvina"/>
<br />
<sub><b>Ulises Viña</b></sub>
</a>
</td>
<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 -->
> 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)

51
TODO.md Normal file
View File

@@ -0,0 +1,51 @@
### 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

6
__mocks__/mobile.mock.js Normal file
View File

@@ -0,0 +1,6 @@
const MOCK_MOBILE_WS = {
from: 'XXXXXX',
hasMedia: false,
}
module.exports = { MOCK_MOBILE_WS }

View File

@@ -0,0 +1,21 @@
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,75 +0,0 @@
const dialogflow = require('@google-cloud/dialogflow');
const fs = require('fs')
const nanoid = require('nanoid')
/**
* Debes de tener tu archivo con el nombre "chatbot-account.json" en la raíz del proyecto
*/
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) => {
let media = null;
const sessionId = nanoid.nanoid()
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
media = fields.media.stringValue || null
}
// const customPayload = parsePayload['payload']
const parseData = {
replyMessage: queryResult.fulfillmentText,
media,
trigger: null
}
return parseData
}
const getDataIa = (message = '', cb = () => { }) => {
detectIntent(message).then((res) => {
cb(res)
})
}
checkFileCredentials();
module.exports = { getDataIa }

View File

@@ -1,89 +0,0 @@
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 get = (message) => new Promise((resolve, reject) => {
/**
* Si no estas usando un gesto de base de datos
*/
if (process.env.DATABASE === 'none') {
const { key } = stepsInitial.find(k => k.keywords.includes(message)) || { key: null }
const response = key || null
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 ) => new Promise( async (resolve, reject) => {
switch ( process.env.DATABASE ) {
case 'mysql':
resolve( await saveMessageMysql( message, trigger, number ) )
break;
case 'none':
resolve( await saveMessageJson( message, trigger, number ) )
break;
default:
break;
}
})
module.exports = { get, reply, getIA, saveMessage }

View File

@@ -1,20 +0,0 @@
const Path = require('path')
const StormDB = require("stormdb");
const date = new Date().toISOString();
const saveMessageJson = (message, trigger, number) => 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 });
db.save();
resolve('Saved')
} catch (error) {
console.log(error)
reject(error)
}
})
module.exports = { saveMessageJson }

View File

@@ -1,71 +0,0 @@
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) {
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}

240
app.js
View File

@@ -1,240 +0,0 @@
/**
* ⚡⚡⚡ DECLARAMOS LAS LIBRERIAS y CONSTANTES A USAR! ⚡⚡⚡
*/
require('dotenv').config()
const fs = require('fs');
const express = require('express');
const cors = require('cors')
const qrcode = require('qrcode-terminal');
const { Client, LegacySessionAuth, LocalAuth } = require('whatsapp-web.js');
const mysqlConnection = require('./config/mysql')
const { middlewareClient } = require('./middleware/client')
const { generateImage, cleanNumber, checkEnvFile } = require('./controllers/handle')
const { connectionReady, connectionLost } = require('./controllers/connection')
const { saveMedia } = require('./controllers/save')
const { getMessages, responseMessages, bothResponse } = require('./controllers/flows')
const { sendMedia, sendMessage, lastTrigger, sendMessageButton, readChat } = require('./controllers/send')
const app = express();
app.use(cors())
app.use(express.json())
const server = require('http').Server(app)
const io = require('socket.io')(server, {
cors: {
origins: ['http://localhost:4200']
}
})
let socketEvents = {sendQR:() => {} ,sendStatus:() => {}};
io.on('connection', (socket) => {
const CHANNEL = 'main-channel';
socket.join(CHANNEL);
socketEvents = require('./controllers/socket')(socket)
console.log('Se conecto')
})
app.use('/', require('./routes/web'))
const port = process.env.PORT || 3000
const SESSION_FILE_PATH = './session.json';
var client;
var sessionData;
/**
* Escuchamos cuando entre un mensaje
*/
const listenMessage = () => client.on('message', async msg => {
const { from, body, hasMedia } = msg;
// Este bug lo reporto Lucas Aldeco Brescia para evitar que se publiquen estados
if (from === 'status@broadcast') {
return
}
message = body.toLowerCase();
console.log('BODY',message)
const number = cleanNumber(from)
await readChat(number, message)
/**
* Guardamos el archivo multimedia que envia
*/
if (process.env.SAVE_MEDIA && hasMedia) {
const media = await msg.downloadMedia();
saveMedia(media);
}
/**
* Si estas usando dialogflow solo manejamos una funcion todo es IA
*/
if (process.env.DATABASE === 'dialogflow') {
const response = await bothResponse(message);
await sendMessage(client, from, response.replyMessage);
if (response.media) {
sendMedia(client, from, response.media);
}
return
}
/**
* Ver si viene de un paso anterior
* Aqui podemos ir agregando más pasos
* a tu gusto!
*/
const lastStep = await lastTrigger(from) || null;
if (lastStep) {
const response = await responseMessages(lastStep)
await sendMessage(client, from, response.replyMessage);
}
/**
* Respondemos al primero paso si encuentra palabras clave
*/
const step = await getMessages(message);
if (step) {
const response = await responseMessages(step);
/**
* Si quieres enviar botones
*/
await sendMessage(client, from, response.replyMessage, response.trigger);
if(response.hasOwnProperty('actions')){
const { actions } = response;
await sendMessageButton(client, from, null, actions);
return
}
if (!response.delay && response.media) {
sendMedia(client, from, response.media);
}
if (response.delay && response.media) {
setTimeout(() => {
sendMedia(client, from, response.media);
}, response.delay)
}
return
}
//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;
await sendMessageButton(client, from, null, actions);
}
return
}
});
/**
* Revisamos si tenemos credenciales guardadas para inciar sessio
* este paso evita volver a escanear el QRCODE
*/
const withSession = () => {
// Si exsite cargamos el archivo con las credenciales
console.log(`Validando session con Whatsapp...`)
sessionData = require(SESSION_FILE_PATH);
client = new Client({
authStrategy: new LegacySessionAuth({
session: sessionData // saved session object
}),
restartOnAuthFail: true,
puppeteer: {
args: [
'--no-sandbox'
],
}
});
client.on('ready', () => {
connectionReady()
listenMessage()
loadRoutes(client);
socketEvents.sendStatus()
});
client.on('auth_failure', () => connectionLost())
client.initialize();
}
/**
* Generamos un QRCODE para iniciar sesion
*/
const withOutSession = () => {
console.log('No tenemos session guardada');
console.log([
'🙌 El core de whatsapp se esta actualizando',
'🙌 para proximamente dar paso al multi-device',
'🙌 falta poco si quieres estar al pendiente unete',
'🙌 http://t.me/leifermendez',
'________________________',
].join('\n'));
client = new Client({
authStrategy: new LocalAuth(),
puppeteer: {
headless: true,
args: ['--no-sandbox']
},
clientId: 'client-one'
});
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()
loadRoutes(client);
// socketEvents.sendStatus(client)
});
client.on('auth_failure', (e) => {
// console.log(e)
// connectionLost()
});
client.on('authenticated', (session) => {
sessionData = session;
});
client.initialize();
}
/**
* Cargamos rutas de express
*/
const loadRoutes = (client) => {
app.use('/api/', middlewareClient(client), require('./routes/api'))
}
/**
* Revisamos si existe archivo con credenciales!
*/
(fs.existsSync(SESSION_FILE_PATH)) ? withSession() : withOutSession();
/**
* Verificamos si tienes un gesto de db
*/
if (process.env.DATABASE === 'mysql') {
mysqlConnection.connect()
}
server.listen(port, () => {
console.log(`El server esta listo por el puerto ${port}`);
})
checkEnvFile();

View File

@@ -1,35 +0,0 @@
{
"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"
}
}

91
changelog.config.js Normal file
View File

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

View File

@@ -1,13 +0,0 @@
{
"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":""
}

1
commitlint.config.js Normal file
View File

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

View File

@@ -0,0 +1,8 @@
{
"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",
"*/"
]
}

View File

@@ -1,18 +0,0 @@
const mysql = require('mysql');
const connection = mysql.createConnection({
host : process.env.SQL_HOST || 'localhost',
user : process.env.SQL_USER || 'me',
password : process.env.SQL_PASS || '',
database : process.env.SQL_DATABASE || 'my_db'
});
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}

View File

@@ -1,13 +0,0 @@
const connectionReady = (cb = () =>{}) => {
console.log('Listo para escuchas mensajes')
console.log('Client is ready!');
cb()
}
const connectionLost = (cb = () =>{}) => {
console.log('** Error de autentificacion vuelve a generar el QRCODE (Borrar el archivo session.json) **');
cb()
}
module.exports = {connectionReady, connectionLost}

View File

@@ -1,28 +0,0 @@
const {get, reply, getIA} = require('../adapter')
const {saveExternalFile, checkIsUrl} = require('./handle')
const getMessages = async (message) => {
const data = await get(message)
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
}
module.exports = { getMessages, responseMessages, bothResponse }

View File

@@ -1,60 +0,0 @@
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 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 mantener el mejor QR⚡`);
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`)
}
}
module.exports = {cleanNumber, saveExternalFile, generateImage, checkIsUrl, checkEnvFile}

View File

@@ -1,18 +0,0 @@
const mimeDb = require('mime-db')
const fs = require('fs')
/**
* Guardamos archivos multimedia que nuestro cliente nos envie!
* @param {*} media
*/
const saveMedia = (media) => {
const extensionProcess = mimeDb[media.mimetype]
const ext = extensionProcess.extensions[0]
fs.writeFile(`./media/${Date.now()}.${ext}`, media.data, { encoding: 'base64' }, function (err) {
console.log('** Archivo Media Guardado **');
});
}
module.exports = {saveMedia}

View File

@@ -1,102 +0,0 @@
const ExcelJS = require('exceljs');
const moment = require('moment');
const fs = require('fs');
const { MessageMedia, Buttons } = require('whatsapp-web.js');
const { cleanNumber } = require('./handle')
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, fileName) => {
number = cleanNumber(number)
const file = `${DIR_MEDIA}/${fileName}`;
if (fs.existsSync(file)) {
const media = MessageMedia.fromFilePath(file);
client.sendMessage(number, media, { sendAudioAsVoice: true });
}
}
/**
* Enviamos archivos como notas de voz
* @param {*} number
* @param {*} fileName
*/
const sendMediaVoiceNote = (client, number, fileName) => {
number = cleanNumber(number)
const file = `${DIR_MEDIA}/${fileName}`;
if (fs.existsSync(file)) {
const media = MessageMedia.fromFilePath(file);
client.sendMessage(number, media ,{ sendAudioAsVoice: true });
}
}
/**
* Enviamos un mensaje simple (texto) a nuestro cliente
* @param {*} number
*/
const sendMessage = async (client, number = null, text = null, trigger = null) => {
setTimeout(async () => {
number = cleanNumber(number)
const message = text
client.sendMessage(number, message);
await readChat(number, message, trigger)
console.log(`⚡⚡⚡ Enviando mensajes....`);
},DELAY_TIME)
}
/**
* Enviamos un mensaje con buttons a nuestro cliente
* @param {*} number
*/
const sendMessageButton = async (client, number = null, text = null, actionButtons) => {
number = cleanNumber(number)
const { title = null, message = null, footer = null, buttons = [] } = actionButtons;
let button = new Buttons(message,[...buttons], title, footer);
client.sendMessage(number, button);
console.log(`⚡⚡⚡ Enviando mensajes....`);
}
/**
* 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) => {
number = cleanNumber(number)
await saveMessage( message, trigger, number )
console.log('Saved')
}
module.exports = { sendMessage, sendMedia, lastTrigger, sendMessageButton, readChat, sendMediaVoiceNote }

View File

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

View File

@@ -1,16 +0,0 @@
const fs = require('fs')
const { sendMessage } = require('../controllers/send')
const sendMessagePost = (req, res) => {
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 }

3
core.class.log Normal file
View File

@@ -0,0 +1,3 @@
[handleMsg]: { from: 'XXXXXX', body: 'hola', hasMedia: false }
[handleMsg]: { from: 'XXXXXX', body: 'hola', hasMedia: false }
[handleMsg]: { from: 'XXXXXX', body: 'hola', hasMedia: false }

25
docker-compose.yml Normal file
View File

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

View File

@@ -1,93 +0,0 @@
[
{
"keywords": [
"hola",
"hola!",
"ola",
"ole",
"inicio",
"welcome",
"buenos días",
"buenas tardes",
"buenas noches",
"me dieron este número",
"venden a crédito",
"quisiera saber si venden",
"necesito saber"
],
"key": "STEP_1"
},
{
"keywords": [
"cursos",
"info",
"curso" ],
"key": "STEP_2"
},
{
"keywords": [
"angular"
],
"key": "STEP_2_1"
},
{
"keywords": [
"node"
],
"key": "STEP_2_2"
},
{
"keywords": [
"ngrx"
],
"key": "STEP_2_3"
},
{
"keywords": [
"aws"
],
"key": "STEP_2_4"
},
{
"keywords": [
"asesor",
"asesores",
"Vendedor",
"cobrador"
],
"key": "STEP_3"
},
{
"keywords": [
"muchas gracias",
"ok",
"gracias",
"vale gracias"
],
"key": "STEP_4"
},
{
"keywords": [
"youtube"
],
"key": "STEP_5"
},
{
"keywords": [
"VER_CURSOS"
],
"key": "STEP_6"
},
{
"keywords": [
"telegram"
],
"key": "STEP_7"
},
{
"keywords": [
"audio"
],
"key": "STEP_8"
}
]

View File

@@ -1,148 +0,0 @@
{
"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
},
"STEP_0":{
"replyMessage":[
"El flujo ha finalizado \n",
"pero puedes ver todo el codigo de este \n",
"repositorio en https://github.com/leifermendez/bot-whatsapp.git"
],
"media":null,
"trigger":null
},
"STEP_1":{
"replyMessage":[
"Hola! y✌ Bienvenido a este 🤖 CHATBOT de Whatsapp, lo primero \n",
"decirte que mi nombre es *Leifer Mendez*😎 \n",
"\n Si necesitas ver más info sobre las capacitacion tecnicas ",
"escribe *cursos* o *info* o escribe *audio*"
],
"media":null,
"trigger":null,
"actions":{
"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"}
]
}
},
"STEP_2":{
"replyMessage":[
"Perfecto, te voy a pasar la lista ",
"de los temas que tengo y un breve video 🙂🤖 \n\n",
"*Angular* Basico (Pago) \n",
"*Angular* Basico (Gratis) \n",
"*Node* Basico (Gratis) \n",
"*NGRX* Basico (Gratis) \n",
"*AWS* Basico (Pago) \n\n",
"Escribe la palabra del tema que te interese \n"
],
"media":"https://i.giphy.com/media/5J5gN0WUk0VToHaK2p/giphy-downsized.gif",
"trigger":null
},
"STEP_2_1":{
"replyMessage":[
"Si te interesa Angular tienes disponible \n",
"*(Gratis)* https://bit.ly/367tJ32 \n\n",
"*(Pago)* https://link.codigoencasa.com/PROMO-INICIAL \n\n",
"*(Pago)* https://link.codigoencasa.com/ANGULAR-BASICO-EDTEAM \n\n",
"😎😎😎"
],
"media":"https://i.imgur.com/Q0a5UQI.jpg",
"trigger":null
},
"STEP_2_2":{
"replyMessage":[
"Si te interesa NODE tienes disponible \n",
"*(Gratis)* https://bit.ly/3od1Bl6 \n\n",
"Espero pronto tener más material disponible",
"🤖"
],
"media":null,
"trigger":null
},
"STEP_2_3":{
"replyMessage":[
"NGRX para manejar estados en Angular \n",
"*(Gratis)* https://bit.ly/ngrx-desde-cero \n",
"A darle! 😮"
],
"media":null,
"trigger":null
},
"STEP_2_4":{
"replyMessage":[
"Muy bien AWS esta pronto a salir pre-registrate aquí \n",
"*(Pre-registro)* https://link.codigoencasa.com/AWS-BASICO-INVITACION \n",
"😮😮"
],
"media":null,
"trigger":null
},
"STEP_3":{
"replyMessage":[
"¿Ok cual curso de intereso? \n",
"*angular* , *node*, *ngrx*, *aws*"
],
"media":null,
"trigger":null
},
"STEP_4":{
"replyMessage":[
"Gracias a ti! \n"
],
"media":"https://media4.giphy.com/media/hur0SFIU5SH4mxNBWa/giphy.gif",
"trigger":null
},
"STEP_5":{
"replyMessage":[
"Muy bien te comparto el canal de Youtube \n",
"https://youtube.com/leifermendez \n"
],
"media":null,
"trigger":null
},
"STEP_6":{
"replyMessage":[
"Perfecto, te voy a pasar la lista ",
"de los temas que tengo y un breve video 🙂🤖 \n\n",
"*Angular* Basico (Pago) \n",
"*Angular* Basico (Gratis) \n",
"*Node* Basico (Gratis) \n",
"*NGRX* Basico (Gratis) \n",
"*AWS* Basico (Pago) \n\n",
"Escribe la palabra del tema que te interese \n"
],
"media":"https://i.giphy.com/media/5J5gN0WUk0VToHaK2p/giphy-downsized.gif",
"trigger":null
},
"STEP_7":{
"replyMessage":[
"Vente al telegram \n",
"https://t.me/leifermendez \n"
],
"media":null,
"trigger":null
},
"STEP_8":{
"replyMessage":[
"Esto es una nota de voz \n"
],
"media":"nota-de-voz.mp3",
"trigger":null
}
}

Binary file not shown.

Binary file not shown.

View File

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

View File

3569
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,38 +1,95 @@
{
"name": "test-ws-bot",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "node ./app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@google-cloud/dialogflow": "^4.6.0",
"cors": "^2.8.5",
"dotenv": "^11.0.0",
"exceljs": "^4.3.0",
"express": "^4.17.2",
"file-type": "^16.5.3",
"mime-db": "^1.51.0",
"moment": "^2.29.1",
"mysql": "^2.18.1",
"nanoid": "^3.1.32",
"qr-image": "^3.2.0",
"qrcode-terminal": "^0.12.0",
"socket.io": "^4.4.1",
"stormdb": "^0.5.2",
"whatsapp-web.js": "^1.16.4",
"xlsx": "^0.16.9"
},
"devDependencies": {
"pm2": "^5.1.2",
"prettier": "2.5.1"
},
"engines": {
"node": "14.x"
}
"name": "@bot-whatsapp/root",
"version": "0.1.2",
"description": "Bot de wahtsapp open source para MVP o pequeños negocios",
"main": "app.js",
"private": true,
"scripts": {
"commit": "git-cz",
"cli:rollup": "rollup --config ./packages/cli/rollup-cli.config.js ",
"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 ",
"database:rollup": "rollup --config ./packages/database/rollup-database.config.js",
"create-bot-whatsapp:rollup": "rollup --config ./packages/create-bot-whatsapp/rollup-create.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": "yarn run cli:rollup && yarn run bot:rollup && yarn run provider:rollup && yarn run database:rollup && yarn run create-bot-whatsapp:rollup",
"copy.lib": "node ./scripts/move.js",
"test.unit": "node ./node_modules/uvu/bin.js packages test",
"test.coverage": "node ./node_modules/c8/bin/c8.js npm run test.unit",
"test": "npm run test.coverage",
"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"
},
"workspaces": [
"packages/create-bot-whatsapp",
"packages/bot",
"packages/cli",
"packages/database",
"packages/provider",
"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",
"devDependencies": {
"@commitlint/cli": "^17.3.0",
"@commitlint/config-conventional": "^17.3.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",
"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": {
"node": ">=16",
"npm": "please-use-yarn",
"yarn": ">=3"
},
"author": "Leifer Mendez <leifer33@gmail.com>"
}

110
packages/bot/USES_CASES.md Normal file
View File

@@ -0,0 +1,110 @@
# @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

@@ -0,0 +1,171 @@
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`),
})
/**
* [ ] Escuchar eventos del provider asegurarte que los provider emitan eventos
* [ ] Guardar historial en db
* [ ] Buscar mensaje en flow
*
*/
class CoreClass {
flowClass
databaseClass
providerClass
constructor(_flow, _database, _provider) {
this.flowClass = _flow
this.databaseClass = _database
this.providerClass = _provider
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),
},
]
/**
*
* @param {*} messageInComming
* @returns
*/
handleMsg = async (messageInComming) => {
logger.log(`[handleMsg]: `, messageInComming)
const { body, from } = messageInComming
let msgToSend = []
let fallBackFlag = false
if (!body.length) return
const prevMsg = await this.databaseClass.getPrevByNumber(from)
const refToContinue = this.flowClass.findBySerialize(
prevMsg?.refSerialize
)
if (prevMsg?.ref) {
const ctxByNumber = toCtx({
body,
from,
prevRef: prevMsg.refSerialize,
})
this.databaseClass.save(ctxByNumber)
}
// 📄 [options: fallback]: esta funcion se encarga de repetir el ultimo mensaje
const fallBack = () => {
fallBackFlag = true
msgToSend = this.flowClass.find(refToContinue?.keyword, true) || []
this.sendFlow(msgToSend, from)
return refToContinue
}
// 📄 [options: callback]: Si se tiene un callback se ejecuta
if (!fallBackFlag && refToContinue && prevMsg?.options?.callback) {
const indexFlow = this.flowClass.findIndexByRef(refToContinue?.ref)
this.flowClass.allCallbacks[indexFlow].callback(messageInComming, {
fallBack,
})
}
// 📄🤘(tiene return) [options: nested(array)]: Si se tiene flujos hijos los implementa
if (!fallBackFlag && 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) || []
this.sendFlow(msgToSend, from)
return
}
// 📄🤘(tiene return) [options: capture (boolean)]: Si se tiene option boolean
if (!fallBackFlag && !prevMsg?.options?.nested?.length) {
const typeCapture = typeof prevMsg?.options?.capture
const valueCapture = prevMsg?.options?.capture
if (['string', 'boolean'].includes(typeCapture) && valueCapture) {
msgToSend = this.flowClass.find(refToContinue?.ref, true) || []
this.sendFlow(msgToSend, from)
return
}
}
msgToSend = this.flowClass.find(body) || []
this.sendFlow(msgToSend, from)
}
/**
* Enviar mensaje con contexto atraves del proveedor de whatsapp
* @param {*} numberOrId
* @param {*} ctxMessage ver más en GLOSSARY.md
* @returns
*/
sendProviderAndSave = (numberOrId, ctxMessage) => {
const { answer } = ctxMessage
return Promise.all([
this.providerClass.sendMessage(numberOrId, answer, ctxMessage),
this.databaseClass.save({ ...ctxMessage, from: numberOrId }),
])
}
sendFlow = async (messageToSend, numberOrId) => {
const queue = []
for (const ctxMessage of messageToSend) {
const delayMs = ctxMessage?.options?.delay || 0
if (delayMs) await delay(delayMs)
Queue.enqueue(() =>
this.sendProviderAndSave(numberOrId, ctxMessage)
)
}
return Promise.all(queue)
}
/**
* @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)
}
}
}
module.exports = CoreClass

47
packages/bot/index.js Normal file
View File

@@ -0,0 +1,47 @@
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 }) =>
new CoreClass(flow, database, provider)
/**
* 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

@@ -0,0 +1,67 @@
const { toSerialize } = require('./methods/toSerialize')
class FlowClass {
allCallbacks = []
flowSerialize = []
flowRaw = []
constructor(_flow) {
if (!Array.isArray(_flow)) throw new Error('Esto debe ser un ARRAY')
this.flowRaw = _flow
this.allCallbacks = _flow
.map((cbIn) => cbIn.ctx.callbacks)
.flat(2)
.map((c, i) => ({ callback: c?.callback, index: i }))
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
/** Retornar expresion regular para buscar coincidencia */
const mapSensitive = (str, flag = false) => {
const regexSensitive = flag ? 'g' : 'i'
if (Array.isArray(str)) {
return new RegExp(str.join('|'), regexSensitive)
}
return new RegExp(str, regexSensitive)
}
const findIn = (keyOrWord, symbol = false, flow = overFlow) => {
const sensitive = refSymbol?.options?.sensitive || false
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) => {
return mapSensitive(c.keyword, sensitive).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)
}
module.exports = FlowClass

View File

@@ -0,0 +1,93 @@
const { generateRef } = require('../../utils/hash')
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 = () => ({
nested: Array.isArray(nested) ? nested : [],
})
const callback =
typeof cb === 'function'
? cb
: () => console.log('Callback no definida')
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,
},
])
const callbacks = [].concat(inCtx.callbacks).concat([
{
ref: lastCtx.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

@@ -0,0 +1,15 @@
const { toSerialize } = require('./toSerialize')
/**
* @deprecate
* @param answer string
* @param options {media:string, buttons:[], capture:true default false}
* @returns
*/
const addChild = (flowIn = null) => {
if (!flowIn?.toJson) {
throw new Error('DEBE SER UN FLOW CON toJSON()')
}
return toSerialize(flowIn.toJson())
}
module.exports = { addChild }

View File

@@ -0,0 +1,49 @@
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) => {
const parseOptions = () => {
const defaultProperties = {
sensitive:
typeof options?.sensitive === 'boolean'
? options?.sensitive
: 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

@@ -0,0 +1,8 @@
const { addAnswer } = require('./addAnswer')
const { addKeyword } = require('./addKeyword')
const { addChild } = require('./addChild')
const { toSerialize } = require('./toSerialize')
const { toCtx } = require('./toCtx')
const { toJson } = require('./toJson')
module.exports = { addAnswer, addKeyword, addChild, toCtx, toJson, toSerialize }

View File

@@ -0,0 +1,19 @@
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, index }) => {
return {
ref: generateRef(),
keyword: prevRef,
answer: body,
options: {},
from,
refSerialize: generateRefSerialize({ index, answer: body }),
}
}
module.exports = { toCtx }

View File

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

View File

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

@@ -0,0 +1,14 @@
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()],
}

32
packages/bot/package.json Normal file
View File

@@ -0,0 +1,32 @@
{
"name": "@bot-whatsapp/bot",
"version": "0.0.21-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"
}
}

View File

@@ -0,0 +1,29 @@
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
}
}
module.exports = ProviderClass

View File

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

View File

@@ -0,0 +1,279 @@
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 = [{ callback: () => console.log('') }]
flowSerialize = []
flowRaw = []
find = (arg) => {
if (arg) {
return [{ answer: 'answer', ref: 'ref' }]
} else {
return null
}
}
findBySerialize = () => ({})
findIndexByRef = () => 0
}
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

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

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

View File

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

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

View File

@@ -0,0 +1,46 @@
class Queue {
static queue = []
static pendingPromise = false
static enqueue(promise) {
return new Promise((resolve, reject) => {
this.queue.push({
promise,
resolve,
reject,
})
this.dequeue()
})
}
static dequeue() {
if (this.workingOnPromise) {
return false
}
const item = this.queue.shift()
if (!item) {
return false
}
try {
this.workingOnPromise = true
item.promise()
.then((value) => {
this.workingOnPromise = false
item.resolve(value)
this.dequeue()
})
.catch((err) => {
this.workingOnPromise = false
item.reject(err)
this.dequeue()
})
} catch (err) {
this.workingOnPromise = false
item.reject(err)
this.dequeue()
}
return true
}
}
module.exports = Queue

20
packages/cli/README.md Normal file
View File

@@ -0,0 +1,20 @@
# @bot-whatsapp/cli
- [x] Revisar version de NODE
- [x] Revisar OS
- [x] Obtener Package Manager
- [x] Revisar las libreria de WhatsappWeb para obtener version reciente
- [x] Opcion interactiva de limpiar session
- [x] Opcion de generar `json` con la configuracion
- [x] Agregar `rollup` para limpiar el codigo
---
**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)

3
packages/cli/bin/cli.js Executable file
View File

@@ -0,0 +1,3 @@
#!/usr/bin/env node
const index = require('../lib/cli/bundle.cli.cjs')
index.startInteractive()

View File

@@ -0,0 +1,38 @@
const { red, yellow, green, bgCyan } = require('kleur')
const checkNodeVersion = () => {
console.log(bgCyan('🚀 Revisando tu Node.js'))
const version = process.version
const majorVersion = parseInt(version.replace('v', '').split('.').shift())
if (majorVersion < 16) {
console.error(
red(
`🔴 Se require Node.js 16 o superior. Actualmente esta ejecutando Node.js ${version}`
)
)
process.exit(1)
}
console.log(green(`Node.js compatible ${version}`))
console.log(``)
}
const checkOs = () => {
console.log(bgCyan('🙂 Revisando tu sistema operativo'))
const os = process.platform
if (!os.includes('win32')) {
const messages = [
`El sistema operativo actual (${os}) posiblemente requiera`,
`una configuración adicional referente al puppeteer`,
``,
`Recuerda pasar por el WIKI`,
`🔗 https://github.com/leifermendez/bot-whatsapp/wiki/Instalación`,
``,
]
console.log(yellow(messages.join(' \n')))
}
console.log(``)
}
module.exports = { checkNodeVersion, checkOs }

View File

@@ -0,0 +1,19 @@
const rimraf = require('rimraf')
const { yellow } = require('kleur')
const { join } = require('path')
const PATH_WW = [
join(process.cwd(), '.wwebjs_auth'),
join(process.cwd(), 'session.json'),
]
const cleanSession = () => {
const queue = []
for (const PATH of PATH_WW) {
console.log(yellow(`😬 Eliminando: ${PATH}`))
queue.push(rimraf(PATH, () => Promise.resolve()))
}
return Promise.all(queue)
}
module.exports = { cleanSession }

View File

@@ -0,0 +1,33 @@
const { writeFile } = require('fs').promises
const { join } = require('path')
/**
* JSON_TEMPLATE = {[key:string]{...pros}}
*/
const JSON_TEMPLATE = {
provider: {
vendor: '',
},
database: {
host: '',
password: '',
port: '',
username: '',
db: '',
},
io: {
vendor: '',
},
}
const PATH_CONFIG = join(process.cwd(), 'config.json')
const jsonConfig = () => {
return writeFile(
PATH_CONFIG,
JSON.stringify(JSON_TEMPLATE, null, 2),
'utf-8'
)
}
module.exports = { jsonConfig }

View File

@@ -0,0 +1,25 @@
const fs = require('fs-extra')
/**
* Copy files
*/
const copyFiles = async (from, to) => {
try {
await fs.copy(from, to)
console.log('success!')
} catch (err) {
console.error(err)
}
}
/**
* Copiar directorio con archivos
* @param {*} templateName
*/
const copyBaseApp = async (fromDir = process.cwd(), toDir = process.cwd()) => {
const BASEP_APP_PATH_FROM = `${fromDir}`
const BASEP_APP_PATH_TO = `${toDir}`
await copyFiles(BASEP_APP_PATH_FROM, BASEP_APP_PATH_TO)
}
module.exports = { copyBaseApp }

3
packages/cli/index.js Normal file
View File

@@ -0,0 +1,3 @@
const { startInteractive } = require('./interactive')
if (process.env.NODE_ENV === 'dev') startInteractive()
module.exports = { startInteractive }

View File

@@ -0,0 +1,24 @@
const { readFileSync, existsSync } = require('fs')
const { join } = require('path')
const { installDeps, getPkgManage } = require('./tool')
const PATHS_DIR = [
join(__dirname, 'pkg-to-update.json'),
join(__dirname, '..', 'pkg-to-update.json'),
join(__dirname, '..', '..', 'pkg-to-update.json'),
]
const PKG_TO_UPDATE = () => {
const PATH_INDEX = PATHS_DIR.findIndex((a) => existsSync(a))
const data = readFileSync(PATHS_DIR[PATH_INDEX], 'utf-8')
const dataParse = JSON.parse(data)
const pkg = Object.keys(dataParse).map((n) => `${n}@${dataParse[n]}`)
return pkg
}
const installAll = async () => {
const pkg = await getPkgManage()
installDeps(pkg, PKG_TO_UPDATE()).runInstall()
}
module.exports = { installAll }

View File

@@ -0,0 +1,68 @@
const { red } = require('kleur')
const spawn = require('cross-spawn')
// const { detect } = require('detect-package-manager')
const PKG_OPTION = {
npm: 'install',
yarn: 'add',
pnpm: 'add',
}
const getPkgManage = async () => {
// const pkg = await detect()
// return pkg
return 'npm'
}
const installDeps = (pkgManager, packageList) => {
const errorMessage = `Ocurrió un error instalando ${packageList}`
let childProcess = []
const installSingle = (pkgInstall) => () => {
new Promise((resolve) => {
try {
childProcess = spawn(
pkgManager,
[PKG_OPTION[pkgManager], pkgInstall],
{
stdio: 'inherit',
}
)
childProcess.on('error', (e) => {
console.error(e)
console.error(red(errorMessage))
resolve()
})
childProcess.on('close', (code) => {
if (code === 0) {
resolve()
} else {
console.error(code)
console.error(red(errorMessage))
}
})
resolve()
} catch (e) {
console.error(e)
console.error(red(errorMessage))
}
})
}
if (typeof packageList === 'string') {
childProcess.push(installSingle(packageList))
} else {
for (const pkg of packageList) {
childProcess.push(installSingle(pkg))
}
}
const runInstall = () => {
return Promise.all(childProcess.map((i) => i()))
}
return { runInstall }
}
module.exports = { getPkgManage, installDeps }

View File

@@ -0,0 +1,139 @@
const prompts = require('prompts')
const { yellow, red, cyan, bgMagenta } = require('kleur')
const { copyBaseApp } = require('../create-app')
const { join } = require('path')
const { existsSync } = require('fs')
const { checkNodeVersion, checkOs } = require('../check')
const bannerDone = () => {
console.log(``)
console.log(
cyan(
[
`[Agradecimientos]: Este es un proyecto OpenSource, si tienes intenciones de colaborar puedes hacerlo:`,
`[😉] Comprando un cafe https://www.buymeacoffee.com/leifermendez`,
`[⭐] Dar estrella https://github.com/leifermendez/bot-whatsapp`,
`[🚀] Realizando mejoras en el codigo`,
].join('\n')
)
)
console.log(``)
}
const startInteractive = async () => {
const questions = [
{
type: 'text',
name: 'outDir',
message: 'Quieres crear un bot? (Y/n)',
},
{
type: 'multiselect',
name: 'providerWs',
message: '¿Cuál proveedor de whatsapp quieres utilizar?',
choices: [
{ title: 'whatsapp-web.js (gratis)', value: 'wweb' },
{ title: 'Twilio', value: 'twilio' },
{ title: 'Venom (gratis)', value: 'venom' },
{ title: 'Baileys (gratis)', value: 'bailey', disabled: true },
{ title: 'API Oficial (Meta)', value: 'meta', disabled: true },
],
max: 1,
hint: 'Espacio para seleccionar',
instructions: '↑/↓',
},
{
type: 'multiselect',
name: 'providerDb',
message: '¿Cuál base de datos quieres utilizar?',
choices: [
{ title: 'Memory', value: 'memory' },
{ title: 'Mongo', value: 'mongo' },
{ title: 'MySQL', value: 'mysql' },
{ title: 'Json', value: 'json', disabled: true },
],
max: 1,
hint: 'Espacio para seleccionar',
instructions: '↑/↓',
},
]
console.clear()
checkNodeVersion()
checkOs()
const onCancel = () => {
console.log('¡Proceso cancelado!')
return true
}
const response = await prompts(questions, { onCancel })
const { outDir = '', providerDb = [], providerWs = [] } = response
const createApp = async (templateName = null) => {
if (!templateName)
throw new Error('TEMPLATE_NAME_INVALID: ', templateName)
const possiblesPath = [
join(__dirname, '..', '..', 'starters', 'apps', templateName),
join(__dirname, '..', 'starters', 'apps', templateName),
join(__dirname, 'starters', 'apps', templateName),
]
const answer = outDir.toLowerCase() || 'n'
if (answer.includes('n')) return true
if (answer.includes('y')) {
const indexOfPath = possiblesPath.find((a) => existsSync(a))
await copyBaseApp(indexOfPath, join(process.cwd(), templateName))
console.log(``)
console.log(bgMagenta(`⚡⚡⚡INSTRUCCIONES⚡⚡⚡`))
console.log(yellow(`cd ${templateName}`))
console.log(yellow(`npm install`))
console.log(yellow(`npm start`))
console.log(``)
return outDir
}
}
/**
* Selccionar Provider (meta, twilio, etc...)
* @returns
*/
const vendorProvider = async () => {
const [answer] = providerWs
if (!providerWs.length) {
console.log(
red(
`Debes seleccionar un proveedor de whatsapp. Tecla [Space] para seleccionar`
)
)
process.exit(1)
}
return answer
}
/**
* Selecionar adaptador de base de datos
* @returns
*/
const dbProvider = async () => {
const [answer] = providerDb
if (!providerDb.length) {
console.log(
red(
`Debes seleccionar un proveedor de base de datos. Tecla [Space] para seleccionar`
)
)
process.exit(1)
}
return answer
}
const providerAdapter = await vendorProvider()
const dbAdapter = await dbProvider()
const NAME_DIR = ['base', providerAdapter, dbAdapter].join('-')
await createApp(NAME_DIR)
bannerDone()
}
module.exports = { startInteractive }

19
packages/cli/package.json Normal file
View File

@@ -0,0 +1,19 @@
{
"name": "@bot-whatsapp/cli",
"version": "0.0.28-alpha.0",
"description": "",
"main": "index.js",
"devDependencies": {
"cross-env": "^7.0.3",
"cross-spawn": "^7.0.3",
"detect-package-manager": "^2.0.1",
"kleur": "^4.1.5"
},
"files": [
"./starters/",
"./lib/cli/bundle.cli.cjs"
],
"bin": {
"bot": "./bin/cli.js"
}
}

View File

@@ -0,0 +1,3 @@
{
"whatsapp-web.js": "latest"
}

View File

@@ -0,0 +1,23 @@
const banner = require('../../config/banner.rollup.json')
const commonjs = require('@rollup/plugin-commonjs')
const copy = require('rollup-plugin-copy')
const { nodeResolve } = require('@rollup/plugin-node-resolve')
const { join } = require('path')
const PATH = join(__dirname, 'lib', 'cli', 'bundle.cli.cjs')
module.exports = {
input: join(__dirname, 'index.js'),
output: {
banner: banner['banner.output'].join(''),
file: PATH,
format: 'cjs',
},
plugins: [
copy({
targets: [{ src: 'starters/*', dest: join(__dirname, 'starters') }],
}),
commonjs(),
nodeResolve(),
],
}

View File

@@ -0,0 +1,3 @@
#!/usr/bin/env node
const main = require('../lib/bundle.create-bot-whatsapp.cjs')
main()

View File

@@ -0,0 +1,10 @@
const { startInteractive } = require('../cli')
/**
* Voy a llamar directo a CLI
* Temporalmente luego mejoro esta
* parte
* @returns
*/
const main = () => startInteractive()
module.exports = main

View File

@@ -0,0 +1,15 @@
{
"name": "create-bot-whatsapp",
"version": "0.0.39-alpha.0",
"description": "",
"main": "./lib/bundle.create-bot-whatsapp.cjs",
"files": [
"./starters/",
"./bin/create.js",
"./lib/bundle.create-bot-whatsapp.cjs"
],
"bin": "./bin/create.js",
"dependencies": {
"@bot-whatsapp/cli": "*"
}
}

View File

@@ -0,0 +1,23 @@
const banner = require('../../config/banner.rollup.json')
const commonjs = require('@rollup/plugin-commonjs')
const copy = require('rollup-plugin-copy')
const { nodeResolve } = require('@rollup/plugin-node-resolve')
const { join } = require('path')
const PATH = join(__dirname, 'lib', 'bundle.create-bot-whatsapp.cjs')
module.exports = {
input: join(__dirname, 'index.js'),
output: {
banner: banner['banner.output'].join(''),
file: PATH,
format: 'cjs',
},
plugins: [
copy({
targets: [{ src: 'starters/*', dest: join(__dirname, 'starters') }],
}),
commonjs(),
nodeResolve(),
],
}

View File

@@ -0,0 +1,63 @@
### 🚀 Package (@bot-whatsapp/database)
Este package tiene como reponsabilidad proveer de diferentes adaptadores para la capa de datos.
La idea es brindar multiples opciones como un adaptador de MySQL, Mongo, entre otros.
Ejemplo de como se implementaria:
```js
const MongoAdapter = require('@bot-whatsapp/database/mongo')
/// o
const MySQLAdapter = require('@bot-whatsapp/database/mysql')
const main = async () => {
const adapterDB = new MongoAdapter()
const adapterFlow = createFlow([flujoBot])
const adapterProvider = createProvider(WebWhatsappProvider)
createBot({
flow: adapterFlow,
provider: adapterProvider,
database: adapterDB,
})
}
```
#### CTX
```json
{
ref: 'ans_7d9981e5-5019-422c-a19a-565cbb021391',
keyword: 'ans_cfdad31b-ff6d-475f-873a-4ed6f8a79a43',
answer: 'Esperando respuesta...',
options: {
media: null,
buttons: [],
capture: true,
child: null,
nested: [Array],
keyword: {},
callback: true
},
refSerialize: '81f18f563fd26a6c6d12c62aed98095f',
from: 'NUMERO_PERSONA_QUE_ESCRIBE'
}
```
#### Video
> Video explicando como debes de agregar nuevos adaptadores
[![Video](https://i.imgur.com/DlxJIKV.gif)](https://youtu.be/Sjzkpg1OJuY)
---
**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

@@ -0,0 +1,24 @@
{
"name": "@bot-whatsapp/database",
"version": "0.0.20-alpha.0",
"description": "Esto es el conector a mysql, pg, mongo",
"main": "./lib/mock/index.cjs",
"keywords": [],
"author": "",
"license": "ISC",
"files": [
"./lib/"
],
"dependencies": {
"dotenv": "^16.0.3",
"mongodb": "^4.11.0",
"mysql2": "^2.3.3",
"stormdb": "^0.6.0"
},
"exports": {
"./mock": "./lib/mock/index.cjs",
"./mongo": "./lib/mongo/index.cjs",
"./json-file": "./lib/json-file/index.cjs",
"./mysql": "./lib/mysql/index.cjs"
}
}

View File

@@ -0,0 +1,41 @@
const banner = require('../../config/banner.rollup.json')
const commonjs = require('@rollup/plugin-commonjs')
const { join } = require('path')
module.exports = [
{
input: join(__dirname, 'src', 'mock', 'index.js'),
output: {
banner: banner['banner.output'].join(''),
file: join(__dirname, 'lib', 'mock', 'index.cjs'),
format: 'cjs',
},
plugins: [commonjs()],
},
{
input: join(__dirname, 'src', 'mongo', 'index.js'),
output: {
banner: banner['banner.output'].join(''),
file: join(__dirname, 'lib', 'mongo', 'index.cjs'),
format: 'cjs',
},
plugins: [commonjs()],
},
{
input: join(__dirname, 'src', 'mysql', 'index.js'),
output: {
banner: banner['banner.output'].join(''),
file: join(__dirname, 'lib', 'mysql', 'index.cjs'),
format: 'cjs',
},
plugins: [commonjs()],
},
{
input: join(__dirname, 'src', 'json-file', 'index.js'),
output: {
banner: banner['banner.output'].join(''),
file: join(__dirname, 'lib', 'json-file', 'index.cjs'),
},
plugins: [commonjs()],
},
]

View File

@@ -0,0 +1,48 @@
const path = require('path')
const StormDB = require('stormdb')
const engine = new StormDB.localFileEngine(
path.join(process.cwd(), './db.stormdb')
)
class JsonFileAdapter {
db
listHistory = []
constructor() {
this.init().then()
}
init() {
return new Promise((resolve) => {
this.db = new StormDB(engine)
this.db.default({ history: [] })
resolve(this.db)
})
}
getPrevByNumber = async (from) => {
const response = await this.db.get('history')
const { history } = response.state
if (!history.length) {
return null
}
const result = history.filter((res) => res.from === from).pop()
return {
...result,
}
}
save = async (ctx) => {
await this.db
.get('history')
.push({ ...ctx })
.save()
console.log('Guardado en DB...', ctx)
this.listHistory.push(ctx)
}
}
module.exports = JsonFileAdapter

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