Skip to content

Instantly share code, notes, and snippets.

@dmongeau
Created March 30, 2012 20:09
Show Gist options
  • Save dmongeau/2254589 to your computer and use it in GitHub Desktop.
Save dmongeau/2254589 to your computer and use it in GitHub Desktop.
Forward tweets to SMS using node.js, Twilio and Twitter stream api
/*
*
*
* Forward tweets to SMS in realtime
*
*
*/
var TWILIO_ACCOUNT_SID = ''; //Twilio Account SID
var TWILIO_AUTH_TOKEN = ''; //Twilio AUTH Token
var TWILIO_FROM = '+15141231234'; //Your twilio number
var TWILIO_TO = '+15141231234'; //The cellphone number to Spam
var TWITTER_USER = ''; //Twitter username
var TWITTER_PWD = ''; //Twitter password
var TWITTER_FOLLOW = ['bieber']; //Twitter words to track
var TwitterNode = require('twitter-node').TwitterNode,
sys = require('sys');
var TwilioClient = require('twilio').Client,
client = new TwilioClient(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, 'localhost');
var phone = client.getPhoneNumber(TWILIO_FROM);
phone.setup(function() {
console.log('Phone ready.');
// you can pass args to create() or set them on the TwitterNode instance
var twit = new TwitterNode({
user: TWITTER_USER,
password: TWITTER_PWD,
track: ['bean']
});
function sendSMS(sms) {
console.log('sendSMS',sms);
phone.sendSms(TWILIO_TO, sms, null, function(sms) {
});
}
twit.headers['User-Agent'] = 'whatever';
twit.addListener('error', function(error) {
console.log(error.message);
});
twit.addListener('tweet', function(tweet) {
sendSMS('@'+tweet.user.screen_name+': '+tweet.text);
}).addListener('limit', function(limit) {
sys.puts("LIMIT: " + sys.inspect(limit));
}).addListener('delete', function(del) {
sys.puts("DELETE: " + sys.inspect(del));
}).addListener('end', function(resp) {
sys.puts("wave goodbye... " + resp.statusCode);
}).stream();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment