Archive for the ‘Ruby’ Category

Control your Christmas lights by phone using Arduino and Tropo

Monday, November 26th, 2012

Get into the holiday spirit with this fun hack by Tropo developer Anthony Webb.  This video demonstrates how you can hack your G-35 Holiday Lights by mashing them up with Arduino, Tropo, Nodejs, and a little dash of Ruby code.   It also shows the speed of Tropo’s scripting engine using TCP sockets. This allows for extremely low latency, as opposed to simple web callback methods.

What you’ll need:

Here’s the video:

Recovering from the Railsberry Sugar High

Tuesday, April 24th, 2012

Wow, what an awesome event that the Railsberry team put on last week in Krakow, Poland! It’s difficult to describe in words the attention to detail and coordination by the Applicake and Future Simple crews put into making this a truly memorable event.

The Railsberry team put together some awesome videos as well such as this one from Day 1 and this one from Day 2. I put some video together from the API Bakeoff and Day One.

The highlight of the conference (for me at least) was getting to play the giant grand Yamaha piano at the very end of Day 2 for the entire Railsberry conference. Here’s a video of the performance. You can also check out the lyrics, which have already been transcribed and forked on Github!

Auto-Returning Phone Calls with Tropo

Monday, March 5th, 2012

Using Tropo’s Scripting API and Ruby, I wrote a clever little script that allows you to automatically return missed calls from people as soon as you hang up a phone call.

Here is the use case:

  • User A calls user B
  • While users A and B talking, user C calls user B
  • Tropo script records the missed user C call and returns their call after B hangs up. The Tropo script automatically calls users B and C and bridges them in a conference call.

Here is a video to help demonstrate the concept:

Here is the Ruby script using Iris Couch as a JSON datastore directly from the Tropo cloud!

(more…)

Ruby on Rails Conference Caller

Friday, February 24th, 2012

Have you ever wanted to initiate a conference call and have it dial everyone’s phone numbers and invite them into a standup conference call? I will show you how to do this using Ruby on Rails and the Tropo Scripting API. The following Rails application is running version 3.2.1 powered by Twitter Bootstrap for the sweet CSS styling plus Gritter jQuery alerts (like Growl) with a little AJAX mixed in to liven things up.

Here is a screencast to show off my conference caller app!

The Rails application uses the Ruby Rest-Client gem to kick off the Tropo conference caller script while passing the Tropo script a comma delimited string of numbers to dial. The Rails Rest-Client call looks like:

response = RestClient.get "http://api.tropo.com/1.0/sessions?
action=create&token=0e0a2a5742a75c...e01102c8f745818848
&phones=#{phonenumbers}"

Here is the Tropo Ruby script: (more…)

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.