Archive for the ‘Web API’ Category

Updated Version of the Python Module for the Tropo WebAPI

Friday, April 29th, 2011

Python logoFor you pythonistas out there, I merged in some changes today to the “tropo-webapi-python” module. My colleague Justin Dupree found and fixed an error where the “on” object was not included as an available option. With this fixed you can now send in events using the ‘on’ object.

To get the updated tropo-webapi-python library, you can download it (or git clone it) from:

https://github.com/tropo/tropo-webapi-python

… and if you already have a local clone of the git repo, odds are that you know how to update it ;-)

Alternatively you can also grab it from the PyPi repository:

http://pypi.python.org/pypi/tropo-webapi-python/

Thanks to Justin for the fix and thanks to other pythonistas who have reported issues. Speaking of that, if you do find any issues with the library, please report them to the “Issues” area on Github. Many thanks… and please let us know how else we can help you build awesome python apps using Tropo!

Empire Avenue Stock Quotes by SMS

Tuesday, April 26th, 2011

Have you heard of EmpireAvenue? According to their website, “Empire Avenue is the Social Media Exchange, where you can buy and sell shares in any social media profile, meet new people, unlock Achievement badges, and earn boatloads of virtual cash by being active and social online! Buy shares in your friends, your followers, people with similar interests, brands you love, celebrities – anyone! All using a virtual currency and all for free!”

Cas Hoefman, a long time telephony geek and friend of Tropo, built an SMS hook into their API!

If you want to see a working sample just send a text message with DISRUPTIVE to (818) 900-2731 to get back our latest stock price or replace DISRUPTIVE with your own Empire Avenue Ticker Symbol to get your own latest stock price!  You can also scan the QR code on the left and we’ll do it for you.

Using Tropo, you can add SMS to virtually API to further extend services to meet your needs.  For more details on Cas’ application including the source code, please visit his blog post!

Voice powered applications with Grails (Screencast)

Wednesday, April 20th, 2011

Grails Logo Hi. In a previous post we announced our new and shiny Grails Webapi library that allows all Grails developers to create voice and SMS powered applications very easily from their Grails applications.

If you go to the plugin’s web page at Grails.org you will find that there is already quite a few documentation out there. But I thought it would be quite useful to publish a screencast showing step by step how to create applications. This can be very interesting specially for developers that are not used to the Grails platform.

So here it is. It is a very short 15 minutes video in which I’ll show you how quick and easy you can create voice applications in Grails. I really hope you like it.

New Java based WebApi implementation

Thursday, February 24th, 2011

I’m happy to announce that Tropo finally has a Java based WebAPI implementation.

This implementation will allow every Java developer to create Tropo based applications with a very simple and lightweight API. This API hides all the communication and protocol details, making it much easier to deploy Tropo applications in a Java environment. It can be used with any Java program, including Application Servers like Tomcat, WebSphere or WebLogic as well as stand-alone applications.

As the other WebAPI implementations do, the Java WebAPI library offers a very simple but comprehensive DSL that can be used to create Tropo applications with syntax very close to natural language. However, in contrast to other implementations, the Java WebAPI is statically typed, which means we can catch errors at compile time. This makes it even easier for developers to create Tropo applications. Previous to this implementation, developers who wanted to use Tropo with Java had to create JSON documents by hand, inherently unfriendly and error-prone.

The sources of the Java WebAPI implementation are available from GitHub as usual, including documentation to help get you started. You can download the latest version of this library from the distribution folder, where you will also find all the required dependencies (of which there are not many). Building the Java WebAPI requires Apache Maven and is just a one line: mvn clean install.

There are plenty of examples on the project’s page at GitHub; I’ll share a couple of them now so you can see how easy it is to create Tropo applications in Java. Let’s start with a simple Java Servlet that will be the entry point to our Tropo application. Tropo sends a POST request to our application server each time a person calls a number, sends an SMS to our app, etc. – we just have to implement the doPost method from our Servlet.

protected void doPost(HttpServletRequest request,
                      HttpServletResponse response) 
                         throws ServletException, IOException {

    Tropo tropo = new Tropo();
    tropo.say("Hello from Tropo. This is our first application.");
    tropo.render(response);
}

How cool is that? No JSON, no response handling, just plain and easy Java code! Let’s look at another example – imagine you have a Tropo hosted application, which sends SMS to a number; this number is passed to Tropo as a parameter. You have a Java standalone application that you want to hook into this hosted app, in order to send an SMS based on a particular criteria (like when a file download is finished). You can simply use this Java implementation to launch your hosted application using the application’s token and pass the phone number at the same time. It would be as simple as this:

public void sendSMS(String number) {

    String token = ...
    Tropo tropo = new Tropo();
    Map params = new HashMap();
    params.put("number", number);
    tropo.launchSession(token, params);
}

Finally, the Java WebAPI also offers classes to deal with all results and incoming information from Tropo. For example, checking Tropo’s session object is very easy:

protected void doGet(HttpServletRequest request,
                     HttpServletResponse response) 
                        throws ServletException, IOException {

	Tropo tropo = new Tropo();
	TropoSession session = tropo.session(request);
	System.out.println("Call id: " + session.getCallId());
}

As you can see, writing Tropo applications in Java has never been that easy. We hope you like this new WebAPI implementation!

Tropo Powers PennApps Mobile Winner

Friday, January 28th, 2011

The recent PennApps Mobile competition, held at the University of Pennsylvania on January 14th through the 16th, brought together teams of students to work on the next generation of mobile applications.

Tropo was proud to be a sponsor of this event, and equally proud to see one of the event standouts use the Tropo platform.

A team of four Penn Computer Science Students (Lu Chen, Matt Croop, Gary Menezes and Ryan Menezes) used Tropo to build the Decider, one of the winners of the PennApps event with an interesting take on the contest theme – Serendipity.

We talked with the team to find out more about their project, and why they selected Tropo.

Briefly describe your project – what is it, what does it do?

What should we do tonight: watch a movie or play board games? Should I pull an all-nighter or get some sleep? These five desserts on the menu all look delicious… Which one should I order?

Instead of flipping a coin, why not let a stranger decide?

We used Tropo to build the Decider, which anonymously sends your question to a randomly chosen stranger who decides for you. You can send questions over SMS and IM, or with our Android app.

What technologies does your project use?

Decider is written in Python, hosted on Google App Engine, and reliant on Tropo’s WebAPI library for all of its SMS and IM needs. The Android app is built with Java.

Explain your decision to use the Tropo platform. Why did you choose Tropo?

We first considered Tropo because the demo given at the event convinced us that using it would be simple and free. A big bonus was the ability to seamlessly tie in IM: our original intent was to just handle SMS, but adding IM support was effortless.

Finally, Tropo’s scripting made it easy to quickly debug and test, while WebAPI gave us a lot of flexibility in choosing a backend.

What did you like best about using Tropo?

Tropo made it terrifically easy to get started. Even though we had no experience with messaging technologies, it took our team of four less than 6 hours to sign up, learn WebAPI, deploy an app, and test it over chat and sms. The docs and sample code were excellent.

What are your future plans? Any plans to take the project to a wider audience?

Right now, we still think of the Decider as a fun experiment — we aren’t actively searching for users, but we’ll definitely keep it up to speed as more people join.

This smart, talented bunch has a bright future.

We at Tropo wish them the best of luck in all their future endeavors and hope that our paths cross again soon.

Control Your Tropo Scripts with External Events

Thursday, January 20th, 2011

A few weeks back, Adam Kalsey introduced an exciting new piece of functionality on the Tropo platform – the ability to control a Tropo script by injecting events into a running session.

This type of functionality has lots of very cool applications – you can break a caller out of a long running process, or stop an executing action like a conference or a transfer. And what’s even cooler, now you can have access to all of this functionality through the existing Tropo WebAPI library for PHP.

Here is a quick example to demonstrate how to use external events to interrupt an executing action – in this case, an inbound call to a Tropo script that performs a transfer to another number.

Say, for example, that you wanted to limit the amount of time that a caller could stay on the transfer. With external events, it’s a snap.

Consider the follow sample script.

// Include required classes.
require 'classes/tropo.class.php';
require 'classes/sag/sag.php';

// Grab the raw JSON sent from Tropo.
$json = file_get_contents("php://input");

// Create a new Session object and obtain the session ID value.
$session = new Session($json);
$session_id = $session->getId();

// Insert the Session object into a CouchDB database called sessions.
try {
	$sag = new Sag();
	$sag->setDatabase("sessions");
	$sag->put($session_id, $json);	
}
catch (SagCouchException $ex) {
	die("*** ".$ex->getMessage()." ***");
}

// Create a new Tropo object.
$tropo = new Tropo();

$tropo->say("Please hold while your call is transferred.");
$tropo->transfer("5551112222", array("from" => "7861112233", "allowSignals" => "transferOver"));

// Set event handlers
$tropo->on(array("event" => "continue", "next" => "hangup.php?uri=end&timeout=false"));
$tropo->on(array("event" => "transferOver", "next" => "hangup.php?uri=end&timeout=true", "say" => "You have reached the time limit. Transfer over"));

// Render JSON for Tropo to consume.
$tropo->renderJSON();

As you can see, I’m using a property of the WebAPI Transfer object called “allowSignals” and giving it a value of transferOver. This is the name of the external event we want to send to our script. When it is received, our Tropo script will end execution of the transfer and invoke the handler set up for the transferOver event.

In order to control a Tropo script with external events, we need to know the unique ID for the session the Tropo script is executing in. We can get this from the Session object which is sent to our script at the inception of the call.

$session = new Session($json);
$session_id = $session->getId();

We want to store this session ID somewhere so that we can access it when we want to end an outbound transfer that has gone on longer than some set time interval. For the purposes of this example, I’m just going to stick it into a running instance of CouchDB. Since the session ID for our Tropo script is globally unique, we can use it as the document ID for our CouchDB document.

In this example, I’ using the very handy Sag CouchDB library for PHP. It’s dead simple, and makes working with CouchDB from PHP a snap.

For this example, I’m using a fresh CouchDB database named “sessions.” Because we want to insert a CouchDB document with a specific document ID, we’re going to do an HTTP PUT – we do this by simply invoking the put() method of the sag object:

$sag = new Sag();
$sag->setDatabase("sessions");
$sag->put($session_id, $json);	

Now we can send a transferOver event to the session running our Tropo script. This is easy to do with the new sendEvent() method of the Tropo class.

Here is a simple script that uses this method to send an event to a running script:

#! /usr/bin/php
<?php

if(empty($argv[1])) {
	die("*** You must use a Session ID with this script ***\n");
}

$session_id = $argv[1];
$event_name = $argv[2];
$path_to_classes = $argv[3];

require $path_to_classes.'/tropo.class.php';
$tropo = new Tropo();

try{

	if($tropo->sendEvent($session_id, $event_name)) {
		echo "Event { $event_name } successfully queued.\n";
	}
	else {
		echo "ERROR: Could not queue event { $event_name }.\n";
	}

}

catch(TropoException $ex) {
	die("*** There is big trouble in River City: ".$ex->getMessage()." ***");
}

After you make this script executable, you simply invoke it by:

  • Giving it the id of the session to send an event to;
  • The name of the event to send, and;
  • The path to the Tropo WebAPI library files.

When invoked, it will generate a response like this:

{"status": "QUEUED"}

This means that the event is queued and will be delivered to the session that is running our script.

When the event is delivered to the script, it interrupts the ongoing transfer and causes a Result object to be sent to the URL specified in the transferOver event handler. The JSON for the Result object looks like this:

{
    "result": {
        "sessionId": "bc9fe7edf356cfa045cf6d814ff07bf1",
        "callId": "b7feb41c8e50768733a8875713d5541e",
        "state": "ANSWERED",
        "sessionDuration": 94,
        "sequence": 1,
        "complete": true,
        "error": null,
        "actions": {
            "disposition": "EXTERNAL_EVENT"
        }
    }
}

