-
-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release/production
- Loading branch information
Showing
43 changed files
with
1,055 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.