Created
October 28, 2010 22:07
-
-
Save pdeschen/652433 to your computer and use it in GitHub Desktop.
Sends a SMS message to provided number using Apache HttpClient
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also: http://github.com/pdeschen/nubot-labs/raw/master/tropo/src/Sms.groovy