Skip to content

Instantly share code, notes, and snippets.

@adrienjoly
Created September 23, 2011 05:52
Show Gist options
  • Save adrienjoly/1236832 to your computer and use it in GitHub Desktop.
Save adrienjoly/1236832 to your computer and use it in GitHub Desktop.
A simple JSON-RPC call to send a SMS from Node.JS, through Thecallr
/**
* Send a SMS using "Thecallr" service
* @author adrienjoly, "Hear I Am" (#4sqHackathon)
*/
var https = require('https');
var authStr = new Buffer(login + ":" + password).toString('base64'); // <-- your creds here
exports.sendSMS = function (phone, msg, callback) {
var query = {
jsonrpc: "2.0",
id: 42,
method: "sms.send",
params: [
"THECALLR", // sender name
phone,
msg,
{"flash_message": false}
]
};
query = JSON.stringify(query);
var req = https.request({
host: "api.thecallr.com",
port: 443,
method: "POST",
headers: {
"Authorization" : "Basic " + authStr,
"Accept": "*/*",
"Content-Type": "application/json-rpc; charset=utf-8",
"Content-Length": query.length
}
}, function (res) {
var body = "";
res.addListener('data', function(chunk) {
body += chunk.toString();
});
res.addListener('end', function() {
if (callback) callback(body);
});
});
req.end(query);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment