Skip to content

Instantly share code, notes, and snippets.

@pdeschen
Created October 28, 2010 22:07
Show Gist options
  • Save pdeschen/652433 to your computer and use it in GitHub Desktop.
Save pdeschen/652433 to your computer and use it in GitHub Desktop.
Sends a SMS message to provided number using Apache HttpClient
// Uses a very very simple tropo script configured for your application
// See http://github.com/pdeschen/nubot-labs/raw/master/tropo/src/Sms.groovy
HttpClient mHttpClient = new HttpClient();
String mBaseUrl = "http://api.tropo.com/1.0/sessions";
GetMethod method = new GetMethod();
// here we have to throttle. We can't have more then x sms/minutes.
method.setPath(mBaseUrl);
NameValuePair[] query = new NameValuePair[]{new NameValuePair("action", "create"),
new NameValuePair("token", mToken),
new NameValuePair("msg", message),
new NameValuePair("to", recipient)};
method.setQueryString(query);
try {
int status = mHttpClient.executeMethod(method);
if (status != HttpURLConnection.HTTP_OK) {
String body = method.getResponseBodyAsString();
throw new NotificationAgentException("An error occured ["
+ status
+ "] while reaching tropo sms service at ["
+ mBaseUrl
+ "] with response ["
+ body
+ "]");
}
}
catch (Exception exception) {
throw new NotificationAgentException("An error occured while reaching tropo sms service at ["
+ mBaseUrl
+ "]");
}
finally {
method.releaseConnection();
}
@pdeschen
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment