Tropo with XMPP and BOSH, More Real-time in Your Communications

December 17th, 2010 by Jason Goecke

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 (Tropo script and HTML/Javscript example). And don’t forget to add and enable a Tropo Jabber account on your application:

Enjoy!

Related posts:

  1. WebSockets and Tropo, Putting the Real-Time in Your Communications
  2. Real-Time Communications with Tropo and Node.js
  3. Tropo DTMF to XMPP IM Relay
  4. Babelverse: Using the phone for real-time Japanese translation for crisis workers
  5. QR Code Fun with Tropo!

Tags: , , , , , , ,

6 Responses to “Tropo with XMPP and BOSH, More Real-time in Your Communications”

  1. Ted Gilchrist says:

    Hi Jason,

    Are you going to be publishing the Javascript code you used to create the web page in this examples?

    Thanks,

    Ted Gilchrist

  2. Ted Gilchrist says:

    Hi Jason,

    So, I’m trying to get the client html page side working, and I keep getting “Strophe failed to connect” errors. Where is it supposed to be getting login credentials from?

    Thanks,

    Ted

  3. Jason Goecke says:

    Lines 120 through 123 in the HTML file:

    $(document).ready(function () { connection = new Strophe.Connection(BOSH_SERVICE); connection.connect(‘user’, ‘pass’, onConnect); });

    Are where you may put the login credentials. Any XMPP server/service will work. For the demonstration I used Jabber.org’s public XMPP service.

  4. Ted Gilchrist says:

    One more thing that people should know. In order to make this work, you have to activate Jabber on your Tropo app. It’s right there in the UI, when you create the app. So, yes, the demo does indeed work!

    Thanks,

    Ted

  5. Jason Goecke says:

    Good feedback, I will update the post with a little more detail. Thanks!

Leave a Reply

Please note: By submitting a comment you agree to comply with our Comment Policy. We welcome all comments, positive or negative, but do reserve the right to remove all or part of blog comments that do not comply with our policy.

Additionally, the first time you leave a comment on this blog, it will be held for moderation. After that first comment has been approved, future comments will be posted without delay.

Additional comments powered by BackType