Last active
December 22, 2015 16:48
-
-
Save justinvdm/6501516 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var vumigo = require('vumigo_v01'); | |
var jed = require('jed'); | |
if (typeof api === 'undefined') { | |
// testing hook (supplies api when it is not passed in by the real sandbox) | |
var api = this.api = new vumigo.dummy_api.DummyApi(); | |
} | |
var Promise = vumigo.promise.Promise; | |
var success = vumigo.promise.success; | |
var Choice = vumigo.states.Choice; | |
var ChoiceState = vumigo.states.ChoiceState; | |
var FreeText = vumigo.states.FreeText; | |
var EndState = vumigo.states.EndState; | |
var InteractionMachine = vumigo.state_machine.InteractionMachine; | |
var StateCreator = vumigo.state_machine.StateCreator; | |
function Simple() { | |
var self = this; | |
// The first state to enter | |
StateCreator.call(self, 'initial_state'); | |
self.add_state(new ChoiceState( | |
'initial_state', | |
function(choice) { return choice.value; }, | |
'What would you like?', | |
[new Choice('state_little', 'Spam bacon sausage and spam'), | |
new Choice('state_some', 'Spam egg spam spam bacon and spam'), | |
new Choice('state_lots', 'Spam sausage spam spam bacon spam spam tomato and spam')]) | |
); | |
self.add_state(new EndState( | |
'state_little', | |
'Ok, bye.', | |
'initial_state')); | |
self.add_state(new FreeText( | |
'state_some', | |
function(content, done) { done('state_response_why_some'); }, | |
'Why?')); | |
self.add_state(new EndState( | |
'state_response_why_some', | |
'Cool, bye.', | |
'initial_state')); | |
self.add_creator('state_lots', function(state_name, im) { | |
var n = Math.floor(Math.random() * (10 - 4) + 4); | |
var spams = []; | |
while (n--) { spams.push('spam'); } | |
new EndState( | |
state_name, | |
'...' + spams.join(' ') + '...', | |
'initial_state'); | |
}); | |
} | |
// launch app | |
var states = new Simple(); | |
var im = new InteractionMachine(api, states); | |
im.attach(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment