Posted on by 4 comments

LinkedInGoogle+TwitterFacebook

Tropo’s coding model is designed around conversations. Ask a question, get an answer, ask something else, get another answer. Through grammars and our ask() functions, we make it easy to rapidly build a powerful automated phone or text conversation.

But what if you don’t want a conversation? What if you just want to send a text message out, without writing any code. One simple GET request and you’re on your way. And if someone texts your app, you just want that text posted somewhere like a form field would be.

One common case that’s come up a few times is people wanting to build SMS applications that run on SalesForce’s Force.com cloud. The Force.com programming language has a limitation that it can accept form posts, but sending other sorts of complex data into it doesn’t work. For example, there’s no way to receive and parse the JSON data that our WebAPI can send.

I’ve written a small application that anyone can use to do just this. Just drop it into your Tropo application and you can easily send text messages out. by passing the variables “to” and “msg” in the query string. Add in your secret API token from your Tropo account, and sending out messages is easy.

http://api.tropo.com/1.0/sessions?action=create&token=TOKEN&to=NUMBER&msg=MESSAGE

If you prefer to use POST to send your messages, Tropo can do that, too. Just post an XML document to us using the same fields above. The details of the document format can be found toward the end of our session API documentation.

To post incoming messages to a server, all you need to do is change one line in the code to add the URL you want to post to. You can also add a username and password if the server requires authentication.

Incoming messages are posted as form fields to your url. The fields “to”, “from” and “msg” contain the number (or IM address!) the message was sent to, the number or address the message was from, and the contents of the message.

Because Tropo works across multiple services with the same API, you can send and receive instant messages, too. Just remember, in order to send a message on a network, you need to have that an account for that network set up on your Tropo account. In other words, to send or receive SMS, you need an SMS phone number. To send or receive over Jabber, you need to add a Jabber account to your Tropo app.

The code is up on our GitHub account, so go read the short usage guide and grab it and try it out. You can even run it straight from GitHub without copying it up to Tropo if you want. Just fork it, edit to add your URL, then grab the “raw” url for the file off GitHub and use that as your Tropo app URL.

Here’s a short screencast showing you how to fork the code into your own github account, change the URL, and then use GitHub to serve the code to Tropo.

4 Responses to “Simple POST and GET interface to Tropo SMS”

  1. Jude

    Hi, I’m very new to this. I find nowhere to specify which script hosted on tropo to excute when incoming messages are sent. Does it mean all the supported scripts on my host space will be excuted?

    Thanks!

    Reply
  2. Dan York

    Jude,

    Welcome! We’re glad you are trying out Tropo! To use the simple POST and GET interface, the first step is that you login to your Tropo account and create a new application. The suggestion here:

    https://github.com/tropo/simpleMessage/blob/master/readme.markdown

    is to copy the code from:

    https://github.com/tropo/simpleMessage/raw/master/simpleMessage.php

    and paste that into a new file hosted in your Tropo account. As part of setting up the app, you will create this hosted file and that will be the only file on Tropo executed by the app.

    A Tropo app maps to one file (that you specify in the application configuration process).

    When you copy/paste the code in to your Tropo account, you will ALSO need to modify lines 18-20 to point to the URL back on your server to where the Tropo app will send the information:

    $url = ‘http://example.com’; // Tropo will POST incoming messages here
    $username = ”; // using HTTP Auth on your URL?
    $password = ”; // using HTTP Auth on your URL?

    The first line is the URL back on your server. The 2nd and 3rd line are only necessary if you are requiring HTTP authentication for the Tropo app to communication to your web app.

    Does that all make sense? Feel free to comment back if you need more info. You can also email us at “support@tropo.com” or catch us on IRC at #tropo on freenode.net.

    Thanks,
    Dan

    Reply
  3. Jude

    Thanks for your so detailed reply, I’ve got it working now. The previous app I created is using the webapi, that’s why I can’t find anywhere to specify a hosted script.

    I noticed that in the URL form you pasted a link on github, so if the script is not hosted on the tropo server, tropo will grab the source file then excute, right?

    Reply
  4. Adam Kalsey

    Yes, Tropo will download the source code from any URL you give it. Make sure your source appears at that URL as plain text, however. For example, if you try and use a PHP file on a server that executes PHP, we won’t get the source, we’ll get the output, and that won’t contain anything for Tropo to do.

    Reply

Leave a Reply

  • (will not be published)