Posts Tagged ‘tunnlr’

Hello, Python World (Django Edition)

Sunday, May 29th, 2011

I’ve been doing my Python Tropo development on top of Google App Engine, for the past couple of years. Out of the box, App Engine uses the webapp framework. But for my current “Hello, World” project, I decided to leave my App Engine comfort zone, and gain a different perspective. I took up the task of writing a “Hello, World”, Tropo Web API app, using the Django framework for Python.

(more…)

Send a Fax with your Voice!

Monday, February 21st, 2011

Tropo just recently partnered with PamFax to deliver faxing capabilities via an API.  Jason Goecke wrapped their API with a very simple Ruby gem called pamfaxr available at GitHub and installable using a “gem install pamfaxr” from your command line.  Using the PamFaxr Ruby gem, I will demonstrate how to send a simple fax as well as how to build a Tropo Voice to Fax transcription application using our Scripting API!

Getting Started

Before you can start sending faxes, you need to head over to the PamFax site and sign up for a PamFax account. After you fill out and submit the form, you’ll get an email with your login credentials and how to get started.

You also need to install the Ruby gem called pamfaxr on to the system where you are going to run the application that will send the fax. The Ruby gem is available at GitHub and should install simply by typing “gem install pamfaxr” from your command line. You will need to edit the code to have your PamFax username and password.

Sending A Fax From The Command Line

Before we involve Tropo, here is the Ruby/Sinatra code for simply sending a fax from the command line using the PamFaxr gem:

require 'rubygems'
require 'pamfaxr'

# Pass user name and password
pamfaxr = PamFaxr.new :username => 'your_username',
                      :password => 'secret'

# Create a new FaxJob
faxjob = pamfaxr.create_fax_job

# Add the cover sheet
covers = pamfaxr.list_available_covers
pamfaxr.set_cover(covers['Covers']['content'][1]['id'], 'Chris was here 2!')

# Add files
# pamfaxr.add_remote_file('https://s3.amazonaws.com/pamfax-test/R-intro.pdf')
# pamfaxr.add_file('examples/R-intro.pdf')

# Add a recipient
pamfaxr.add_recipient('+14802191300')

# Loop until the fax is ready to send
loop do
  fax_state = pamfaxr.get_state
  break if fax_state['FaxContainer']['state'] == 'ready_to_send'
  sleep 5
end

# Send the fax
pamfaxr.send_fax

Just copy that code into a text file, edit it to have your information in it and then run it with ruby from your command line. In a short bit you should have a fax waiting for you.

Sending Faxes From Tropo

Now for the fun Tropo Voice to Fax application code! The first code snippet is written in Ruby runs on the Tropo cloud. It greets the caller, asks for your fax number, records your voice/fax message and sends the transcription via a callback to the Ruby/Sinatra application that sends the actual fax.  Here’s the Tropo code:

say "Welcome to the Tropo fax demo.", :voice => 'dave'

result = ask "What's your fax number? Please include your country code.", {
   :choices => "[11 DIGITS]", :voice => 'dave'}

record "Please say what you would like for me to fax.", {
    :beep => false,
    :voice => 'dave',
    :maxTIme => 60,
    :silenceTimeout  => 2,
    :transcriptionOutURI => "http://web1.tunnlr.com:11053/transcribe?fax=" + result.value
    }

say "Your voice is being converted to a facsimily!  Go check your fax machine!  Goodbye.", :voice => 'dave'

hangup

Here is the complimentary Ruby/Sinatra code that catches the Tropo transcription callback and sends the fax of the transcription to the number specified in the Tropo script using the PamFaxr gem as demonstrated above. This code needs to be run on a publicly-accessible web server to which Tropo can connect and send the data. You have several options including:

  • Running the code on your own publicly-available webserver
  • Running the code on a hosting service like Heroku
  • Running the code on your local machine and use a service like Tunnlr to make the service available

Once you have the Ruby/Sinatra code below running in one of those locations, you’ll just update the Tropo code above with the correct URL (on line 11).

The code is here:

require "rubygems"
require "sinatra"
require 'json'
require 'pamfaxr'

pamfaxr = PamFaxr.new :username => 'your_username',
                      :password => 'secret'

post "/transcribe" do

  transcript_json = JSON.parse(request.body.read)
  identifier = transcript_json['result']['identifier']
  transcript = transcript_json['result']['transcription']

  # Create a new FaxJob
  faxjob = pamfaxr.create_fax_job

  # Add the cover sheet
  covers = pamfaxr.list_available_covers
  pamfaxr.set_cover(covers['Covers']['content'][1]['id'], transcript)

  # Add a recipient
  pamfaxr.add_recipient('+' + params[:fax])

  # Loop until the fax is ready to send
  loop do
    fax_state = pamfaxr.get_state
    break if fax_state['FaxContainer']['state'] == 'ready_to_send'
    sleep 5
  end

  # Send the fax
  pamfaxr.send_fax

end

Wow, that was fun!  I hope that you enjoyed this demonstration and I hope that you find both our PamFaxr gem and our Tropo Scripting API useful and powerful.

WebAPI Tips & Tricks

Tuesday, September 7th, 2010

