Archive for the ‘Ruby’ Category

Meet Phono – Tropo’s Web Phone

Monday, January 23rd, 2012

Have you heard about Phono, our open source Javascript Phone API project?

Phono is a free HTML5 jQuery-based web phone that you can add to any web page to place or receive open SIP-based VoIP calls to/from any web browser (or iOS/Android mobile device using Phono Mobile)!

Phono can be connected to Tropo to place or receive phone calls to/from real telephone numbers! Phono can also interact with Tropo voice applications directly from a web page using Tropo’s speech recognition and text-to-speech in 24 languages as well as record and play media such as WAV or MP3 files or conduct conference calls, call transfers, call recording, etc.

To make things even better, Phono and Tropo both support SIP headers which are basically key/value pairs of data that you can sent along with calls. SIP headers are very common in call center applications and enterprise screen-pop implementations. Using SIP headers allows Phono to place a call into a Tropo application and pass along data instructing Tropo to transfer the call to another telephone number. This is how all of the click-to-call demo applications work on phono.com. These demo applications are also limited to 10 minutes in length so that you can experience the quality of a Phono call and write your own Tropo application for longer calls.

Because we have had a few questions lately on this topic, I wanted to provide some sample code for both Phono and Tropo to make this easier for you to apply to your application. This demo application allows you to enter a phone number on a web page and call it using Phono and Tropo. The web page has a simple form that asks for a phone number and has a call button that initiates a SIP VoIP call to Tropo app:9996182316. Reviewing the Phono code below, you will find that it uses jQuery to pass the phone number value in the textbox to Tropo as a SIP header.

<html>
  <head>
    <script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
    <script src="http://s.phono.com/releases/0.3/jquery.phono.js"></script>
  </head>
  <body>
	<input id="phonenumber" type="text">
    <input id="call" type="button" disabled="true" value="Loading..." />
    <span id="status"></span>
    <script>
    $(document).ready(function(){
      var phono = $.phono({
        apiKey: "your secret key",
        onReady: function() {
          $("#call").attr("disabled", false).val("Call");
        }
      });

      $("#call").click(function() {
        $("#call").attr("disabled", true).val("Busy");
        phono.phone.dial("app:9996182316", {
		  	headers: [
			             {
			               name:"x-numbertodial",
			               value:$('#phonenumber').val()
			             }
			           ],
          onRing: function() {
            $("#status").html("Ringing");
          },
          onAnswer: function() {
            $("#status").html("Answered");
          },
          onHangup: function() {
            $("#call").attr("disabled", false).val("Call");
            $("#status").html("Hungup");
          }
        });
      });
    })
    </script>
  </body>
</html>

You could write a Tropo transfer application using the Scripting API in one line of Ruby code that transfers the call to the phone number in the SIP header like this:

transfer $currentCall.getHeader("x-numbertodial")

What if you wanted to add a timer that ends the call after 10 minutes like we do on phono.com for demo purposes? This feature is also simple but it requires multithreading your Ruby application and using our REST API for sending a signal to interrupt the transfer method once your timer reaches its alarm.

require "net/http"

# Create second thread for timer and announcements
Thread.new do
  sleep 600 # Note: Sleep is in seconds so 600 = 10 minutes

  http = Net::HTTP.new "api.tropo.com"

  request = Net::HTTP::Get.new "/1.0/sessions/#{$currentCall.sessionId}/signals?action=signal&value=limitreached"
  response = http.request request
end

say "hold please while we transfer your call."
transfer $currentCall.getHeader("x-numbertodial"), :allowsignals => "limitreached"
say "your limit has been reached."

That’s cool but what if you wanted to block certain phone numbers or limit the demo calls to North America? You could add area codes or phone numbers to a regex array and check the desired phone number against the list of regexes to see if you should allow the call to transfer or not like this example:

phone = $currentCall.getHeader "x-numbertodial"

# Blocked North American area codes
blocked = [
  /^\+?1?8[024]9/,
  /^\+?1?26[48]/,
  /^\+?1?24[26]/,
  /^\+?1?34[05]/,
  /^\+?1?[62]84/,
  /^\+?1?67[10]/,
  /^\+?1?78[47]/,
  /^\+?1?8[024]9/,
  /^\+?1?86[89]/,
  /^\+?1?441/,
  /^\+?1?473/,
  /^\+?1?664/,
  /^\+?1?649/,
  /^\+?1?721/,
  /^\+?1?758/,
  /^\+?1?767/,
  /^\+?1?876/,
  /^\+?1?939/
]

block_call = blocked.any? { |x| phone =~ x }

You could add this code immediately above your transfer and add a conditional statement that says something like this example:

if block_call
  say "calls to this area code are blocked."
else
  say "hold please while we transfer your call."
  transfer phone, :allowsignals => "limitreached"
  say "your limit has been reached."
end

You could also add billing functionality to the Tropo script by applying a rate based on country code and multiply it times the number of seconds that the call was in progress. To accomplish this goal, you would add a timestamp at the beginning of the script and a timestamp directly following the transfer method. When either party hangs up, the Tropo script will continue running with the line immediately following the blocked method such as transfer in this case.

If necessary, you could also check to see if the Phono caller is still on the call by interrogating the $currentCall.isActive property or by wrapping your entire application in a while loop like this example:

while $currentCall.isActive
  # Do Stuff
end

I think that should get you started! You can now build your next-generation click-to-call application using Phono and Tropo! Please let us know how you are using Phono with your Tropo applications :)

Voice Texting With Tropo Speech & SMS Technology

Wednesday, December 21st, 2011

We all agree that texting while driving is very dangerous, right? Fred Wilson, VC and principal of Union Square Ventures thinks so too. He recently wrote a blog post that starts like this:

“As a parent of two young adult drivers and a third soon to hit the road, nothing scares me more than texting while driving.”

Fred continued his blog post envisioning a Voice Texting application as follows:

“Being an engineer at heart and by training, I’ve been looking for a solution to the problem. I know that the buzz of the phone and the unread/unresponded message is like a drug to many and that the best solution would be a “hands free” way to read and respond. And the bluetooth/hands free voice solution works so well on most cars and most phones now, so why can’t we do the same with texting?”

Having two kids of my own (1 already driving and 1 studying for a drivers permit) and having access to the Tropo API and platform, I felt compelled to build a quick Voice Texting application to share with Fred Wilson! Here is what Fred had to say upon me sharing it with him…

Here is how it works:

To send a text, call (415) 349-3120 and using Tropo speech recognition say the phone number that you would like to text and then speak your message. Tropo then transcribes the message and sends your text message to phone number you spoke without taking your eyes or hands off the road.

Disclaimer: We are not promoting texting while driving even with the proper tools that would keep your eyes on the road such as a bluetooth earpiece and autodial features.

The source code for this project is written in Ruby and open sourced on GitHub in case anyone would like to extend it or perhaps even create a new business around this idea and have a head start! Here’s a video of me demonstrating the technology in action:

Drive safely!

Tropo Jambox Megaphone

Monday, December 19th, 2011

After rocking out to a little White Stripes’ Icky Thump, Chris Matthieu shows you how to build a megaphone using a Jawbone Jambox, an iPhone, and the Tropo Scripting API!

Here’s the Ruby script used in the video:

say "Welcome to the Tropo megaphone app! Please turn on and pair your Jam box now."

while $currentCall.isActive do

record "Record your message at the beep and then switch audio to jam box.", {
        :beep => true,
        :timeout => 10,
        :silenceTimeout => 7,
        :maxTime => 60,
        :onRecord => lambda { |event|
            log "Recording result = " + event.recordURI
            say event.recordURI}
        }

end

Rock on!

LA Holiday Hackathon :: Results

Monday, December 12th, 2011

Approximately 30 Los Angeles .NET, Ruby, PHP, and Javascript developers attended this Saturday’s LA Holiday Hackathon at Outlook Amusements sponsored by RightNow Technologies and Tropo. The theme of the event consisted of building a Voice, SMS, or Instant Messaging holiday application based on the Tropo Scripting or Web API. Here is a photo of everyone hard at work hacking on their holiday Tropo application.

I love the sound of phones ringing in the morning! By noon, the applications were starting to take shape with some definite front runners in the competition. In addition to Tropo APIs, many of the teams also used Phono, SMSified, RightNow, Wolfram Alpha, and Google’s Shopping APIs to deliver their new applications.

Here are the winners of the LA Holiday Hackathon listed in order:

First place goes to Gift Finder winning an iPad2 compliments of RightNow Technologies. This application allows the user to enter a phone number, name, and email address to place an outbound call to someone to recommend gifts for loved ones. Speech recognition was used to ask the user for their zip code, gender, price range range, and category of the gift. The application uses the Google Shopping API to find gifts in their area for the gender and age of the recipient and reads them off one by one using text to speech. This application was built using Ruby and Sinatra and hosted on Heroku as well as using the Javascript Tropo Scripting API.

Second place goes to Santa’s Book winning a Kindle Fire compliments of RightNow Technologies. This application asks for two phone numbers and starts by calling the first number to ask a series of five questions using speech recognition to determine if the person is naughty or nice along with asking them to record the present that they would like to receive. The application proceeds to call the second number to relay the naughty/nice determination and playback their gift recording. The application also sends an SMS text message to the second number with the naughty/nice determination along with the transcribed gift request. This application also used RightNow’s CRM API to log the call and data related to the surveys. This application was built using PHP and the Tropo WebAPI along with RightNow’s CRM API.

Third place goes to Santa Hack winning a $75 Fry’s Electronics gift card compliments of Outlook Amusements. This application used Phono and Tropo to schedule and bridge appointments to speak with Santa. This application was built using C# and the Tropo WebAPI.

Fourth place goes to Tropo WA (Wolfram Alpha) winning a $50 Tropo production credit. This application was a Wolfram Alpha and Tropo SMS mashup written in PHP using the Tropo Scripting API. You can ask the application various questions via SMS on the following number 661-206-2681.

LA .NET Hackathon 2011

Monday, December 5th, 2011

Tropo is partnering with the LA .NET Developers Group and Outlook Amusements to sponsor this weekend’s LA (Burbank) Hackathon at Outlook Amusements on Saturday, December 10, 2011 from 9:00 AM to 6:30 PM (PT).

Here’s the address: Outlook Amusements 2900 W. Alameda Ave suite 400 Burbank, CA 91505

The theme of the LA Hackathon is “Build Voice/SMS apps for Holidays”! Here are a few ideas to get you thinking:

  • Santa Caller (similar to http://santacall.us) – Build a website that allows a parent to schedule a call to their kids from Santa. Have Santa ask the kid what they would like for Christmas and then email the parents their kid’s recorded message and/or transcribe the message for the email.
  • Santa Tag (similar to http://www.bloggingbistro.com/jc-penney-comes-up-with-a-new-use-for-qr-codes-video/) – Build a website that calls someone to record a message then associates the message with a QR code that plays when scanned.
  • Holiday Greetings Hotline – Build a holiday greetings hot line where user can leave a voice message that will be transcribed into text and posted to “Holiday Greetings” twitter account.

Even though this event is sponsored by the .NET Developers Group, we will be supporting all development languages and will have Tropo expertise onsite in .NET, PHP, Ruby/Rails, and Javascript, and Node.JS!

Register today!

Modernize Your App with Speech Recognition

Thursday, October 6th, 2011


This commercial was released in 1971 but touchtone (DTMF) was originally invented in 1941. That was 70 years ago! If your voice application is still using touchtone for user input, don’t you think it’s time to enter the 21st century?

Tropo offers speech recognition in 24 languages by default on every prompt allowing callers to use either touchtone or their voice to answer prompts during the call. We support four forms of speech recognition grammars include:

  1. Simple Grammars – Tropo’s comma delimited grammar strings
  2. GrXML – Speech Recognition Grammar Specification Version 1.0
  3. JSGF – Java Speech Grammar Format or the JSpeech Grammar Format (in a W3C Note)
  4. ABNF – Augmented BNF (Backus Normal Form)

Using Tropo’s simple grammars are incredibly, well, simple. Here is what an auto-attendant’s dial directory prompt would look like using Tropo’s simple speech recognition grammar.

ask "Welcome to the Tropo company directory.  Who are you trying to reach?", {
    :choices => "department(support, engineering, sales), person(chris, jason, adam)",
    :onChoice => lambda { |event| 
        say("You said " + event.choice.interpretation + ", which is a " + event.value)    
    }
}

From here you could also transfer the call to the department or person’s phone number or SIP address by substituting the onChoice say prompt with the following logic:

say "Please wait while we transfer your call. Press star to cancel the transfer."
transfer ["+14075550100","sip:12345678912@221.122.54.86"], {
    :playvalue => "http://www.phono.com/audio/holdmusic.mp3",
    :terminator => "*",
    :onTimeout => lambda { |event|
        say "Sorry, but nobody answered"}
}

The possibilities of developing new voice apps using speech recognition are endless! For one, your customers will have a better user experience (UX) by not having to press buttons on the phone. Secondly, apps such as language translater applications and personal assistant applications are now possible.

We want to be your speech recognition and cloud communications partner.

Writing and Deploying a Tropo App with an iPad

Tuesday, September 27th, 2011

I recently found myself at a conference without WIFI and i wanted to write and deploy a new Tropo voice application to the cloud. Armed with my 3g iPad, this task was a snap! See for yourself…

SMS forwarding to an email using MailChimp

Tuesday, September 6th, 2011

Depending on your application, you might receive multiple messages back to back to back – system notifications, alerts, user confirmations and so on – that would be inconvenient to redirect to your phone one by one. As an alternative, how about receiving a full list of the inbound texts sent to you as an email? Using MailChimp with Tropo, this can be accomplished with relative ease.

MailChimp allows users to send an email to multiple email addresses at once as an email blast; this blog will show how to implement MailChimp’s API with a Tropo Scripting app using Ruby. As is typical, first step is to set up an account for MailChimp.

Go here to sign up for an account, then once signed up and logged in, we need to create a list – this is how MailChimp sends emails. Unfortunately, lists cannot be made programmatically, so to set up a new list – sign-in, fill out the requirements, then click the tab Lists.

Screen shot 2011-09-01 at 4.50.15 PM.png

Once there, hit the “create a subscriber list” button to the left. Following that, some information will be requested – list name, default name, and default email (which is not the email that will send the text messages, but the email that receives confirmation that the emails were sent). When everything is filled out, hit save to create a new list.

Next, the first email address that will receive the email containing the texts needs to be added. This can be done by clicking “add people”.

Screen shot 2011-09-06 at 10.46.12 AM.png

After selecting “add people”, the only relevant information that needs to be added is the email address. Repeat this process to add multiple email destinations.

From here, the app takes over. To begin, a few requirements are necessary – uri, to format strings into proper URLs,  net/http, to submit URLs to receive information and send the emails, and json, to read the received information.

%w(uri net/http json).each{|lib| require lib}

Following this will be the config section, which are constants that can be set in the beginning. 

**Important Note**

-In the API_URL the first three characters can change and will rely strictly on the API_KEY.  An example to expect is: myapikey-us2, in this case the first three characters would be us2.

#CONFIG
YOUR_NAME = URI.encode("Kevin Bond")
API_URL = "http://us2.api.mailchimp.com/1.3"
API_KEY = 'mailchimp_api_key'
FROM_ADDRESS = "kbond@voxeo.com"
SUBJECT = URI.encode("You just received a text message!")

The next piece of code will extract the text and the caller id from the SMS. The text will be the "content" of the email (the body) and the caller id will be the "from_name".

# Get the initial Text, and callerId
initial_text = $currentCall.initialText
caller_id = $currentCall.callerID

Now it's finally time to utilize the MailChimp API. This piece of code will send a request to get the list id, which is the specific number that corresponds to the list we made earlier. Once received, it is parsed into JSON and read as the variable list_id.

#Get the list ID that corresponds to your email
id =Net::HTTP.get_response(URI.parse("#{API_URL}/?method=listsForEmail&apikey=#{API_KEY}&email_address=#{FROM_ADDRESS}"))
list_id = JSON.parse(id.body)

The next step in sending this email blast is to create a new email campaign. To do this, there are some parameters that need to be added to the URL. There are four in total, two variables - "api key" and "type of email" - and two arrays or hashes. The code below shows the two hashes ("content" and "options").

#This will be the body of your email, which is the text message
content = "1=#{URI.encode(initial_text)}"

#Setting the url variables
options = "&
options[list_id]=#{list_id[0]}&
options[subject]=#{SUBJECT}&
options[from_email]=#{FROM_ADDRESS}&
options[from_name]=#{URI.encode(caller_id)}&
options[to_name]=#{YOUR_NAME}".gsub("\n","")

The other two parameters are just inserted individually. Below is the variable parameters, which holds all of the contents.

#Parameters will be the variable that goes inside of the url
#To satisfy mailchimps method, you need 4 fields, the apikey, type of email, 
#options - which is an array or hash, and content - which is also an array or hash
parameters = "apikey=#{API_KEY}&type=plaintext&options=#{options}&content#{content}"

The next MailChimp API request creates a new email campaign, it doesn't actually send the emails. The request returns the campaign id, called cid, which is used to launch that campaign.

#This response creates a new campaign and returns the id for that campaign
id = Net::HTTP.get_response(URI.parse("#{API_URL}/?method=campaignCreate&#{parameters}"))
cid = id.body[1..10]

Now that the email campaign is created, all that is left to do is send it. The code below sets the URL, creates a new HTTP post, and finally initiates the post. The result should return "true" if the campaign successfully sent.

#This is a post to send the email using the cid, which is the campaign id
url = URI.parse("#{API_URL}/?method=campaignSendNow&apikey=#{API_KEY}&cid=#{cid}")
req = Net::HTTP::Post.new("#{API_URL}/?method=campaignSendNow&apikey=#{API_KEY}&cid=#{cid}")
res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }

Once this executes, all of the email adresses from the list will receive the email with the text message contents.

Hope this was helpful, you can go here to view the app in full. Questions or concerns can be added in the comments, or opened as a forum post here.

Voice Board and Group SMS for Burning Man

Thursday, August 25th, 2011

This is a true testimonial to the power of running Tropo in a Private Cloud using generators for disaster relief or business continuity or for handling communications for events like Burning Man!

This rack includes Tropo and OpenBTS communications equipment for powering Burning Man’s Tropo Voice Board and Group SMS apps!

Once a year, tens of thousands of BurningMan participants gather in Nevada’s Black Rock Desert to create Black Rock City, dedicated to community, art, self-expression, and self-reliance. They depart one week later, having left no trace whatsoever.  Black Rock Desert (or the Playa as Burners refer to it) is an isolated region with no electricity, running water, or communications.

Tropo has partnered with Range Networks and GWOB to setup a local OpenBTS-powered cell tower to provide both Tropo-powered Voice and SMS communications services to the Burners on the Playa.

Custom Private Cloud Tropo applications have been developed to deliver a social voice mail solution – or better yet – an asynchronous voice board messaging platform as well as a Group SMS solution like Facebook’s new messaging app but for local Burners only.

This is what the Voice Board application looks like if you were to connect to the Tropo server using a local IP address!  It’s basically a Ruby on Rails 3.1 application utilizing Tropo’s Scripting API and small Ruby script.  The website is designed to allow the outside world to interface with the Burners, provided we can establish a good satellite data uplink (more details to follow). The website grabs the latest BurningMan-tagged Flickr image and associates it with a voice memo being streamed while enjoying photos from the event.

Burners can call into our Voice Board application to record social voice memos and listen to public messages left by other Burners on the voice board. If a recording is in progress when a new call comes in, it automagically  becomes a conference room party line and continues recording the chat from the participants.

The conference room recording simply becomes another voice memo like the others – presented in descending order to new callers. As you listen to voice memos, they automagically get marked as read and disappear from your list. The Voice Board application loops through options (record memo or listen to memos) while the call isActive and lets you leave multiple voice memos or join the conference after listening to memos (if one is in progress)!

The Voice Board application also includes a Group SMS application which is available only for the local Burners. Any one who has called the Voice Board or texted a message to the Tropo Group SMS app will automagically be added to the Group SMS distribution list for the duration of the event.  They will receive text messages from other Burners any time the Voice Board is sent a text message!

The source code for our the Tropo-powered Voice Board and Group SMS application can be found at https://github.com/chrismatthieu/voiceboard

We are also in the process of establishing a satellite data connection to allow for VoIP connectivity of these communications applications to the outside world allowing the Burners to actually make real phone calls to anyone in North America.  This is powered byt the Tropo.com Public Cloud service.  If communications with the outside world can be established, Tropo will be sponsoring an unlimited number of 5 minute phone calls from the Playa to any phone number in North America to allow Burners to stay in touch with loved ones and to provide an additional route for emergency communications.

We are proudly embracing the BurningMan experience and we hope to gain more experience in using Tropo to deliver real-time communications services in times of disaster and business continuity programs as well as allowing our customers and telcos/carriers to run Tropo’s cloud communications API and platform in their own data centers and private voice clouds.

For more information on about Tropo’s involvement and applications used in the BurningMan event, please refer to our blog post below or contact Chris Matthieu at chris [at] tropo.com

http://blog.tropo.com/2011/08/23/tropo-openbts-burning-man-awesome/

Win a Free Pass to Madison RubyConf!

Saturday, August 13th, 2011

Tropo is giving away 1 FREE pass to this week’s Madison Ruby conference! The conference is in beautiful Madison, Wisconsin and the venue is the elegant Overture Center for the Arts. The conference starts with workshops on Thursday, 8/18/2011, followed by two full days of dual track 40+ speaker sessions and after parties!

Entering the FREE pass to MadisonRuby give-away contest is simple:

1. Tweet this sentence to be entered to win:

“Hey @Tropo – Pick me for the free ticket to @MadisonRuby conference!”

2. The winner will be randomly selected on Monday, 8/15/2011, at midnight Pacific time from a list of all of these tweets posted on Twitter.  You can tweet it as much as you like to increase your chances!

Tropo is a proud sponsor of the MadisonRuby conference.