We continue our focus this week on ways to create real-time interfaces for your users via Tropo for phone calls, instant messaging, SMS and Twitter. As promised in my recent blogpost, WebSockets with Tropo, I would like to build upon Chris Matthieu’s XMPP with Tropo post by throwing BOSH into the mix.

“Bidirectional-streams Over Synchronous HTTP”, or BOSH, provides for  two-way communications over HTTP, emulating much of TCP. This allows yet another approach for creating low-latency interfaces to Tropo using the unique capabilities of our scripting platform. With this, you skip the latency inherent in chatty request/response APIs over HTTP REST. Allowing you to have fluid interactions with users in public spaces where their only interface to your application is a phone call.

Tropo has native support for XMPP built right into the standard API. Therefore a call comes into Tropo, we start asking the caller for input and then send those responses to the XMPP user that represents our browser application. In the browser we use JQuery and Strophe.js for the XMPP/BOSH support and then Artisan.js for the HTML5 Canvas tag rendering of the graphics. On the Tropo side we  have a Ruby script that looks like this:

require 'json'

loop do
  ask "Press a key or push zero to exit.", {
    :choices  => "[1 DIGITS]",
    :onChoice => lambda { |event|
      input = { :command => event.value }.to_json
      message input, {
        :to      => "troporiffic@jabber.org",
        :network => "JABBER" }
        break if event.value == "0"
      }
    }
end

The simplicity of this is driven home by the fact that the Tropo API is the same for interacting with phone calls or messages (IM, Twitter or SMS), the power of a unified API. You may watch this in action here:

The Tropo script and Javascript/HTML examples may be found on Github here. Enjoy!

Originally from Voxeo Blogs