Skip to content

Commit 652d0ef

Browse files
authored
chore(release): 0.1.21
chore(release): 0.1.21
2 parents 186c48d + 9a63fa5 commit 652d0ef

File tree

97 files changed

+659
-1008
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+659
-1008
lines changed

.husky/commit-msg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env sh
22
. "$(dirname -- "$0")/_/husky.sh"
33

4-
npx --no -- commitlint --edit
4+
npm run lint:fix && npx --no -- commitlint --edit

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
packages/**/lib
2-
packages/docs/*.json
2+
packages/docs/
33
**/.git
44
**/.svn
55
**/.hg

.vscode/extensions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"recommendations": ["xyc.vscode-mdx-preview"]
2+
"recommendations": ["xyc.vscode-mdx-preview", "vivaxy.vscode-conventional-commits", "mhutchie.git-graph"]
33
}

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@
22

33
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.
44

5+
### [0.1.20](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.19...v0.1.20) (2023-02-05)
6+
7+
8+
### Features
9+
10+
* **cli:** :fire: add regex expression in addKeyworkd ([e34560c](https://github.com/leifermendez/bot-whatsapp/commit/e34560c77d4852d2e90930f0858e51aa67d4eeab))
11+
* **provider:** :zap: possible get class provider ([76ba717](https://github.com/leifermendez/bot-whatsapp/commit/76ba717927a75b3d6299206aa0b8aee2bc25b726))
12+
13+
14+
### Bug Fixes
15+
16+
* **cli:** :zap: working flowDynamic test ([c0113ca](https://github.com/leifermendez/bot-whatsapp/commit/c0113ca49295aff220d8defcb53f2ba7f2872d75))
17+
* **cli:** :zap: working flowDynamic test ([aef52d2](https://github.com/leifermendez/bot-whatsapp/commit/aef52d2694fa6616d614338643db198b4f7f1fe8))
18+
* **cli:** :zap: working flowDynamic test ([f769320](https://github.com/leifermendez/bot-whatsapp/commit/f76932021ce968d93241b55cfcdb8ae0e0e6c934))
19+
* **cli:** :zap: working flowDynamic test ([23e09ef](https://github.com/leifermendez/bot-whatsapp/commit/23e09efaeccaf51018c55da492edff45b625f0a9))
20+
* **database:** add support emoji in mysql ([9311aa0](https://github.com/leifermendez/bot-whatsapp/commit/9311aa0a65623a1bf40e96207a281625154dae90))
21+
* **database:** fix naming ([cd082f2](https://github.com/leifermendez/bot-whatsapp/commit/cd082f235012cd5f5844c6437f51711beee0c865))
22+
* **database:** fix naming ([1afc3ba](https://github.com/leifermendez/bot-whatsapp/commit/1afc3ba182070713b5bec40eaab0fa1f680830cd))
23+
* **database:** fix naming ([c9831d2](https://github.com/leifermendez/bot-whatsapp/commit/c9831d202ab2c85f15a0247cd2a2426bc435270c))
24+
* **provider:** :zap: baily wa.link ([96c2bff](https://github.com/leifermendez/bot-whatsapp/commit/96c2bffd093269be8e39474a84c156938504a6cb))
25+
526
### [0.1.19](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.18...v0.1.19) (2023-01-29)
627

728

__test__/01-case.test.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ const { test } = require('uvu')
22
const assert = require('uvu/assert')
33
const MOCK_DB = require('../packages/database/src/mock')
44
const PROVIDER_DB = require('../packages/provider/src/mock')
5-
const {
6-
addKeyword,
7-
createBot,
8-
createFlow,
9-
createProvider,
10-
} = require('../packages/bot')
5+
const { addKeyword, createBot, createFlow, createProvider } = require('../packages/bot/index')
116

127
test(`[Caso - 01] Flow Basico`, async () => {
138
const [VALUE_A, VALUE_B] = ['hola', 'buenas']

__test__/05-case.test.js

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ const { test } = require('uvu')
22
const assert = require('uvu/assert')
33
const MOCK_DB = require('../packages/database/src/mock')
44
const PROVIDER_DB = require('../packages/provider/src/mock')
5-
const {
6-
addKeyword,
7-
createBot,
8-
createFlow,
9-
createProvider,
10-
} = require('../packages/bot/index')
5+
const { addKeyword, createBot, createFlow, createProvider } = require('../packages/bot/index')
116

127
/**
138
* Falsear peticion async
@@ -21,11 +16,7 @@ const fakeHTTP = async (fakeData = []) => {
2116
}
2217

2318
test(`[Caso - 05] Continuar Flujo (continueFlow)`, async () => {
24-
const MOCK_VALUES = [
25-
'¿CUal es tu email?',
26-
'Continuamos....',
27-
'¿Cual es tu edad?',
28-
]
19+
const MOCK_VALUES = ['¿CUal es tu email?', 'Continuamos....', '¿Cual es tu edad?']
2920
const provider = createProvider(PROVIDER_DB)
3021
const database = new MOCK_DB()
3122

@@ -39,26 +30,20 @@ test(`[Caso - 05] Continuar Flujo (continueFlow)`, async () => {
3930
const validation = ctx.body.includes('@')
4031

4132
if (validation) {
42-
const getDataFromApi = await fakeHTTP([
43-
'Gracias por tu email se ha validado de manera correcta',
44-
])
33+
const getDataFromApi = await fakeHTTP(['Gracias por tu email se ha validado de manera correcta'])
4534
return flowDynamic(getDataFromApi)
4635
}
4736
return fallBack(validation)
4837
}
4938
)
5039
.addAnswer(MOCK_VALUES[1])
51-
.addAnswer(
52-
MOCK_VALUES[2],
53-
{ capture: true },
54-
async (ctx, { flowDynamic, fallBack }) => {
55-
if (ctx.body !== '18') {
56-
await delay(50)
57-
return fallBack(false, 'Ups creo que no eres mayor de edad')
58-
}
59-
return flowDynamic('Bien tu edad es correcta!')
40+
.addAnswer(MOCK_VALUES[2], { capture: true }, async (ctx, { flowDynamic, fallBack }) => {
41+
if (ctx.body !== '18') {
42+
await delay(50)
43+
return fallBack(false, 'Ups creo que no eres mayor de edad')
6044
}
61-
)
45+
return flowDynamic('Bien tu edad es correcta!')
46+
})
6247
.addAnswer('Puedes pasar')
6348

6449
createBot({
@@ -98,10 +83,7 @@ test(`[Caso - 05] Continuar Flujo (continueFlow)`, async () => {
9883
assert.is('this is not email value', getHistory[1])
9984
assert.is(MOCK_VALUES[0], getHistory[2])
10085
assert.is('[email protected]', getHistory[3])
101-
assert.is(
102-
'1 Gracias por tu email se ha validado de manera correcta',
103-
getHistory[4]
104-
)
86+
assert.is('1 Gracias por tu email se ha validado de manera correcta', getHistory[4])
10587
assert.is(MOCK_VALUES[1], getHistory[5])
10688
assert.is(MOCK_VALUES[2], getHistory[6])
10789
assert.is('20', getHistory[7])

__test__/07-case.test.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
const { test } = require('uvu')
2+
const assert = require('uvu/assert')
3+
const MOCK_DB = require('../packages/database/src/mock')
4+
const PROVIDER_DB = require('../packages/provider/src/mock')
5+
const { addKeyword, createBot, createFlow, createProvider } = require('../packages/bot/index')
6+
7+
/**
8+
* Falsear peticion async
9+
* @param {*} fakeData
10+
* @returns
11+
*/
12+
const fakeHTTP = async (fakeData = []) => {
13+
await delay(5)
14+
const data = fakeData.map((u, i) => ({ body: `${i + 1} ${u}` }))
15+
return Promise.resolve(data)
16+
}
17+
18+
let STATE_APP = {}
19+
20+
test(`[Caso - 07] Retornar estado`, async () => {
21+
const MOCK_VALUES = ['¿Cual es tu nombre?', '¿Cual es tu edad?', 'Tu datos son:']
22+
const provider = createProvider(PROVIDER_DB)
23+
const database = new MOCK_DB()
24+
25+
const flujoPrincipal = addKeyword(['hola'])
26+
.addAnswer(
27+
MOCK_VALUES[0],
28+
{
29+
capture: true,
30+
},
31+
async (ctx, { flowDynamic, fallBack }) => {
32+
STATE_APP[ctx.from] = { ...STATE_APP[ctx.from], name: ctx.body }
33+
34+
flowDynamic('Gracias por tu nombre!')
35+
}
36+
)
37+
.addAnswer(
38+
MOCK_VALUES[1],
39+
{
40+
capture: true,
41+
},
42+
async (ctx, { flowDynamic, endFlow }) => {
43+
STATE_APP[ctx.from] = { ...STATE_APP[ctx.from], age: ctx.body }
44+
45+
await flowDynamic('Gracias por tu edad!')
46+
}
47+
)
48+
.addAnswer(MOCK_VALUES[2], null, async (ctx, { flowDynamic }) => {
49+
flowDynamic(`Nombre: ${STATE_APP[ctx.from].name} Edad: ${STATE_APP[ctx.from].age}`)
50+
})
51+
.addAnswer('🤖🤖 Gracias por tu participacion')
52+
53+
createBot({
54+
database,
55+
flow: createFlow([flujoPrincipal]),
56+
provider,
57+
})
58+
59+
provider.delaySendMessage(0, 'message', {
60+
from: '000',
61+
body: 'hola',
62+
})
63+
64+
provider.delaySendMessage(20, 'message', {
65+
from: '000',
66+
body: 'Leifer',
67+
})
68+
69+
provider.delaySendMessage(40, 'message', {
70+
from: '000',
71+
body: '90',
72+
})
73+
74+
await delay(1200)
75+
const getHistory = database.listHistory.map((i) => i.answer)
76+
assert.is(MOCK_VALUES[0], getHistory[0])
77+
assert.is('Leifer', getHistory[1])
78+
assert.is('Gracias por tu nombre!', getHistory[2])
79+
assert.is('¿Cual es tu edad?', getHistory[3])
80+
assert.is('90', getHistory[4])
81+
assert.is('Gracias por tu edad!', getHistory[5])
82+
assert.is('Tu datos son:', getHistory[6])
83+
assert.is('Nombre: Leifer Edad: 90', getHistory[7])
84+
assert.is('🤖🤖 Gracias por tu participacion', getHistory[8])
85+
assert.is(undefined, getHistory[9])
86+
})
87+
88+
test.run()
89+
90+
function delay(ms) {
91+
return new Promise((res) => setTimeout(res, ms))
92+
}

__test__/08-case.test.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const { test } = require('uvu')
2+
const assert = require('uvu/assert')
3+
const MOCK_DB = require('../packages/database/src/mock')
4+
const PROVIDER_DB = require('../packages/provider/src/mock')
5+
const { addKeyword, createBot, createFlow, createProvider } = require('../packages/bot/index')
6+
7+
test(`[Caso - 08] Regular expression on keyword`, async () => {
8+
const provider = createProvider(PROVIDER_DB)
9+
const database = new MOCK_DB()
10+
11+
const REGEX_CREDIT_NUMBER = `/(^4[0-9]{12}(?:[0-9]{3})?$)|(^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$)|(3[47][0-9]{13})|(^3(?:0[0-5]|[68][0-9])[0-9]{11}$)|(^6(?:011|5[0-9]{2})[0-9]{12}$)|(^(?:2131|1800|35\d{3})\d{11}$)/gm`
12+
const flujoPrincipal = addKeyword(REGEX_CREDIT_NUMBER, { regex: true })
13+
.addAnswer(`Gracias por proporcionar un numero de tarjeta valido`)
14+
.addAnswer('Fin!')
15+
16+
createBot({
17+
database,
18+
flow: createFlow([flujoPrincipal]),
19+
provider,
20+
})
21+
22+
provider.delaySendMessage(0, 'message', {
23+
from: '000',
24+
body: 'hola',
25+
})
26+
27+
provider.delaySendMessage(20, 'message', {
28+
from: '000',
29+
body: '374245455400126',
30+
})
31+
32+
await delay(40)
33+
const getHistory = database.listHistory.map((i) => i.answer)
34+
assert.is('Gracias por proporcionar un numero de tarjeta valido', getHistory[0])
35+
assert.is('Fin!', getHistory[1])
36+
assert.is(undefined, getHistory[2])
37+
})
38+
39+
test.run()
40+
41+
function delay(ms) {
42+
return new Promise((res) => setTimeout(res, ms))
43+
}

__test__/09-case.test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const { test } = require('uvu')
2+
const assert = require('uvu/assert')
3+
const MOCK_DB = require('../packages/database/src/mock')
4+
const PROVIDER_MOCK = require('../packages/provider/src/mock')
5+
const { addKeyword, createBot, createFlow, createProvider } = require('../packages/bot/index')
6+
7+
let PROVIDER = undefined
8+
9+
test(`[Caso - 09] Check provider WS`, async () => {
10+
const [VALUE_A, VALUE_B] = ['hola', 'buenas']
11+
12+
const flow = addKeyword(VALUE_A).addAnswer(VALUE_B, null, async (_, { provider }) => {
13+
PROVIDER = provider
14+
})
15+
const provider = createProvider(PROVIDER_MOCK)
16+
const database = new MOCK_DB()
17+
18+
createBot({
19+
database,
20+
flow: createFlow([flow]),
21+
provider,
22+
})
23+
24+
provider.delaySendMessage(100, 'message', {
25+
from: '000',
26+
body: VALUE_A,
27+
})
28+
29+
await delay(100)
30+
31+
const prevMsg = database.getPrevByNumber('000')
32+
33+
assert.is(prevMsg.answer, VALUE_B)
34+
assert.is(typeof PROVIDER.sendMessage, 'function')
35+
})
36+
37+
test.run()
38+
39+
function delay(ms) {
40+
return new Promise((res) => setTimeout(res, ms))
41+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bot-whatsapp/root",
3-
"version": "0.1.19",
3+
"version": "0.1.20",
44
"description": "Bot de wahtsapp open source para MVP o pequeños negocios",
55
"main": "app.js",
66
"private": true,

0 commit comments

Comments
 (0)