Working with Tropo’s WebAPI engine is fun, but there are a few ways to make it not only fun, but easier as well.  Since making developers lives easier is what our support team is here for I wanted to share these tips with you guys!! The first one is Tunnlr, which has been mentioned here before, but I figured I would bump it, since it really is an awesome service! You get 90 days free for all new signups, and there after it’s only 5 bucks a month for single user, or $15 for a 5 pack. You can sign up here and please tell them Tropo sent you :). Now a problem I had when working with Tunnlr was that among my 200 open windows I would often either forget I had a tunnlr session open, or lost track of it, and then I would have to locate the pid, kill it, and try again. This was a pain in the ____, so I figured lets make a shell function to address this issue, and now I would like to post it here to help our developers out as well!

#Create Tunnlr reverse http proxy, takes port as parameter
    function tunnlr(){
        pid=$(ps aux | grep tunnlr | grep -v "grep" | cut -d " " -f6)
        if [ "$pid" == "" ]; then
            echo "No existing pid found, starting tunnlr"
        else
            echo "Found Existing pid(s) [ $pid ], so long sucka"
            kill -9 $pid > /dev/null
        fi
    	    echo "http://web1.tunnlr.com:______" | pbcopy
    	    echo "URL Copied to clipboard"
        ssh  -nNt -g -R :_____:0.0.0.0:$1 tunnlr____@ssh1.tunnlr.com &
    }

Make sure you replace the redacted values above ( ____ ) with values from your Tunnlr account settings page.  You can find these by logging into your account, and clicking “how do I start tunnlr manually”, this will then show you the ssh command to start it, and you will see the missing values for your account.

Now since most developers are working with multiple web servers, which could be running on various ports, I figured it to be a good idea for this function to take port as a parameter; So to it, on port Sinatra’s default port of 4567 for example, we just run tunnlr 4567. The script will first check processes to make sure no other tunnlr sessions are running, if so kill them, and then starts the tunnlr session. It will them copy the tunnlr URL to your clipboard, since I kept forgetting this :), that way you can just paste it to the browser.

The next tool I wanted to mention is shotgun, which is a gem that allows yours changes to push live without having to restart Sinatra. You can find this gem here. Once installed (sudo gem install shotgun) you just run it like so:

dyer:~/dev/webapi git:master
→ shotgun -p 4567 sms_webapi.rb 
== Shotgun/Mongrel on http://127.0.0.1:4567/

-P 4567 specifies the port to run on, and I like to run this on the default Sinatra’s default port, rather then Shotguns default of 9393.

So with these two items you can now develop locally on your machine, and avoid Sinatra restarts when making changes. I really hope this helps, and if our team can be of any help please let us know. We are always available on Freenode (irc.freenode.net) in #tropo, so please drop by and chat us up, or simply you can email support@tropo.com.

John Dyer

Tropo Support

Using the Tropo Web API behind a firewall with Tunnlr

Wednesday, February 24th, 2010

Many times we find ourselves sitting behind networks without the ability to open a TCP port to hack on our web services. This may be at a coffee shop, a corporate network or that guest network you just connected to at your developer meetup. We have a solution for that.

In steps Tunnlr, a great little service by the folks at ElevatedRails. With Tunnlr, you are able to create a reverse SSH tunnel to a port on your computer. While they do have a plug-in for Ruby on Rails, this may be used to redirect traffic to any application running on a port. In this example I will walk you through how to do this using another Ruby web framework, Sinatra.

The first step is to sign-up for a Tunnlr account. You may select a single plan for USD$5 per month, but you get a 90-day free trial with no credit card required at sign-up. Once you have signed-up and verified your account, they will then provide you with a URL to use to access your tunnel. You will also need to provide them with your public SSH key in your account.

Tunnlr

Once you have this setup, then you need to create the tunnel from your computer. I created a shell script that I may run each time I want to have a tunnel.

create_tunnel.sh

Then, fire up your tunnel in a terminal window. Terminal — ssh — 80×24

Now that the hard part is over, write a Sinatra (or any others) app using our Tropo-WebAPI-Ruby gem and run it on the port you specified in your shell script above.

tunnlr_sample.rb

Thats it, now your Tropo WebAPI app is ready to run behind any firewall. Now you may demonstrate Tropo at that next developer meetup!

Ruby on Rails Example for Tropo Web API without port forwarding!

Friday, February 12th, 2010

Zhao Lu (aka @zlu) has shared a tutorial he has done using Ruby on Rails and our recently released Tropo Web API. The tutorial shows how to add, or build, the Tropo features to your Rails application in 15 minutes using our REST/JSON API. All of this deployed to Heroku for easy application deployment.

Another great thing that Zhao goes on to show, is the ability to use the Tropo Web API behind a firewall where you can not open or forward ports. For this he shows using Tunnlr to establish a remote SSH tunnel. With this tunnel you obtain a port on Tunnlr’s public IP address that forwards via your SSH tunnel to your application inside your firewall. This is great when you are on a company or university network where opening and forwarding a port through a firewall is not an option.

For more details have a look at the README. The full source code example is available on Github @ http://github.com/zlu/tropo-tutorial. A big thanks to Zhao for showing how easy it is to use the Tropo Web API!