Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Pull request Compare This branch is even with tropo:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
app
config
db
doc
lib/tasks
log
public
script
test
.gems
README
Rakefile

README

create a rails application
(note that there is an incompatibility issue with ActiveSupport 2.3.2 and json, which is requied by tropo ruby gem.  I'm using rails 2.3.5 and it works fine.)

rails tropo
cd tropo
script/generate controller messagings
=======edit messagings_controller.rb================
class MessagingsController < ApplicationController
  def index
    initial_text = params["session"]["initialText"]
    from = params["session"]["from"]
    network = from["network"]
    from_id = from["id"]
    if network == "SMS" || network == "JABBER"
      render :json => parse(initial_text)
    else
      render :json => Tropo::Generator.say("Unsupported operation")
    end
  end

  private

  def parse(input)
    input.strip!
    # do whatever parsing you need.  in this example, if user types "n what a new day", tropo will
    # respond him with "you said: what a new day"
    if m = input.match(/^(n|N)\s+/)
      Tropo::Generator.say "you said: " + m.post_match
    else
      Tropo::Generator.say "Unsupported operation."
    end
  end
end
=====================================================
There are lot you can do with all the parameters tropo posts to your app:
Processing MessagingsController#index (for 127.0.0.1 at 2010-02-09 16:19:29) [POST]
  Parameters: {"session"=>{"timestamp"=>"2010-02-10T00:19:01.718Z", "from"=>{"name"=>"unknown", "network"=>"SMS", "id"=>"14085059096", "channel"=>"TEXT"}, "to"=>{"name"=>"unknown", "network"=>"SMS", "id"=>"16175759989", "channel"=>"TEXT"}, "userType"=>"HUMAN", "id"=>"p8rzeh", "initialText"=>"Zzzzz", "headers"=>[{"value"=>"70", "key"=>"Max-Forwards"}, {"value"=>"124", "key"=>"Content-Length"}, {"value"=>"<sip:10.6.93.201:5066;transport=udp>", "key"=>"Contact"}, {"value"=>"<sip:9991444206@10.6.93.202:5061;to=16175759989>", "key"=>"To"}, {"value"=>"1 INVITE", "key"=>"CSeq"}, {"value"=>"SIP/2.0/UDP 10.6.93.201:5066;branch=z9hG4bK7oo7k1", "key"=>"Via"}, {"value"=>"p8rzeh", "key"=>"Call-ID"}, {"value"=>"application/sdp", "key"=>"Content-Type"}, {"value"=>"<sip:370930B3-D767-4F35-9A9AABB4535A61AB@10.6.61.201;channel=private;user=14085059096;msg=Zzzzz;network=SMS;step=2>;tag=mbx865", "key"=>"From"}], "accountId"=>"38958"}, "tropo-engine"=>"json"}
=====================================================

add a route for the messageings_controller in config/routes.rb
map.connect 'messaging', :controller => 'messagings', :action => 'index'

add a gem require in config/environment.rb, which means you need to gem install tropo-webapi-ruby
require 'tropo-webapi-ruby'

now it's time to create a tropo app
activate an IM account.  I like to use @bot.im's jabber account.  For this example, I have created foobuz@bot.im.
Once your tropo IM account is activated, go ahead and add it to your IM client (a jabber client in this exmaple)
next you need to supply a url that powers voice calls.  just put in any url for now as we won't deal with voice in this blog.  it is a mandatory field on tropo.

then supply a url that powers sms/messaging calls.  since we deal with tropo web api (v.s. hosted script), we will need to supply a valid server url that points to a rails controller for example.
http://your_server/messaging?tropo-engine=json

please note that "tropo-engine" is a required parameter for tropo currently.  the value for it is json in this example.

now add a sms-enabled number.

That's it, now fire up your rails server.

send message to your IM bot (created on tropo) or SMS to the tropo number.
e.g. "this is a test"
tropo should respond "unsupported operation"
e.g. "n this is a test"
tropo should respond "you said: this is a test"
Something went wrong with that request. Please try again.