Note the disposition value in this object – EXTERNAL_EVENT – this lets your application know that the result was caused by an external event being injected into the Tropo session.

This functionality opens up a host of new avenues for Tropo developers to build sophisticated applications.

We’ll be adding this functionality to other Tropo libraries in the days ahead, and if you use Tropo scripting it’s already available to you.

Have fun!

Build Node.js apps for Tropo that use voice, SMS, IM and Twitter and host them at NodeFu

Tuesday, January 18th, 2011

NodeFu-1.jpgHave you been itching to try out Node.JS for a real-time communication app? Perhaps a voice application? Or a SMS or IM agent? Or a Twitter-bot? Did you read about our Node.js library for the Tropo Web API released back in October and think “That would be a cool way to learn Node.js!” But have been put off by not having a server on the Internet where you could run your Node.JS apps?

You don’t have to wait any longer… our own Chris Matthieu of Voxeo Labs today launched a project he’s been working on in his spare time called “NodeFu that offers free hosting of Node.JS applications at:

http://nodefu.com

The beautiful thing is that NodeFu is an excellent platform to build Tropo apps that interact with users via voice, SMS, IM or Twitter.

How to Get Started with NodeFu

First, take a look at the NodeFu home page where the process is documented. You request an invite via a curl command from the command line:

curl -X POST -d "email=your_address@example.com" http://nodefu.com/coupon

You will get an invite with a link to register a new NodeFu account. After that, all your interaction with your application occurs through curl and git.

You start out by registering a new NodeFu application using another command-line curl command:

curl -X POST -u "testuser:123" -d "appname=myapp&start=hello.js" http://api.nodefu.com/app

Assuming your chosen “appname” is available, NodeFu will send back a bit of JSON that includes the port number your app will run on and the name of the git repo you will push to. (If your appname is not available you will see that in the JSON and will have to try again with a new appname.) As each NodeFu application runs on a different port, you will now need to edit your Node.js code to have your server run on this provided port number.

When you are ready to deploy your code to NodeFu, you then just do two git commands:

git remote add nodefu the_url_returned_by_our_api
git push nodefu master

Your NodeFu app will be live at http://appname.nodefu.com. As you work on your app, you just do more commits to your local git repo and then do

git push nodefu master

when you want to update the live app. Once you push to NodeFu, your app should automatically be updated.

If you are building your Node.js app with the tropo-webapi-node library, which is perhaps the easiest way to get started, you should be able to go to your “http://appname.nodefu.com/” URL and see the JSON that will be sent to Tropo.

Setting Up The Tropo Side

To connect your NodeFu app to the communication services, you need to login to your Tropo account (or create a new free account if you don’t have one). Once logged in, you’ll go to “Your Applications” and click on “Create New Application” and then click the big button above “Tropo WebAPI”, as shown in this image:

tropoaddapp.jpg

Next you’ll enter a name, which only shows up in your list of Tropo apps, so you can use whatever name will help you remember what the app is. Then you will enter the “http://appname.nodefu.com/” URL that corresponds to your app.

tropoappinfo.jpg

After you click the big “Create Application” button, your app is basically ready to go! You’ll see a list of phone numbers come up and you can get started right away calling into the app via Skype or from a SIP softphone. If you want to add a phone number, you just click the link on the right side and add one (or more) of the available phone numbers. You can also use the section under “Instant Messaging Networks” to connect your app to Jabber, AIM, GoogleTalk, MSN or Yahoo!Messenger IM accounts… or to connect your app to a Twitter account:

tropocontactmethods.jpg

Phone numbers are provided for free to developers in a range of states and countries around the world:

tropophonenumbers.jpg

That’s it! Now you can get started calling, SMS’ing, IM’ing or tweeting into your Node.js app hosted over at NodeFu!

You can try out the application above by calling or messaging one of the following numbers or addresses:

Voice & SMS Messaging: +1-860-578-2022
Skype Voice: +990009369991478873
SIP Voice: sip:9991478873@sip.tropo.com
INum Voice: +883510001827349
Jabber/GoogleTalk: nodefuhello@tropo.im

Tropo is providing the voice and SMS connectivity and then communicating with my app running over on NodeFu.com.

Kudos to Chris on the launch of NodeFu and we’re definitely looking forward to seeing what you all build with Tropo and Node.js!


P.S. Note that the process under “Setting Up The Tropo Side” is NOT specific to NodeFu – it’s the same process you would use for any application hosted externally and using the Tropo WebAPI. It could be any of the other Node.js hosting providers, or it could be a hosting provider for any other language out there. The only difference is going to be the URL that you provide as part of the application creation process.


Python Tropo WebAPI Library Now Available in PyPI for Easy Installation

Wednesday, January 5th, 2011

Python logoI’m pleased to announce that we’ve made it even easier for people to install the Tropo WebAPI library for python. (This lets you build apps that are hosted on your local system that communicate with Tropo for voice/SMS/IM/Twitter connectivity.)

Last night I uploaded the module to PyPI, the python package index, and as a result you can now simply type this command to install the latest version:

easy_install tropo-webapi-python

This assumes, of course, that you have the setuptools package installed, but that should be available in most python installations. (And if you don’t have it, you can get setuptools from PyPI and follow the instructions there.)

Alternatively, if you prefer to use the newer pip replacement for easy_install, you can type this command:

pip install tropo-webapi-python

(And pip is also available from PyPI if you want to trying using it versus easy_install.)

If you want to see the PyPI page describing the Tropo WebAPI library, it is at:

http://pypi.python.org/pypi/tropo-webapi-python/0.1.0

We’ll make sure to upload a new version after there have been any real changes to the python library. The definitive source will of course always be at the tropo-webapi-python Github page, but we’ll aim to make sure that the PyPI version tracks closely.

Many thanks to developer Randall Degges who raised an issue on Github asking if we could upload the library to PyPI. Thanks, Randall, for the suggestion!

P.S. Feel free to raise issues on Github with your suggestions (or fixes), too!

Get Your Node on with Tropo and Node.js

Thursday, December 9th, 2010

Node.js is a framework for writing server side JavaScript applications.

This video will provide an overview of how you can use Node.js, Tunnlr and the Tropo Node.js module to quickly and easy create powerful, sophisticated multi-channel communication applications.

Building communication apps in pure JavaScript has never been easier!

Hacking Awesomeness in Baltimore

Sunday, November 21st, 2010

Tropo was in Charm City this weekend for the first Baltimore Hackathon, which took place at Beehive Baltimore – a co-working space in Baltimore’s Canton neighborhood.

This thoroughly awesome location was the appropriate setting for a get together of hardware and software hackers from around the Baltimore area to come together and bang out great ideas over the weekend.

As hackathons go, it was a really special event.

Not only was it the first hackathon in Baltimore, but it was somewhat unique in that it focused on both software development and hardware hacking as well. All of the developers in attendance were smart, passionate technologists; the location along Baltimore’s harbor was outstanding; the event was organized exceptionally well and ran smoothly; the food was great; even the beer was good.

Tropo was on hand as a sponsor of the event and also to lend a hand to developers that wanted to add phone, voice or SMS awesomeness to their apps. Tropo’s APIs were used in some really impressive projects during the event.

For example Brent Frederick of Baltimore built what he refers to as VoiceBump – an app that lets people call a phone number and create a blog post with Tropo’s recording and transcription services.

Another app – Call the Door by Mike Brenner – uses Tropo’s SMS service to unlock the door at the building where the event was held (locked doors can turn into something of a hindrance when your coding all night).

Tropo also provided a special award at the event – giving a prize to the devleoper of the app with the best use of our services. An update with the name of the winner (or winners) and a description of the project will be posted in the next day or two.

In the interim, here are some pictures from the event.

Update: all of the winners from the Baltimore Hackathon are now listed on the Startup Baltimore site. Congratulations to all the winners!

Baltimore Hackathon

Baltimore Hackathon

Baltimore Hackathon

Baltimore Hackathon