Tropo is an API and web service that allows developers to easily build voice and text communication applications using common programming languages like JavaScript, Ruby, Python, and Groovy. It provides capabilities for call control, text-to-speech, speech recognition, and integrating with web services. The document provides examples of "Hello World" programs, handling user input, conditional logic, and accessing data from external web services.
9. Developing with Voxeo XML-based Telephony Voxeo CallXML The easiest telephony markup ever devised Tool-based Telephony Voxeo Designer Easy web-based, Visio- like rapid app dev tool VoiceObjects Sophisticated service creation environment, personalization, analytics VoiceXML The only 100% compliant browser CCXML The world’s most proven CCXML engine A Voxeo Company API-based Telephony Tropo Mash-up style API in multiple language Java Media Control JSR 309 Java SIP Servlets JSR 116/289 A Voxeo Company Simpler apps, all skill levels Sophisticated apps
11. T.1: Hello World JavaScript and PHP answer(); say("Hello, world!"); hangup(); Ruby answer say "Hello, world!” hangup Groovy answer() say 'Hello, world!' hangup() Python answer() say("Hello, world !") hangup()
12. T.2: Asking for Input - JavaScript // ----------- // asking for input // ----------- answer(); result=ask( "Hi. For sales, press 1. For support, press 2.", {choices:"1, 2"} ); if (result.name=='choice') { if (result.value=="1") { say( "sales is not available right now.") } if (result.value=="2") { say( "support is currently on the other line." ) } } hangup();
13. T.3: Repeating the Question - Ruby # ----------- # repeating the question # ----------- answer options = { :choices => '1, 2', :repeat => 3 } result = ask 'For sales, press 1. For support, press 2.', options if result.name == 'choice' case result.value when '1' say 'sales is not available right now.' when '2' say 'support is currently on the other line.' end end hangup
14. T.4: Changing Timeouts - Groovy // ----------- // changing the default timeout // ----------- answer(); result=ask( "For sales, press 1. For support, press 2.", [choices:"1, 2",repeat:3, timeout:10 ] ); if (result.name=='choice') { if (result.value=="1") { say( "sales is not available right now.") } if (result.value=="2") { say( "support is currently on the other line." ) } } hangup();
15. T.5: Speech - Python # Using speech input instead of touch-tone answer() result = ask("Hi. For sales, say sales. For support, say support", {'choices':"sales, support", 'repeat':3}) if (result.name == 'choice'): if (result.value == "sales"): say("Sales is not available right now") if (result.value == "support"): say("Support is currently on the other line.") hangup()
16. T.6: Speech & DTMF - PHP <?php // ----------- // using both speech and touch-tone input // ----------- answer(); $result = ask( "For sales, just say sales or press 1. For support, say support or press 2.", array( "choices" => "sales( 1, sales), support( 2, support)" , "repeat" => 3 ) ); if ($result->name=="choice") { if ($result->value==" sales ") say( "sales is not available right now." ) ; if ($result->value==" support ") say( "support is currently on the other line." ) ; } hangup(); ?>
17. T.7: Transfer Time - Ruby # ----------- # connecting the call to another number () # ----------- answer options = { :choices => 'sales( 1, sales), support( 2, support)', :repeat => 3 } result = ask 'For sales, say sales or press 1. For support, say support or press 2.', options if result.name == 'choice' case result.value when 'sales' say 'Ok, let me transfer you to sales.' transfer '14075551212' when 'support' say 'Sure, let me get support. Please hold.' transfer '14085551212' end end hangup
18. T.8: Wrong Choices - Groovy answer(); result=ask( "For sales, say sales or press 1. For support, say support or press 2.", [choices:"sales( 1, sales), support( 2, support)", repeat:3] ); if (result.name=='choice') { if (result.value=="sales") { say( "Ok, let me transfer you to sales."); transfer( "14075551212"); } if (result.value=="support") { say( "Sure, let me get support. Please hold." ); transfer( "14085551212"); } } if( result.name=='badChoice') { say( "I'm not sure what you wanted. Goodbye.") }
19. T.9: Event Handlers - JavaScript answer(); result=ask( "For sales, just say sales or press 1. For support, say support or press 2.", { choices:"sales( 1, sales), support( 2, support)", repeat:3, onBadChoice: function() { say("I'm sorry, I didn't understand what you said.") } } ); if (result.name=='choice') { if (result.value=="sales") { say( "Ok, let me transfer you to sales." ); transfer( "14075551111"); } if (result.value=="support") { say( "Sure, let me get support. Please hold." ); transfer( "14085552222"); } }
20. T.10: Bad Choices - Ruby answer options = { :choices => 'sales( 1, sales), support( 2, support)', :repeat => 3, :onBadChoice => lambda { say ‘I did not understand what you said.' }, :onTimeout => lambda { say 'Hm. I did not hear anything.' } } result = ask 'For sales, just say sales or press 1. For support, say support or press 2.', options if result.name == 'choice' case result.value when 'sales' say 'Ok, let me transfer you to sales.' transfer '14075551212' when 'support' say 'Sure, let me get support. Please hold.' transfer '14085551212' end end hangup
21. T.11: Right choices - Groovy // ----------- // handling good choices with event handlers too // ----------- answer(); ask( "Hi. For sales, just say sales or press 1. For support, say support or press 2.", [ choices:"sales( 1, sales), support( 2, support)", repeat:3, onBadChoice: { say("I'm sorry, I didn't understand what you said.") }, onTimeout: { say("Hm. I didn't hear anything.") }, onChoice: {event-> if (event.value=='sales') { say( "Ok, let me transfer you to sales." ); transfer( "14075551212"); } if (event.value=='support') { say( "Sure, let me get support. Please hold." ); transfer( "14085551212"); } } ] );
22. T.12: onEvent - JavaScript answer(); ask( "Hi. For sales, just say sales or press 1. For support, say support or press 2.", { choices:"sales( 1, sales), support( 2, support)", repeat:3, onEvent: function( event ) { if (event.name=='badChoice') { say( ”I didn't understand what you said.") } if (event.name=='timeout') { say( "Hm. I didn't hear anything.") } if (event.name=='choice') { if (event.value=='sales') { say( "Ok, let me transfer you to sales." ); transfer( "14075551111"); } if (event.value=='support') { say( "Sure, let me get support. Please hold." ); transfer( "14085551111"); } } transfer( "14075552222"); } } );
23. T.13: conditional accept - Ruby # ----------- # reject based on callerid # ----------- answer log "*"*100 + currentCall.inspect if currentCall.callerID == ’4078675309' answer say 'Hello there and goodbye' hangup else reject end
25. T.15: Branching - Groovy // ----------- // Changing behavior based on number called // ----------- answer(); if (currentCall.calledID == '4075551111') say( "Hello Andrew."); if (currentCall.calledID == '4075552222') say( "Hello Brian. "); hangup();
26. T.16 Recording - JavaScript answer(); event=record("Leave your message at the beep. Thanks!", { beep:true, silenceTimeout: 5, maxTime:60, timeout:10, onRecord:function(event ) { say("you said " + event.recordURI ) } } ); log( "event.recordURI = " + event.recordURI ); hangup();
27.
28. Mashing Up With Web Services # python app to retrieve and say a text file import urllib number= urllib.urlopen("http://blog-files.voxeo.com/media/test.txt").read() answer() say("Welcome to Tropo. Your magic number is %s. Goodbye." % number) hangup() // Groovy app to retrieve and say top ten hits from Yahoo music def musicbase = "http://us.music.yahooapis.com/track/v1" def appid = "KgtDvNrV34Eavq_dUF81vBlVLKAOq7o1tj7Tzvu_kYbKsCtBW190VmrvVHK_0w--” say( ", Top 10 Chart Toppers!" ) def toptracksxml = new XmlSlurper().parseText( "${musicbase}/list/published/popular?count=10&appid=${appid}".toURL().text ) toptracksxml.Track.each { track -> say( ", Number " + track.ItemInfo.ChartPosition["@this"] + ", " + track["@title"] + ", by " + track.Artist[0]["@name"] ) } say( ", Goodbye!" ) hangup()