Skip to content

Commit

Permalink
release 0.1.33
Browse files Browse the repository at this point in the history
Release/production
  • Loading branch information
leifermendez authored Oct 2, 2023
2 parents cae433b + f72df9e commit 7bdd8e9
Show file tree
Hide file tree
Showing 43 changed files with 1,055 additions and 280 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ En la consola encontraras los pasos a seguir -->
![](https://i.imgur.com/dC6lEwy.png)


> __NOTA:__ [Eres libre de aportar informacion a este documento o arreglar ortografia 🤣](
> __NOTA:__ [Eres libre de aportar informacion inexacta a este documento o arreglar horrores de ortografia que dificultan la comprensión. 🤣](
https://github.com/codigoencasa/bot-whatsapp/edit/dev/CONTRIBUTING.md)

------
Expand Down
103 changes: 97 additions & 6 deletions __test__/0.1.7-case.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ suiteCase(`Debe retornar un mensaje resumen`, async ({ database, provider }) =>
capture: true,
},
async (ctx, { flowDynamic, state }) => {
state.update({ name: ctx.body })
flowDynamic('Gracias por tu nombre!')
await state.update({ name: ctx.body })
await flowDynamic('Gracias por tu nombre!')
}
)
.addAnswer(
Expand All @@ -28,14 +28,14 @@ suiteCase(`Debe retornar un mensaje resumen`, async ({ database, provider }) =>
capture: true,
},
async (ctx, { flowDynamic, state }) => {
state.update({ age: ctx.body })
const myState = state.getMyState()
await flowDynamic(`Gracias por tu edad! ${myState.name}`)
await state.update({ age: ctx.body })
const name = state.get('name')
await flowDynamic(`Gracias por tu edad! ${name}`)
}
)
.addAnswer(MOCK_VALUES[2], null, async (_, { flowDynamic, state }) => {
const myState = state.getMyState()
flowDynamic(`Nombre: ${myState.name} Edad: ${myState.age}`)
await flowDynamic(`Nombre: ${myState.name} Edad: ${myState.age}`)
})
.addAnswer('🤖🤖 Gracias por tu participacion')

Expand Down Expand Up @@ -98,4 +98,95 @@ suiteCase(`Debe retornar un mensaje resumen`, async ({ database, provider }) =>
assert.is(undefined, getHistory[18])
})

suiteCase(`Manejando globalState`, async ({ database, provider }) => {
const MOCK_VALUES = ['¿Cual es tu nombre?', '¿Cual es tu edad?', 'Tu datos son:']

const flujoPrincipal = addKeyword(['hola'])
.addAnswer(
MOCK_VALUES[0],
{
capture: true,
},
async (ctx, { flowDynamic, state, globalState }) => {
await state.update({ name: ctx.body })
await globalState.update({ value: 'Soy el valor global' })
await flowDynamic('Gracias por tu nombre!')
}
)
.addAnswer(
MOCK_VALUES[1],
{
capture: true,
},
async (ctx, { flowDynamic, state }) => {
await state.update({ age: ctx.body })
const name = state.get('name')
await flowDynamic(`Gracias por tu edad! ${name}`)
}
)
.addAnswer(MOCK_VALUES[2], null, async (_, { flowDynamic, state, globalState }) => {
const myState = state.getMyState()
const value = globalState.get('value')
await flowDynamic(`Nombre: ${myState.name} Edad: ${myState.age} Valor Global: ${value}`)
})
.addAnswer('🤖🤖 Gracias por tu participacion')

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

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

await provider.delaySendMessage(5, 'message', {
from: '001',
body: 'hola',
})

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

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

await provider.delaySendMessage(20, 'message', {
from: '001',
body: 'Maria',
})

await provider.delaySendMessage(25, 'message', {
from: '001',
body: '100',
})

await delay(1000)
const getHistory = database.listHistory.map((i) => i.answer)
assert.is(MOCK_VALUES[0], getHistory[0])
assert.is('¿Cual es tu nombre?', getHistory[1])
assert.is('Leifer', getHistory[2])
assert.is('Gracias por tu nombre!', getHistory[3])
assert.is('¿Cual es tu edad?', getHistory[4])
assert.is('90', getHistory[5])
assert.is('Gracias por tu edad! Leifer', getHistory[6])
assert.is('Tu datos son:', getHistory[7])
assert.is('Nombre: Leifer Edad: 90 Valor Global: Soy el valor global', getHistory[8])
assert.is('🤖🤖 Gracias por tu participacion', getHistory[9])
assert.is('Maria', getHistory[10])
assert.is('Gracias por tu nombre!', getHistory[11])
assert.is('¿Cual es tu edad?', getHistory[12])
assert.is('100', getHistory[13])
assert.is('Gracias por tu edad! Maria', getHistory[14])
assert.is('Tu datos son:', getHistory[15])
assert.is('Nombre: Maria Edad: 100 Valor Global: Soy el valor global', getHistory[16])
assert.is('🤖🤖 Gracias por tu participacion', getHistory[17])
assert.is(undefined, getHistory[18])
})
suiteCase.run()
11 changes: 7 additions & 4 deletions __test__/0.1.8-case.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ suiteCase(`Debe ejecutar accion con captura`, async ({ database, provider }) =>

await delay(1000)
const getHistory = database.listHistory.map((i) => i.answer)
assert.is('Buenas! ¿Cual es tu nombre?', getHistory[0])
assert.is('Gracias por tu nombre!: Leifer', getHistory[3])
assert.is('Chao!', getHistory[4])
assert.is(undefined, getHistory[5])
assert.is('__call_action__', getHistory[0])
assert.is('Buenas! ¿Cual es tu nombre?', getHistory[1])
assert.is('__capture_only_intended__', getHistory[2])
assert.is('Leifer', getHistory[3])
assert.is('Gracias por tu nombre!: Leifer', getHistory[4])
assert.is('Chao!', getHistory[5])
assert.is(undefined, getHistory[6])
})

