Posts Tagged ‘scripting’

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!

Sending outbound SMS with Java

Friday, May 6th, 2011

Tropo’s Java API allows you to send SMS messages from your Java applications with little or no effort. In this blog post I’ll go through a very simple application that sends an SMS message with very few lines of code.

To make it a little bit more exciting I will use Quartz‘s latest version. If you are not familiar with it, Quartz is a task scheduler library that you can use in Java to schedule and execute tasks. It is a very powerful library that has tons of different configuration options and integrates quite well with different application servers. Java veterans know it very well as it has been there almost from the very beginning. As Quartz was releasing a major upgrade this March, I decided to test how it works. I also thought that delivering scheduled messages would be a great real-life example of how Tropo can be useful for you. Imagine for example you can use to do SMS broadcasting, send advertisements, send alerts on health monitoring applications and many more exciting use cases.

So let’s start. The first step is to create your application. If you are familiar with Tropo’s WebApi model and in particular with the Java library ( if not, you can have a look to this introductory screencast ) you may expect that we would create a WebApi based application. But this is not the case. We are going to take advantage of Tropo’s Java API REST implementation to make it super-easy to send SMS messages. What we are going to do is to create a script in Tropo that will send the SMS message, get a session token, and invoke that tropo script from our Java application using the session token. So, let’s go. The first step is to create a Scripting based application:

Next, give it a name, like for example QuartzTest and click on the “use a Hosted File” link and next click on the “Create a new hosted file for this application” option, like is shown in the screenshot below:

Ok, we are almost there. Now you need to enter the script contents. This script will send the actual SMS outbound message. I will use the message function and pass the message text and the phone number as parameters. At the docs section you will find plenty of information about all the functions and cool actions you can execute from Tropo scripts. As you can see in the screenshot below, our script is super simple:

Ok, so once you have created your application the last step you need to do is to get your Session API token. We will use that token from Java to run the script that we just have created. So, to get access to your token you only need to go to your application screen and click on the Voice link (message token is also valid) at the bottom of your application. A new window will pop up showing your token information:

And that is it. Let’s go now to the Java world. I’ve created a very simple Java project that uses Quartz and invokes our new and shiny tropo script. I’ve uploaded this project to Github. You can find the source code on this link. Feel free to browse the project sources. As you will see, we are using Tropo’s Java Webapi binary libraries that you can find here. And there is just only two classes. One is the scheduler that creates a quartz job and sends it (I wont go into this code, as it is just some Quartz specific stuff). And the second class is the actual job that sends the SMS message using Tropo. Lets have a look to that class:

public class LongJob implements Job {

	@Override
	public void execute(JobExecutionContext arg0) throws JobExecutionException {

		try {
			// This coude launches your Tropo application. You can configure your tropo application to 
			// do things like sending an SMS, calliing a phone, etc. 
			String token = "f46f1f14bdd7684d9195ad83e1bbce021d0f024ad5e56e8c99cbd10e9cf3b2b026cb68749b41cb487dd09a5d";
			Tropo tropo = new Tropo();
			Map<String, String> params = new HashMap<String, String>();
			params.put("message","This is an SMS message");
			params.put("numberToDial", "+34637710708");
			tropo.launchSession(token, params);		

		} catch (InterruptedException e) {
			e.printStackTrace();
		}		
	}
}

That is all the code you need to send an SMS message from Java. Isn’t it cool? Lets go through the different parts of that snipped:

  1. First we create a new Tropo instance. The Tropo class drives all the interactions with the Tropo cloud.
  2. Next, we build a set of parameters. If you remember our script, we need to pass the message and the number that we are sending the message to. All the keys that you put on that params map will be accessible from your script.
  3. And finally we launch the session using the launchSession method. That method will use our token to launch remotely the Tropo script that we created previously. The script will fetch the parameters from the map and will send the SMS message.

Feel free to download and run the example. One word of caution though. Tropo supports international SMS delivery which is very cool. But it could happen that your country could have not been enabled yet. So, if you find that the SMS messages aren’t getting into your phone then let us know about it because we would have to enable SMS delivery to that country through one of our multiple carrier agreements.

And that is it. Hope you have fun with Tropo and Java!

Customer Service Hotline

Monday, December 6th, 2010

Do you wish that you had a local phone number or toll-free customer hotline? Well, we have a simple solution for your simple request!

The following application was written using Ruby and the Tropo Scripting API. One of our customers was looking for an inexpensive but reliable way to route their customers to an available system engineer. The system basically answers the customer’s call and puts them into a conference room name by the timestamp.  The application proceeds to call a comma delimited list of the engineers’ phone numbers. When an engineer answers the call, they can press ’1′ or say ‘one’ to speak to the customer or press/say anything else to have the system try calling the next available engineer. If none of the engineers accepted the call, the application loops through the numbers until someone accepts the call.

The cool thing about this application being built on the Tropo Scripting API is that it is hosted in our cloud at no additional charge. You can rest assured that even if your office loses power, we will route your customer service calls to your team without worrying about your own phone systems being online.

Here’s the code:

