Skip to content

Instantly share code, notes, and snippets.

@honzabrecka
Created May 7, 2016 21:43
Show Gist options
  • Save honzabrecka/8dd43fae6e1e08a2506f7228f02b8389 to your computer and use it in GitHub Desktop.
Save honzabrecka/8dd43fae6e1e08a2506f7228f02b8389 to your computer and use it in GitHub Desktop.
const ask = (questions, end) => (response, convo) => {
let responses = {}
const $ask = (questions) => {
const {id, question, validate} = questions.shift()
convo.ask(question, (response, convo) => {
try {
responses[id] = response
typeof validate === 'function' && validate(response, responses)
if (questions.length === 0)
convo.say(end(responses))
else
$ask(questions)
} catch (err) {
convo.say(err.message)
} finally {
convo.next()
}
})
}
$ask(questions)
}
module.exports = {ask}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment