Posts Tagged ‘JavaScript’

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!

Want to play with building Twitter apps on Tropo? Here’s source code for 5 sample apps.

Wednesday, December 1st, 2010

twitterlogo-shadow-2.jpgIf you listened to yesterday’s Developer Jam Session, a good part of it discussed building Twitter apps on top of Tropo (slides are available). I’ve made the source code available from our Github account at:

https://github.com/tropo/tropo-twitter-samples

You are welcome to copy/paste that code into your own Tropo account and start building Twitter apps! (and Tropo accounts are free if you don’t have one already)

The five sample apps are:

  • twitter-helloback.js – A one-line “hello world” example that in reality is rather pointless, but shows all you need to do. It was written in JavaScript but could be done in any language. You can see this in action by sending a tweet to @tropohello
  • nightservice.py – An improved version of a python app I wrote about earlier this year that could be used to provide a “night service” when your staff goes home for the evening. You can try this app by tweeting to @stratohelp
  • twitter-keywordalerting.py – Scans Twitter replies or mentions for certain keywords (fail, faq, help, documentation) and then either sends someone a SMS alert or replies back with specific messages. You can try it out by tweeting to: @tropohelp
  • clubtropo.js – A simple JavaScript app that replies back with a message if you send it the correct phrase. Could be used for a contest or to let people RSVP. My colleague Justin Dupree wrote up a great step-by-step walkthrough on how to get started with this app. You can try it at, of course: @clubtropo
  • yahooweather.py – A new version of the python weather app I first wrote about back in March (and wrote later about how to tweak it for different channels). Tweet a US ZIP code to the app and it will tweet back the latest weather conditions. Try it out at: @danweathertest

I’ll probably add some more apps to the repository over time as we have some other good Twitter samples (and please contact me if you have a sample app you would like to contribute).

If you do try these out in your Tropo account, remember to watch out for duplicate tweets when you are testing. (I’ve been caught by this in testing any number of times.)

Have fun with it… and we’re looking forward to seeing what you will build with Tropo and Twitter!

P.S. Speaking of Twitter, are you following us on Twitter? We’re at @tropo, @voxeo, @phono and more…

Simple JavaScript SMS API: Text Messaging with Tropo

Monday, October 18th, 2010

So you want to build an application that sends and receives text messages?  SMS (Short Message Service) is widely used all over the world on mobile devices and can be a powerful notification/communications tool to connect to friends, customers or audience.  Even though the technologies behind sending and receiving these messages are relatively complex, sending and receiving text messages with Tropo is easy!

In this example we’re going to make a simple “Hello World” text messaging application using Tropo and JavaScript.  It should take you less than 10 minutes.

All you’ll need to try this example is  a Tropo account and a device capable of sending and receiving SMS text messages.   If you don’t already have a Tropo account, you can register for free at http://www.tropo.com/account/register.jsp and your login credentials will be e-mailed to you.  Once you have your credentials, click the Login link at the top right of the main Tropo site (tropo.com) and enter them in.   Go to Your Applications and then click on Create New Application.

SMS API JavaScript Tropo comes in two flavors, Scripting and WebAPI.  In this example, we’ll be using Tropo Scripting, so click on the Tropo Scripting Icon.

Javascript SMS API

In the box that says Tropo Scripting Application Name, type Hello World.  Next, click the link for Hosted File (next to What URL powers your app?), then click Create a new hosted file for this application.

SMS API JavaScript

Next you’ll see a pop-up window.  Type in the File Name box helloworld.js and then for the File Text, type (or copy/paste) these three lines of code:

answer()
say("Hello World") hangup

Tropo SMS API Javascript

After you’ve pasted the code, click Create File to save it, then when you’re returned to the New Application page, click the Create Application button to save your app.  Your screen should should now look something like this:

Tropo SMS API JavaScript

Click on the Add a new phone number link to get a standard phone number assigned (for free), then give it a few minutes to allow your application to propagate to our servers.

With your new app created and a phone number assigned, you’re ready to test! Send a text to the number, any text, and you should immediately receive the response “Hello World”.

