Skip to content

Commit

Permalink
chore(release): 0.1.21
Browse files Browse the repository at this point in the history
chore(release): 0.1.21
  • Loading branch information
leifermendez authored Feb 5, 2023
2 parents 186c48d + 9a63fa5 commit 652d0ef
Show file tree
Hide file tree
Showing 97 changed files with 659 additions and 1,008 deletions.
2 changes: 1 addition & 1 deletion .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit
npm run lint:fix && npx --no -- commitlint --edit
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
packages/**/lib
packages/docs/*.json
packages/docs/
**/.git
**/.svn
**/.hg
Expand Down
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"recommendations": ["xyc.vscode-mdx-preview"]
"recommendations": ["xyc.vscode-mdx-preview", "vivaxy.vscode-conventional-commits", "mhutchie.git-graph"]
}
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

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.20](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.19...v0.1.20) (2023-02-05)


### Features

* **cli:** :fire: add regex expression in addKeyworkd ([e34560c](https://github.com/leifermendez/bot-whatsapp/commit/e34560c77d4852d2e90930f0858e51aa67d4eeab))
* **provider:** :zap: possible get class provider ([76ba717](https://github.com/leifermendez/bot-whatsapp/commit/76ba717927a75b3d6299206aa0b8aee2bc25b726))


### Bug Fixes

* **cli:** :zap: working flowDynamic test ([c0113ca](https://github.com/leifermendez/bot-whatsapp/commit/c0113ca49295aff220d8defcb53f2ba7f2872d75))
* **cli:** :zap: working flowDynamic test ([aef52d2](https://github.com/leifermendez/bot-whatsapp/commit/aef52d2694fa6616d614338643db198b4f7f1fe8))
* **cli:** :zap: working flowDynamic test ([f769320](https://github.com/leifermendez/bot-whatsapp/commit/f76932021ce968d93241b55cfcdb8ae0e0e6c934))
* **cli:** :zap: working flowDynamic test ([23e09ef](https://github.com/leifermendez/bot-whatsapp/commit/23e09efaeccaf51018c55da492edff45b625f0a9))
* **database:** add support emoji in mysql ([9311aa0](https://github.com/leifermendez/bot-whatsapp/commit/9311aa0a65623a1bf40e96207a281625154dae90))
* **database:** fix naming ([cd082f2](https://github.com/leifermendez/bot-whatsapp/commit/cd082f235012cd5f5844c6437f51711beee0c865))
* **database:** fix naming ([1afc3ba](https://github.com/leifermendez/bot-whatsapp/commit/1afc3ba182070713b5bec40eaab0fa1f680830cd))
* **database:** fix naming ([c9831d2](https://github.com/leifermendez/bot-whatsapp/commit/c9831d202ab2c85f15a0247cd2a2426bc435270c))
* **provider:** :zap: baily wa.link ([96c2bff](https://github.com/leifermendez/bot-whatsapp/commit/96c2bffd093269be8e39474a84c156938504a6cb))

### [0.1.19](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.18...v0.1.19) (2023-01-29)


Expand Down
7 changes: 1 addition & 6 deletions __test__/01-case.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ const { test } = require('uvu')
const assert = require('uvu/assert')
const MOCK_DB = require('../packages/database/src/mock')
const PROVIDER_DB = require('../packages/provider/src/mock')
const {
addKeyword,
createBot,
createFlow,
createProvider,
} = require('../packages/bot')
const { addKeyword, createBot, createFlow, createProvider } = require('../packages/bot/index')

test(`[Caso - 01] Flow Basico`, async () => {
const [VALUE_A, VALUE_B] = ['hola', 'buenas']
Expand Down
38 changes: 10 additions & 28 deletions __test__/05-case.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ const { test } = require('uvu')
const assert = require('uvu/assert')
const MOCK_DB = require('../packages/database/src/mock')
const PROVIDER_DB = require('../packages/provider/src/mock')
const {
addKeyword,
createBot,
createFlow,
createProvider,
} = require('../packages/bot/index')
const { addKeyword, createBot, createFlow, createProvider } = require('../packages/bot/index')

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

test(`[Caso - 05] Continuar Flujo (continueFlow)`, async () => {
const MOCK_VALUES = [
'¿CUal es tu email?',
'Continuamos....',
'¿Cual es tu edad?',
]
const MOCK_VALUES = ['¿CUal es tu email?', 'Continuamos....', '¿Cual es tu edad?']
const provider = createProvider(PROVIDER_DB)
const database = new MOCK_DB()

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

if (validation) {
const getDataFromApi = await fakeHTTP([
'Gracias por tu email se ha validado de manera correcta',
])
const getDataFromApi = await fakeHTTP(['Gracias por tu email se ha validado de manera correcta'])
return flowDynamic(getDataFromApi)
}
return fallBack(validation)
}
)
.addAnswer(MOCK_VALUES[1])
.addAnswer(
MOCK_VALUES[2],
{ capture: true },
async (ctx, { flowDynamic, fallBack }) => {
if (ctx.body !== '18') {
await delay(50)
return fallBack(false, 'Ups creo que no eres mayor de edad')
}
return flowDynamic('Bien tu edad es correcta!')
.addAnswer(MOCK_VALUES[2], { capture: true }, async (ctx, { flowDynamic, fallBack }) => {
if (ctx.body !== '18') {
await delay(50)
return fallBack(false, 'Ups creo que no eres mayor de edad')
}
)
return flowDynamic('Bien tu edad es correcta!')
})
.addAnswer('Puedes pasar')

createBot({
Expand Down Expand Up @@ -98,10 +83,7 @@ test(`[Caso - 05] Continuar Flujo (continueFlow)`, async () => {
assert.is('this is not email value', getHistory[1])
assert.is(MOCK_VALUES[0], getHistory[2])
assert.is('[email protected]', getHistory[3])
assert.is(
'1 Gracias por tu email se ha validado de manera correcta',
getHistory[4]
)
assert.is('1 Gracias por tu email se ha validado de manera correcta', getHistory[4])
assert.is(MOCK_VALUES[1], getHistory[5])
assert.is(MOCK_VALUES[2], getHistory[6])
assert.is('20', getHistory[7])
Expand Down
92 changes: 92 additions & 0 deletions __test__/07-case.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const { test } = require('uvu')
const assert = require('uvu/assert')
const MOCK_DB = require('../packages/database/src/mock')
const PROVIDER_DB = require('../packages/provider/src/mock')
const { addKeyword, createBot, createFlow, createProvider } = require('../packages/bot/index')

/**
* Falsear peticion async
* @param {*} fakeData
* @returns
*/
const fakeHTTP = async (fakeData = []) => {
await delay(5)
const data = fakeData.map((u, i) => ({ body: `${i + 1} ${u}` }))
return Promise.resolve(data)
}

let STATE_APP = {}

test(`[Caso - 07] Retornar estado`, async () => {
const MOCK_VALUES = ['¿Cual es tu nombre?', '¿Cual es tu edad?', 'Tu datos son:']
const provider = createProvider(PROVIDER_DB)
const database = new MOCK_DB()

const flujoPrincipal = addKeyword(['hola'])
.addAnswer(
MOCK_VALUES[0],
{
capture: true,
},
async (ctx, { flowDynamic, fallBack }) => {
STATE_APP[ctx.from] = { ...STATE_APP[ctx.from], name: ctx.body }

flowDynamic('Gracias por tu nombre!')
}
)
.addAnswer(
MOCK_VALUES[1],
{
capture: true,
},
async (ctx, { flowDynamic, endFlow }) => {
STATE_APP[ctx.from] = { ...STATE_APP[ctx.from], age: ctx.body }

await flowDynamic('Gracias por tu edad!')
}
)
.addAnswer(MOCK_VALUES[2], null, async (ctx, { flowDynamic }) => {
flowDynamic(`Nombre: ${STATE_APP[ctx.from].name} Edad: ${STATE_APP[ctx.from].age}`)
})
.addAnswer('🤖🤖 Gracias por tu participacion')

createBot({
database,
flow: createFlow([flujoPrincipal]),
provider,
})

provider.delaySendMessage(0, 'message', {
from: '000',
body: 'hola',
})

provider.delaySendMessage(20, 'message', {
from: '000',
body: 'Leifer',
})

provider.delaySendMessage(40, 'message', {
from: '000',
body: '90',
})

await delay(1200)
const getHistory = database.listHistory.map((i) => i.answer)
assert.is(MOCK_VALUES[0], getHistory[0])
assert.is('Leifer', getHistory[1])
assert.is('Gracias por tu nombre!', getHistory[2])
assert.is('¿Cual es tu edad?', getHistory[3])
assert.is('90', getHistory[4])
assert.is('Gracias por tu edad!', getHistory[5])
assert.is('Tu datos son:', getHistory[6])
assert.is('Nombre: Leifer Edad: 90', getHistory[7])
assert.is('🤖🤖 Gracias por tu participacion', getHistory[8])
assert.is(undefined, getHistory[9])
})

test.run()

function delay(ms) {
return new Promise((res) => setTimeout(res, ms))
}
43 changes: 43 additions & 0 deletions __test__/08-case.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const { test } = require('uvu')
const assert = require('uvu/assert')
const MOCK_DB = require('../packages/database/src/mock')
const PROVIDER_DB = require('../packages/provider/src/mock')
const { addKeyword, createBot, createFlow, createProvider } = require('../packages/bot/index')

test(`[Caso - 08] Regular expression on keyword`, async () => {
const provider = createProvider(PROVIDER_DB)
const database = new MOCK_DB()

const REGEX_CREDIT_NUMBER = `/(^4[0-9]{12}(?:[0-9]{3})?$)|(^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$)|(3[47][0-9]{13})|(^3(?:0[0-5]|[68][0-9])[0-9]{11}$)|(^6(?:011|5[0-9]{2})[0-9]{12}$)|(^(?:2131|1800|35\d{3})\d{11}$)/gm`
const flujoPrincipal = addKeyword(REGEX_CREDIT_NUMBER, { regex: true })
.addAnswer(`Gracias por proporcionar un numero de tarjeta valido`)
.addAnswer('Fin!')

createBot({
database,
flow: createFlow([flujoPrincipal]),
provider,
})

provider.delaySendMessage(0, 'message', {
from: '000',
body: 'hola',
})

provider.delaySendMessage(20, 'message', {
from: '000',
body: '374245455400126',
})

await delay(40)
const getHistory = database.listHistory.map((i) => i.answer)
assert.is('Gracias por proporcionar un numero de tarjeta valido', getHistory[0])
assert.is('Fin!', getHistory[1])
assert.is(undefined, getHistory[2])
})

test.run()

function delay(ms) {
return new Promise((res) => setTimeout(res, ms))
}
41 changes: 41 additions & 0 deletions __test__/09-case.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const { test } = require('uvu')
const assert = require('uvu/assert')
const MOCK_DB = require('../packages/database/src/mock')
const PROVIDER_MOCK = require('../packages/provider/src/mock')
const { addKeyword, createBot, createFlow, createProvider } = require('../packages/bot/index')

let PROVIDER = undefined

test(`[Caso - 09] Check provider WS`, async () => {
const [VALUE_A, VALUE_B] = ['hola', 'buenas']

const flow = addKeyword(VALUE_A).addAnswer(VALUE_B, null, async (_, { provider }) => {
PROVIDER = provider
})
const provider = createProvider(PROVIDER_MOCK)
const database = new MOCK_DB()

createBot({
database,
flow: createFlow([flow]),
provider,
})

provider.delaySendMessage(100, 'message', {
from: '000',
body: VALUE_A,
})

await delay(100)

const prevMsg = database.getPrevByNumber('000')

assert.is(prevMsg.answer, VALUE_B)
assert.is(typeof PROVIDER.sendMessage, 'function')
})

test.run()

function delay(ms) {
return new Promise((res) => setTimeout(res, ms))
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bot-whatsapp/root",
"version": "0.1.19",
"version": "0.1.20",
"description": "Bot de wahtsapp open source para MVP o pequeños negocios",
"main": "app.js",
"private": true,
Expand Down
Loading

0 comments on commit 652d0ef

Please sign in to comment.