Add endpoints for canadian and international providers. (fixes #2)

This commit is contained in:
Ian Webster 2014-03-20 10:37:18 -07:00
parent f9f7b708b2
commit 4f39bbcfe2
2 changed files with 178 additions and 30 deletions

42
app.js
View File

@ -6,7 +6,7 @@ var express = require('express')
, exec = require('child_process').exec , exec = require('child_process').exec
, spawn = require('child_process').spawn , spawn = require('child_process').spawn
, Stream = require('stream') , Stream = require('stream')
, providers = require('./providers.js').list , providers = require('./providers.js')
var mpq = new mixpanel.Client('6e6e6b71ed5ada4504c52d915388d73d'); var mpq = new mixpanel.Client('6e6e6b71ed5ada4504c52d915388d73d');
@ -34,6 +34,23 @@ app.get('/', function(req, res) {
}); });
app.post('/text', 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) { if (!req.body.number || !req.body.message) {
mpq.track('incomplete request'); mpq.track('incomplete request');
res.send({success:false,message:'Number and message parameters are required.'}); 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 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; var message = req.body.message;
if (message.indexOf('http') === 0) { if (message.indexOf('http') === 0) {
message = ' ' + message; message = ' ' + message;
@ -97,7 +108,7 @@ app.post('/text', function(req, res) {
}); });
}, 1000*60*60*24); }, 1000*60*60*24);
sendText(req.body.number, message, function(err) { sendText(req.body.number, message, region, function(err) {
if (err) { if (err) {
mpq.track('sendText failed', {number: req.body.number, message: req.body.message, ip: ip}); mpq.track('sendText failed', {number: req.body.number, message: req.body.message, ip: ip});
res.send({success:false,message:'Communication with SMS gateway failed.'}); res.send({success:false,message:'Communication with SMS gateway failed.'});
@ -111,7 +122,7 @@ app.post('/text', function(req, res) {
}); });
}); }
function dateStr() { function dateStr() {
var today = new Date(); var today = new Date();
@ -125,15 +136,18 @@ function stripPhone(phone) {
return (phone+'').replace(/\D/g, ''); return (phone+'').replace(/\D/g, '');
} }
function sendText(phone, message, cb) { function sendText(phone, message, region, cb) {
console.log('txting phone', phone); console.log('txting phone', phone, ':', message);
console.log('msg', message);
var done = _.after(providers.length, function() { region = region || 'us';
var providers_list = providers[region];
var done = _.after(providers_list.length, function() {
cb(false); cb(false);
}); });
_.each(providers, function(provider) { _.each(providers_list, function(provider) {
var email = provider.replace('%s', phone); var email = provider.replace('%s', phone);
var child = spawn('sendmail', ['-f', 'txt@textbelt.com', email]); var child = spawn('sendmail', ['-f', 'txt@textbelt.com', email]);
child.stdout.on('data', console.log); child.stdout.on('data', console.log);

View File

@ -1,23 +1,157 @@
module.exports = { module.exports = {
list: [ us: [
'%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',
'%s@email.uscc.net', '%s@email.uscc.net',
'%s@vtext.com', '%s@message.alltel.com',
'%s@vmobl.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@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',
],
}; };