That’s it!  You now have a working SMS application in its simplest form.  This should just be the beginning, though; the potential power of Tropo extends far beyond Hello World apps.  To delve deeper, check out this post: How To Get Started with SMS / Text Messaging on Tropo.com or go right to the Tropo SMS API docs.

If this helped you, please show us some love on Twitter.

Use Node.js & Javascript to Write Your Tropo Apps

Friday, October 1st, 2010

Today we would like to announce the availability of the Tropo WebAPI Node library for Node.js and the Tropo WebAPI. I have had a lot of fun working with the author – Mark Headd – to both grok Node.js and play with Tropo using this rising star of a framework.

For those of you new to Node.js it is a server side evented Javascript framework. If you have ever used the Python Twisted framework, or Ruby’s Eventmachine, you already have an idea of what Node.js is. You may write asynchronous apps that easily handle sockets or HTTP using Javascript on both the server and the browser.

A nice compliment to Node.js, in the context of the Tropo WebAPI, is the Express.js framework. Express is to Node.js what Sinatra is to Ruby. You may easily assign clojures to your various REST resources and serve up an application in no time. Here is an example:

/**
 * Showing with the Express framwork http://expressjs.com/
 * Express must be installed for this sample to work
 */

require('../../lib/tropo-webapi');
var express = require('express');
var app = express.createServer();

/**
 * Required to process the HTTP body
 * req.body has the Object while req.rawBody has the JSON string
 */
app.configure(function(){
	app.use(express.bodyDecoder());
});

app.post('/', function(req, res){
	// Create a new instance of the TropoWebAPI object.
	var tropo = new TropoWebAPI();
	// Use the say method https://www.tropo.com/docs/webapi/say.htm
	tropo.say("Welcome to my Tropo Web API node demo.");

	// Demonstrates how to use the base Tropo action classes.
	var say = new Say("Please enter your 5 digit zip code.");
	var choices = new Choices("[5 DIGITS]");

	// Action classes can be passes as parameters to TropoWebAPI class methods.
	// use the ask method https://www.tropo.com/docs/webapi/ask.htm
	tropo.ask(choices, 3, false, null, "foo", null, true, say, 5, null);
	// use the on method https://www.tropo.com/docs/webapi/on.htm
	tropo.on("continue", null, "/answer", true);

    res.send(TropoJSON(tropo));
});

app.post('/answer', function(req, res){
	// Create a new instance of the TropoWebAPI object.
	var tropo = new TropoWebAPI();
	tropo.say("Your zip code is " + req.body['result']['actions']['interpretation']);

	res.send(TropoJSON(tropo));
});

app.listen(8000);
console.log('Server running on http://0.0.0.0:8000/')

So what are you waiting for? Go to Github and get started!

Stay tuned as Mark Headd cooks up more good stuff, I hear he might be doing some interesting things with CouchDB. Every developer community would be so lucky to have a member like him. Thanks Mark!

Announcing the 10.10.10 GWOBorg Hackathon

Thursday, September 30th, 2010

Tropo is joining Heroku and Geeks Without Bounds to sponsor a hackathon on 10.10.10 to build +) GWOBorg applications to help save the world!

GWOBorg Logo+) GWOBorg (Geeks Without Bounds) is an international coalition of passionate problem solvers working together to assist people whose survival is threatened by lack of access to technology or communications due to violence, neglect, or catastrophe.

What is the 10.10.10 Hackathon?

This hackathon unites geeks all over the planet who are interested in creating applications that help people communicate more easily in situations where human lives are threatened.

We’ve identified some excellent free and open-source crisis-management platforms as well as group collaborative platforms (“The Platforms”), and we want to challenge developers to extend these platforms across the globe.  You can set up your own, or use one of the  ”sandbox” versions we will have running.

