jRuby allows a developer to run Ruby applications in a Java Virtual Machine. Adam Kalsey from Tropo explains why you'd want to do that, what jRuby can do for you, and show how Tropo uses jRuby in building a real-time communications cloud service. Includes how to deploy apps on jRuby, and some of the pitfalls to watch out for.
21. answer
options = { :choices => '1 (1,sales), 2 (2 support)' }
result = ask 'Hi. For sales, say Sales or press 1. For
support, say Support or press 2.', options
if result.name == 'choice'
case result.value
when '1'
say 'Your money is important to us.'
when '2'
say 'Your call will be ignored in the order received.'
end
end
hangup
22. def ask (ttsOrUrl, options={})
...
result = call.prompt(ttsOrUrl,
localOptions[:voice],
localOptions[:recognizer],
localOptions[:bargein],
localOptions[:grammar],
localOptions[:terminator],
localOptions[:choiceConfidence],
localOptions[:choiceMode],
localOptions[:timeout])
if (result.get('event.name'))
...
23. public Map<String, Object> prompt(final String ttsOrUrl,
final String ttsResourceName, ...) {
LOG.info(this + "->prompt("" + ttsOrUrl +
"", ... )");
Map<String, Object> retval = null;
try {
assertReady("prompt", Call.State.ANSWERED);
if (!Strings.isEmpty(termChar) && Strings.isEmpty
(grammar)) {
log("termChar with no grammar. Setting grammar to
equal termChar: " + termChar);
grammar = termChar;
termChar = null;
}
...