@rotorsoft/flow
Version:
A minimalistic state machine
19 lines (16 loc) • 692 B
JavaScript
const root = (state, scope, { params, actions }) => {
const { name } = params
return [
actions.authenticate,
function next({ authenticate, verifyPhone, canComeToThePhone }) {
const greet = { say: `Hello ${name}. How are you today?`, authenticated: true }
if (authenticate.answer === 'yes') return greet
if (verifyPhone && verifyPhone.answer === 'yes') {
if (canComeToThePhone && canComeToThePhone.answer && canComeToThePhone.answer !== 'no') return greet
return { say: `Hi. Please tell ${name} we will be calling back soon.` }
}
return { say: "I'm sorry for the inconvenience." }
}
]
}
module.exports = root