The Platforms we’re focusing on are:
  • UshahidiUshahidi is a free and open source platform that any person or organization can use to set up their own way to collect and visualize information. The core platform allows for plug-in and extensions so that it can be customized for different locales and needs.
  • Sahana - The Sahana project aims to provide an integrated set of pluggable, Web-based disaster management applications that provide solutions to large-scale humanitarian problems in the relief phase of a disaster.
  • Open AtriumOpen Atrium is an Drupal-based “intranet in a box” that has group spaces to allow different teams to have their own conversations. It comes with six features – a blog, a wiki, a calendar, a to do list, a shoutbox, and a dashboard to manage it all.

How to Participate

All you have to do is sign up to participate and then, during the hackathon, head to your local hacker/maker or co-working space and start coding.  Or create and develop from home –  you can participate anywhere just by signing up and developing.   If you do, you can qualify to win prizes (see below).

The 101010 +) GWOBorg Hackathon officially begins 10am EST on 10.09.10.  In order to qualify for a prize your app must be completed no later than 7:00am EST on 10.10.10.  Winners will be announced during the GWOBorg live broadcast at 1:10pm EST on 10.10.10.

Tropo Scripting Guide updated X 2 – now with PHP examples

Wednesday, August 25th, 2010

As promised, the Scripting Guide now includes PHP examples!  These go along with the original JavaScript examples and the recently added Ruby examples.   Now when you go take a look at each chapter, you’ll see:

Many of the examples in the guide have also been fleshed out, so they can be directly copied into a hosted file and actually work (though they’re usually still pretty simple).  If your flavor of choice is Python or Groovy, have faith – they’re incoming, as is a new and heavily improved WebAPI Guide.

Questions, comments, praise?  Send us an e-mail to support@tropo.com.  Interested in more complex examples?  Check out our Tutorials and Samples.

How to build an automated Twitter bot using JavaScript and Tropo

Friday, August 13th, 2010

We’re back with more how-to goodness!  While perusing our relatively extensive blogging history and existing documentation, we noticed the previous examples showing how to link Twitter and Tropo were moderately complex and potentially daunting, especially for someone just trying to get an initial feel for how it works.  So, in an attempt to remedy that, we endeavored to provide an easy, all-inclusive example from start to finish.  Hopefully we succeeded.

Our example today is a simple RSVP Twitter Bot; when someone tweets the Twitter account attached to your application, it responds back automatically with a confirmation indicating their RSVP was received.   In this case, we set it up to be password driven; if the application receives the Tweet “Tropo Rocks!”, it responds with an approval message.  Any other message will cause the Twitter bot to respond with a message indicating they sent the wrong password and to try again.

We’ll assume you have a Tropo account at this point and begin with creating your Twitter app.  If you don’t already have a account, you can click here to create one.

1) Login to your Tropo account, then go to Your Applications and click the Create New Application link:

2) Choose Tropo Scripting; this will bring up the New Application window:

3) Give the application a name; we chose ClubTropo to fit the example, but you can use whatever you’d like.  Next, click the link for Hosted File (next to What URL powers your app?) and choose Create a new hosted file for this application.  This will open the New Mapped File window:

4) You will need to give the file a name; as with the application name, it can be anything you like, but make sure this one ends with .js to identify it as Javascript .  In the box for File Text, enter in the following simple code:

message = currentCall.initialText;
if(message == "Tropo Rocks!"){
    say("You just learned how to make a Twitter bot with @Tropo for free!  Welcome to the club.");
}
else {
    say ("Say what?  Try it again - send us a tweet with the correct password to get on the list.");
}

Then click Create File to save it.

To explain what the code does:

  • We define the variable message as currentCall.initialText, which contains the tweet sent by the user (go here for more on currentCall).
  • Next, we specify what to tweet back if the user’s tweet has the correct message (i.e., Tropo Rocks!) and when it does not.
  • That’s it!  That’s all the code you need.

5) Once the file has been created and you’re back on the New Application screen, you’ll see the path to your file has been automatically filled in for you.  Now click Create Application to save the application as a whole:

6) This will bring up the page in the next screenshot.  Here, we need to add our Twitter account to the application; this will be the Twitter account that will act as the bot.  Select the Twitter icon at the bottom of the screen and you’ll see a link that says Click to activate Twitter.  This will attempt to connect to whatever Twitter account you’re currently logged into, so make sure you’re in the right one before you click the link.

7) Twitter will display a webpage in your browser asking you to Deny or Allow Tropo access to your Twitter account.  If you’re definitely in the right account, go ahead and click Allow:

8) You will then return back to the Tropo New Application screen and your Twitter account name will be listed:

9) Click the Update Application button to save the change, and you’re ready to test!  Our Twitter bot is named ClubTropo and we sent it a message from two different accounts.  From TropoUser, we sent “@ClubTropo Tropo Rules!”, which was rejected.  From JD_Gryph, we sent “@ClubTropo Tropo Rocks!”, which was accepted as the correct password.  Check out the responses below:

Voila!  RSVP Twitter Bot achieved.  Feel free to test with @ClubTropo and/or create your own; the door is wide open!

For more information, check out our Tropo Scripting documentation, or check out our Tutorials and Samples.

(Sidenote:  You may want to check out this blogpost before testing any Twitter apps; Twitter can be touchy with multiple instances of identical messages)

Get a text message when someone calls your app

Wednesday, July 7th, 2010

If you have a Tropo app and you want to get a notification every time someone calls it, you can add a single line of code somewhere in your application (right after answer() for instance) that will send you a text message telling you who called and which app they called you from.

In PHP….

message("Someone from " . $currentCall->callerID . " just called me.", array('to'=>'your number here', 'network' => 'sms', 'callerID' => $currentCall->calledID)); 

If you have an IM address attached to your app, you can get an IM instead. Just change the parameters of the message call. For example, if you have a Jabber name set up for your app, we can send a message to your Google Talk or other Jabber service. We give Jabber IDs away for free, just type in a name and click Activate.

Activating a Jabber ID

Once you have a Jabber ID for your app, just add the @tropo.im address to your contact list and change the code to send to Jabber.

message("Someone from " . $currentCall->callerID . " just called " . $currentCall->calledID, array('to'=>'your IM id here', 'network' => 'jabber')); 

Not using PHP? Just make some slight changes to adapt the code to the syntax of your chosen language. For instance, Python…

message("Someone from " + currentCall.callerID + " just called " + currentCall.calledID, {'to':'your IM id here', 'network':'jabber'}); 

… or JavaScript …

message("Someone from " + currentCall.callerID + " just called " + currentCall.calledID, {to:"your IM id here", network:"jabber"}); 

WebAPI: Now with outbound and transcription

Thursday, May 6th, 2010

When we released the new WebAPI last month, two things were missing. You couldn’t make an outbound call and transcription wasn’t available for recordings. Today we’ve added some things to make working with text and IM easier and brought parity to the Web and Scripting APIs, ensuring both have all the same features. So whether you want to host yourself and communicate over JSON or like the simplicity of our hosted Scripting API, you can do all the same things.

Here’s what’s new:

  • Outbound calls no longer require “Channel” parameter.
  • Quickly send a text message with new “message” feature
  • Outbound calling and messaging from the Web API
  • Transcriptions on the WebAPI
  • Sweden and Italy

No Channel required

When sending a text message or instant message, you need to provide call() with the network you want to send it out on. Previously we required you to also tell us if it was a voice or text channel. Obviously, if it’s an SMS message, it’s a text channel and not voice, so we’ve added defaults to the channel parameter. Now you can save a few keystrokes and just do this (JavaScript shown):

call('tel:+14075551212',{network:'SMS'});

Send a Message()

One thing people use Tropo’s text features for a lot is alerting. Sending a quick message out used to require that you set up a call, then say() something on that call and finally hang up the call. You can still do that if you want, but now you can do it all in one step;

<?php
message("Home team just scored. It's now Home: 4, Visitors: 1", array('network'=>'SMS', 'to'=>'14075551212'));
?>

Quick and easy, just fire off a message. This also comes in very handy if you want to fire of a text message while your application is on a voice call.

<?php
answer();
say('Thanks for calling the Tropo information service. Sending you a text message now.');
message('Here is what you were looking for...', array('network'=>'SMS', 'to'=>$currentCall->callerID));
?>

For reference, you can take a look at the message docs on either the Scripting or WebAPI.

