(Special thanks to Mark Headd, developer evangelist from Tropo, for helping me out).
We’ve been using Twilio for a while now to make phone calls and send text messages. However, they removed their international SMS support, and I started looking around for another SMS provider.
So naturally I tried out Tropo, since I come across them once in a while. I did manage to get SMSes out, though there are some traps. Their API is also slightly confusing, but it works in the end.
Here are the steps, and some things to look out for, if you want to just get an SMS out.
Create a Tropo Scripting application. Associate it with a hosted javascript file that looks like this:
message(theMessage, {to:numberToDial, network:'sms'})
hangup()
I accidentally copied a Groovy example from the Tropo blog rather than a javascript example, and that totally threw me off. In that example, the message parameter is called “message”, which of course interferes with the message() function. And the associative array is specified using square brackets. Yes, I know, not javascript, but when you’re in “I want to copy the example and make this work” the brain turned off a little 🙂
Add a phone number to that Tropo application.
You can now send a message with a web browser:
http://api.tropo.com/1.0/sessions?action=create&token=<YOUR TOKEN>&theMessage=Hello&numberToDial=+1<YOUR NUMBER>
Note: The phone number must have NO spaces! It doesn’t work with spaces. Weird.
The java library also works (again, no spaces!):
String token = <YOUR TOKEN>;
Tropo tropo = new Tropo();
Map<String, String> params = new HashMap();
//params.put("numberToDial", "<YOUR NUMBER NO SPACES>");
params.put("theMessage", "Test from Tropo, Java. v5");
TropoLaunchResult result = tropo.launchSession(token, params);