suiteCase.run()
44 changes: 44 additions & 0 deletions __test__/0.1.9-case.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const { suite } = require('uvu')
const assert = require('uvu/assert')
const { addKeyword, createBot, createFlow } = require('../packages/bot/index')
const { setup, clear, delay } = require('../__mocks__/env')

const suiteCase = suite('Flujo: flowDynamic (delay)')

suiteCase.before.each(setup)
suiteCase.after.each(clear)

suiteCase(`Delay en los flowDynamic`, async ({ database, provider }) => {
const flujoPrincipal = addKeyword(['hola'])
.addAction(async (_, { flowDynamic }) => {
await flowDynamic('Buenas! ¿Cual es tu nombre? este mensaje debe tener delay 1000', { delay: 1000 })
await flowDynamic([{ body: 'Todo bien?', delay: 850 }])
})
.addAnswer('Bien!', null, async (_, { flowDynamic }) => {
await flowDynamic('si nada')
})
.addAnswer('Chao!')

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

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

await delay(2000)
const getHistory = database.listHistory.map((i) => i.answer)
assert.is('__call_action__', getHistory[0])
assert.is('Buenas! ¿Cual es tu nombre? este mensaje debe tener delay 1000', getHistory[1])
assert.is('Todo bien?', getHistory[2])
assert.is('Bien!', getHistory[3])
assert.is('si nada', getHistory[4])
assert.is('Chao!', getHistory[5])
assert.is(undefined, getHistory[6])
})

suiteCase.run()
61 changes: 61 additions & 0 deletions __test__/0.2.0-case.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const { suite } = require('uvu')
const assert = require('uvu/assert')
const { addKeyword, createBot, createFlow } = require('../packages/bot/index')
const { setup, clear, delay } = require('../__mocks__/env')

const suiteCase = suite('Flujo: addAction (capture) encadenados')

suiteCase.before.each(setup)
suiteCase.after.each(clear)

suiteCase(`Encadenanos addAction con captures`, async ({ database, provider }) => {
const flujoPrincipal = addKeyword(['hola'])
.addAction(async (ctx, { flowDynamic }) => {
await flowDynamic(`Hola! primer flow dynamic. respondeme algo`)
})
.addAction({ capture: true }, async (ctx, { flowDynamic, state }) => {
const reply = ctx.body
await state.update({ reply })
await flowDynamic(`Esto me respondieste ${reply}`)
})
.addAction(async (ctx, { flowDynamic }) => {
await flowDynamic(`Hola! segundo flow dynamic. respondeme algo`)
})
.addAction({ capture: true }, async (ctx, { flowDynamic, state }) => {
const currentState = state.getMyState()?.reply
const reply = ctx.body
await state.update({ reply: currentState + ' ' + reply })
await flowDynamic(`Esto me respondieste ${reply}`)
})
.addAnswer('Chao')

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

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

await provider.delaySendMessage(10, 'message', {
from: '000',
body: 'ping',
})

await delay(2000)
const getHistory = database.listHistory.map((i) => i.answer)
assert.is('__call_action__', getHistory[0])
assert.is('Hola! primer flow dynamic. respondeme algo', getHistory[1])
assert.is('__capture_only_intended__', getHistory[2])
assert.is('ping', getHistory[3])
assert.is('Esto me respondieste ping', getHistory[4])
assert.is('__call_action__', getHistory[5])
assert.is('Hola! segundo flow dynamic. respondeme algo', getHistory[6])
assert.is('__capture_only_intended__', getHistory[7])
assert.is(undefined, getHistory[8])
})

suiteCase.run()
Loading

0 comments on commit 7bdd8e9

Please sign in to comment.