#Method to create timeStamp as our conferenceID
def get_conference_id()
	timeVar  = Time.new
	returnValue = timeVar.strftime("%Y%H%M%S")
	return returnValue
end

conferenceOptions={
	:mute=>false,
	:playTones=>true,
	:leaveprompt=>"beep"
}

begin

  #Create conference ID
  conferenceID = get_conference_id()

  answer

  #Call First Leg (User)
  log "@"*5 + "User has answered"
  #Create second thread for second leg (Operator)
  Thread.new do
    log "@"*5 + "Start second tread"

    phones = "14805551212,16025551212,16235551212"
    numbers = phones.split(",")

    count = 0
    keepcalling = true
    while keepcalling

      # event = call "tel:+" + numbers[count]
      call 'tel:+'+ numbers[count], {
  			:onAnswer=>lambda{|event|
  				log "@"*5+"Engineer answered join conference"
  				newCall = event.value
  				#announce caller
  				newCall.say "Hotline Calling. "
  				newCall.ask "Press or say 1 to accept the call", {
                     :choices => "[1 DIGITS]",
                     :timeout => 15.0,
                     :onChoice => lambda { |engineersays|
                  if engineersays.value == "1"
                    #add to conf
                    newCall.conference(conferenceID,conferenceOptions)
                    keepcalling = false
                    break
                  else
                    newCall.say "thanks. we will try to call another engineer"
                    newCall.hangup
                  end
              }
          }
  			}
  		}

      count = count + 1

      #loop again if no one has answered
      if count == numbers.length
        count = 0
      end
    end

  end #thread

  sleep 2
  say 'You have reached the hotline.  Please hold while we route you to an engineer.'
  conference(conferenceID,conferenceOptions)

end

You may notice that we used Ruby threading in this example.  Since the Tropo conference method is a blocking call, we simply kick off a new Ruby thread within the same application to handle the outbound dials trying to locate the engineer.

Both threads know the name of the conference room so both parties end up in the same conference room.  Many other programming languages offer the concept of threading making it easy to replicate this functionality in your language of choice.

In addition to Ruby, the Tropo Scripting API can leverage: PHP, Python, Groovy, and Javascript.

Tropo Now Speaks Asterisk Gateway Interface (AGI)

Friday, October 1st, 2010

The Asterisk community is a vibrant one, one that we actively support through our sponsorship and advocacy of Adhearsion. We have decided to take it a step further and created a Tropo Scripting application that turns Tropo into a giant Asterisk application platform in the cloud.   You can now run just about any Asterisk AGI application on Tropo.

Tropo AGItate was started on the Nerd Bird (good to have in-flight WiFi) from San Jose to Austin, on my way to LoneStar Ruby Conference. Jim Freeze – the organizer of LSRC – had recently been to AdhearsionConf in San Francisco; I wanted to be able to show something extra special during my talk there. On that one flight, I was able to get the basics working and show Tropo emitting AGI during my talk, just like that. (For those non-Asterisk folks out there, AGI is an API that lets external applications connect in to Asterisk and fully control it).

Since then, it’s been fun working on the application and expanding its capabilities. With Tropo AGItate, you could build your own interactive art display, a full blown cloud PBX like OpenVoice, or add Tropo capabilities to your own Asterisk server. The key features coming out today are:

  • Tropo can now speak AGI over TCP to any FastAGI server, including Adhearsion, PHPAGI, Asterisk-Java, etc.
  • A long list of Asterisk commands are supported, and of course all the Tropo ones.
  • While the script is written in Ruby, no Ruby knowledge is necessary to use it. Just point your Tropo application to the Ruby script on Github, upload a configuration file via FTP or WebDAV to your Tropo account, and you are ready.
  • Full support of Tropo Speech-Synthesis (TTS) and Speech-Recognition (ASR), but also for Asterisk sound files. Yes, tt-monkeys works!
  • Fail over to a SIP URI, in case your FastAGI server does not respond. This could be to another Tropo application, another Asterisk box, or anything that supports SIP.
  • You get all of the Tropo channels over AGI, including SMS, Instant Messaging and Twitter, all using the same application.
  • Support for custom SIP Headers in and out of Tropo.
  • And much more, with more to come…

Not only can you use AGI to write an entire cloud communications application, but you can also seamlessly integrate Tropo services into existing Asterisk systems using the interface you already know and love; after-all, its all SIP to us.

If you want to hear a Tropo AGItate ‘hello world’, give it a ring:

  • Phone/SMS: (408) 641-4410
  • Skype: +990009369991456829
  • SIP: sip:9991456829@sip.tropo.com
  • Jabber/XMPP: tropo_agitate@tropo.im

While this is great for all of the Asterisk developers out there, it also gave us the opportunity to showcase the power of the Tropo Scripting API. Tropo AGItate is 100% Tropo Scripting, no special libraries, no tricks, its all right there in the script. Tropo Scripting allows you to bend the Tropo cloud to your will; this is what we believe is truly innovative about our platform.

Stay tuned for more! We will be providing howtos, screencasts and more features soon.

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.