Outward Bound

The session API can now kick off a WebAPI call. When you pass in the token for your WebAPI application, Tropo will now POST the JSON for the call to your URL so you can handle it. You can now respond to these POST requests with a new call element in the JSON.

{"tropo":[
   {"call":{
       "to":"tel:+13055195825"
   }},
   {"say":{
       "value":"Welcome to Tropo."
   }},
]}

For a full list of what options you can provide the call element, check out the WebAPI documentation for Call and the Session API.

Transcriptionist

When you record a caller’s input, you can now request that it be transcribed to text. Our transcription API can email you the text of the recording or POST it to the URL of your choosing.

{"tropo":[
   {"record":{
        "beep":true,
        "say":{
            "value":"I'm not here right now. Record your message after the beep."
        },
        "transcription": {
            "url":"mailto:you@example.com"
        }
    }},
]}

You can even pass in an ID that we’ll give to you when we hand you the transcription so you can tell different transcriptions apart. As always, the docs have the details on how to use a URL instead of email and all the other options you’ve got.

The new features are available for development applications today. The production servers will get upgraded in the near future, after we’ve seen the new code put through its paces on some developer applications.

And finally, we’ve added numbers in Sweden and Italy to our pool, allowing developers to purchase local numbers in those countries. Like elsewhere outside the US, these numbers can only be added to production accounts.

Deutsch? French? Spanish? How To Use International Text-To-Speech (TTS) in Tropo Apps

Thursday, April 1st, 2010

Last week we announced that Tropo now included for free the ability to support Text-To-Speech in 8 languages. In this post, I want to show you how you can easily implement this in your Tropo app. First, though, if you want to hear the different voices, you can call these numbers now and try it out:

+1 (407) 374-9911
Skype: +990009369991430013
SIP: sip:9991430013@sip.tropo.com
iNum: +883510001805741

Here is what the JavaScript code looks like for that application (thanks to Voxeon Ron Blaisdell):

answer();
wait('500');

say("Hello world! This is a demonstration of the various voices & languages on Tropo.");

//English Female - Allison - en-us
say("1 2 3 4 5 this is Allison", { voice: 'allison' });

//Spanish Castillian Female - Carmen - es-es
say("1 2 3 4 5 this is Carmen", { voice: 'carmen' });

//French Female - Florence - fr-fr
say("1 2 3 4 5 this is Florence", { voice: 'florence' });

//English UK - Kate - en-uk
say("1 2 3 4 5 this is Kate", { voice: 'kate' });

//German Female - Katrin - de-de
say("1 2 3 4 5 this is Katrin", { voice: 'katrin' });

//Italian Female - Paola - it-it
say("1 2 3 4 5 this is Paola", { voice: 'paola' });

//Dutch Female - Saskia - nl-nl
say("1 2 3 4 5 this is Saskia", { voice: 'saskia' });

//American Spanish Female - Soledad - es-mx
say("1 2 3 4 5 this is Soledad", { voice: 'soledad' });

say("ta da");

hangup();

That’s literally all you need to do… add the { voice:'name' } parameter to the say function and there you go!

Now for those of you who don’t use JavaScript, the syntax is similar for the other languages.

Ruby:

say "J'aime les écureuils!", :voice => 'florence'
say "1 2 3 4 5 this in Florence", :voice => 'florence'

Python:

say ("Guten Tag!", {'voice':'katrin'})
say ("1 2 3 4 5 this is Katrin", {'voice':'katrin'})

Groovy:

say( "Hola, como estas?", [ 'voice':"carmen" ])
say( "1 2 3 4 5 this is Carmen", [ 'voice':"carmen" ])

PHP:

<?php say ("J'aime les écureuils!", array('voice'=>'florence')); ?>
<?php say ("1 2 3 4 5, this is Florence", array('voice'=>'florence')); ?>

That’s it! Simple and easy…

Today we support these languages and currently only female voices, but you can expect to see us releasing support for even more languages as well as male voices in the weeks and months ahead. And if you have a project that needs a specific voice, please do email our support team and let them know what you need.