Created
May 29, 2013 14:44
-
-
Save imsickofmaps/5670816 to your computer and use it in GitHub Desktop.
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
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 SmsSender() { | |
var self = this; | |
// The first state to enter | |
StateCreator.call(self, 'first_state'); | |
self.send_sms = function(im, content, to_addr) { | |
var sms_tag = im.config.sms_tag; | |
if (!sms_tag) return success(true); | |
var p = im.api_request("outbound.send_to_tag", { | |
to_addr: to_addr, | |
content: content, | |
tagpool: sms_tag[0], | |
tag: sms_tag[1] | |
}); | |
return p; | |
}; | |
self.add_state(new FreeText( | |
"first_state", | |
"end_state", | |
"Say something please..." | |
)); | |
self.add_creator('end_state', function(state_name, im) { | |
return new EndState( | |
"end_state", | |
"You said '" + im.get_user_answer('first_state') + "'. Thank you and bye bye!", | |
"first_state" | |
); | |
}); | |
} | |
// launch app | |
var states = new SmsSender(); | |
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