From 4f39bbcfe20b9f7ec45f68a6146a4fa85662ff3b Mon Sep 17 00:00:00 2001 From: Ian Webster Date: Thu, 20 Mar 2014 10:37:18 -0700 Subject: [PATCH] Add endpoints for canadian and international providers. (fixes #2) --- app.js | 42 ++++++++----- providers.js | 166 ++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 178 insertions(+), 30 deletions(-) diff --git a/app.js b/app.js index 4c89b9d..cc88200 100644 --- a/app.js +++ b/app.js @@ -6,7 +6,7 @@ var express = require('express') , exec = require('child_process').exec , spawn = require('child_process').spawn , Stream = require('stream') - , providers = require('./providers.js').list + , providers = require('./providers.js') var mpq = new mixpanel.Client('6e6e6b71ed5ada4504c52d915388d73d'); @@ -34,6 +34,23 @@ app.get('/', function(req, res) { }); app.post('/text', function(req, res) { + var number = stripPhone(req.body.number); + if (number.length < 9 || number.length > 10) { + res.send({success:false,message:'Invalid phone number.'}); + return; + } + textRequestHandler(req, res, number, 'us'); +}); + +app.post('/canada', function(req, res) { + textRequestHandler(req, res, stripPhone(req.body.number), 'canada'); +}); + +app.post('/intl', function(req, res) { + textRequestHandler(req, res, stripPhone(req.body.number), 'intl'); +}); + +function textRequestHandler(req, res, number, region) { if (!req.body.number || !req.body.message) { mpq.track('incomplete request'); res.send({success:false,message:'Number and message parameters are required.'}); @@ -41,12 +58,6 @@ app.post('/text', function(req, res) { } var ip = req.header('X-Real-IP');// || req.connection.remoteAddress; - var number = stripPhone(req.body.number); - if (number.length < 9 || number.length > 10) { - res.send({success:false,message:'Invalid phone number.'}); - return; - } - var message = req.body.message; if (message.indexOf('http') === 0) { message = ' ' + message; @@ -97,7 +108,7 @@ app.post('/text', function(req, res) { }); }, 1000*60*60*24); - sendText(req.body.number, message, function(err) { + sendText(req.body.number, message, region, function(err) { if (err) { mpq.track('sendText failed', {number: req.body.number, message: req.body.message, ip: ip}); res.send({success:false,message:'Communication with SMS gateway failed.'}); @@ -111,7 +122,7 @@ app.post('/text', function(req, res) { }); -}); +} function dateStr() { var today = new Date(); @@ -125,15 +136,18 @@ function stripPhone(phone) { return (phone+'').replace(/\D/g, ''); } -function sendText(phone, message, cb) { - console.log('txting phone', phone); - console.log('msg', message); +function sendText(phone, message, region, cb) { + console.log('txting phone', phone, ':', message); - var done = _.after(providers.length, function() { + region = region || 'us'; + + var providers_list = providers[region]; + + var done = _.after(providers_list.length, function() { cb(false); }); - _.each(providers, function(provider) { + _.each(providers_list, function(provider) { var email = provider.replace('%s', phone); var child = spawn('sendmail', ['-f', 'txt@textbelt.com', email]); child.stdout.on('data', console.log); diff --git a/providers.js b/providers.js index 02488a3..13edb4e 100644 --- a/providers.js +++ b/providers.js @@ -1,23 +1,157 @@ module.exports = { - list: [ - '%s@message.alltel.com', - '%s@paging.acswireless.com', - '%s@txt.att.net', - '%s@myboostmobile.com', - //'%s@sms.edgewireless.com', // slow - '%s@messaging.sprintpcs.com', - '%s@tmomail.net', - '%s@mymetropcs.com', - '%s@messaging.nextel.com', - '%s@mobile.celloneusa.com', - '%s@qwestmp.com', - '%s@pcs.rogers.com', - '%s@msg.telus.com', + us: [ '%s@email.uscc.net', - '%s@vtext.com', - '%s@vmobl.com', + '%s@message.alltel.com', + '%s@messaging.nextel.com', + '%s@messaging.sprintpcs.com', + '%s@mobile.celloneusa.com', + '%s@msg.telus.com', + '%s@myboostmobile.com', + '%s@mymetropcs.com', + '%s@paging.acswireless.com', + '%s@pcs.rogers.com', + '%s@qwestmp.com', + '%s@tmomail.net', + '%s@txt.att.net', '%s@txt.windmobile.ca', + '%s@vmobl.com', + '%s@vtext.com', + + //'%s@sms.edgewireless.com', // slow ], + + canada: [ + '%s@bellmobility.ca', + '%s@blueskyfrog.com', + '%s@bplmobile.com', + '%s@cellularonewest.com', + '%s@clearlydigital.com', + '%s@comcastpcs.textmsg.com', + '%s@corrwireless.net', + '%s@csouth1.com', + '%s@cwemail.com', + '%s@cwwsms.com', + '%s@email.swbw.com', + '%s@email.uscc.net', + '%s@fido.ca', + '%s@ideacellular.net', + '%s@inlandlink.com', + '%s@ivctext.com', + '%s@message.alltel.com', + '%s@messaging.centurytel.net', + '%s@messaging.nextel.com', + '%s@messaging.sprintpcs.com', + '%s@mobile.celloneusa.com', + '%s@mobile.dobson.net', + '%s@mobile.surewest.com', + '%s@mobilecomm.net', + '%s@msg.clearnet.com', + '%s@msg.telus.com', + '%s@my2way.com', + '%s@myboostmobile.com', + '%s@mymetropcs.com', + '%s@onlinebeep.net', + '%s@page.metrocall.com', + '%s@pagemci.com', + '%s@paging.acswireless.com', + '%s@pcs.rogers.com', + '%s@pcsone.net', + '%s@qwestmp.com', + '%s@satellink.net', + '%s@sms.3rivers.net', + '%s@sms.bluecell.com', + '%s@sms.edgewireless.com', + '%s@sms.goldentele.com', + '%s@sms.pscel.com', + '%s@sms.wcc.net', + '%s@text.houstoncellular.net', + '%s@text.mtsmobility.com', + '%s@tmomail.net', + '%s@tms.suncom.com', + '%s@txt.att.net', + '%s@txt.bell.ca', + '%s@txt.bellmobility.ca', + '%s@uswestdatamail.com', + '%s@utext.com', + '%s@vmobile.ca', + '%s@vmobl.com', + '%s@vtext.com', + ], + + intl: [ + '%s@airtelchennai.com', + '%s@airtelkol.com', + '%s@airtelmail.com', + '%s@alphame.com', + '%s@bluewin.ch', + '%s@bplmobile.com', + '%s@c.vodafone.ne.jp', + '%s@celforce.com', + '%s@correo.movistar.net', + '%s@delhi.hutch.co.in', + '%s@e-page.net', + '%s@escotelmobile.com', + '%s@freesurf.ch', + '%s@gsm1800.telia.dk', + '%s@h.vodafone.ne.jp', + '%s@ideacellular.net', + '%s@m1.com.sg', + '%s@ml.bm', + '%s@mmail.co.uk', + '%s@mobilpost.no', + '%s@mobistar.be', + '%s@mobtel.co.yu', + '%s@movistar.net', + '%s@mujoskar.cz', + '%s@mymeteor.ie', + '%s@mysmart.mymobile.ph', + '%s@mysunrise.ch', + '%s@o2.co.uk', + '%s@o2imail.co.uk', + '%s@onemail.at', + '%s@onlinebeep.net', + '%s@optusmobile.com.au', + '%s@orange.net', + '%s@orangemail.co.in', + '%s@page.mobilfone.com', + '%s@page.southernlinc.com', + '%s@pageme.teletouch.com', + '%s@pager.irkutsk.ru', + '%s@pcs.ntelos.com', + '%s@rpgmail.net', + '%s@safaricomsms.com', + '%s@satelindogsm.com', + '%s@scs-900.ru', + '%s@sfr.fr', + '%s@sms.co.tz', + '%s@sms.comviq.se', + '%s@sms.emt.ee', + '%s@sms.goldentele.com', + '%s@sms.luxgsm.lu', + '%s@sms.netcom.no', + '%s@sms.orange.nl', + '%s@sms.primtel.ru', + '%s@sms.t-mobile.at', + '%s@sms.tele2.lv', + '%s@sms.umc.com.ua', + '%s@sms.uraltel.ru', + '%s@sms.vodafone.it', + '%s@smsmail.lmt.lv', + '%s@swmsg.com', + '%s@t-d1-sms.de', + '%s@t-mobile-sms.de', + '%s@t-mobile.uk.net', + '%s@t.vodafone.ne.jp', + '%s@text.mtsmobility.com', + '%s@text.simplefreedom.net', + '%s@timnet.com', + '%s@vodafone.net', + '%s@wyndtell.com', + + //'sms@pcom.ru (put the number in the subject line)', + //'pinnumber@jsmtel.com', + ], + };