Merge pull request #57 from alexionescu/carrier-support

Added carrier support. typpo/textbelt#56
This commit is contained in:
Ian Webster 2015-12-05 11:24:45 -08:00
commit 4a84a8dbaa
3 changed files with 424 additions and 7 deletions

398
lib/carriers.js Normal file
View File

@ -0,0 +1,398 @@
module.exports = {
uscellular: [
'%s@email.uscc.net',
],
alltel: [
'%s@message.alltel.com',
],
ting: [
'%s@message.ting.com',
],
sprint: [
'%s@messaging.sprintpcs.com',
],
cellone: [
'%s@mobile.celloneusa.com',
],
telus: [
'%s@msg.telus.com',
],
alaskacommunications: [
'%s@paging.acswireless.com',
],
rogers: [
'%s@pcs.rogers.com',
],
cricket: [
'%s@sms.mycricket.com',
],
tmobile: [
'%s@tmomail.net',
],
att: [
'%s@txt.att.net',
],
westernwireless: [
'%s@cellularonewest.com',
],
windmobile: [
'%s@txt.windmobile.ca',
],
verizon: [
'%s@vtext.com',
],
republic: [
'%s@text.republicwireless.com'
],
/*edgewireless: [
//'%s@sms.edgewireless.com', // slow
],*/
bluskyfrog: [
'%s@blueskyfrog.com',
],
loopmobile: [
'%s@bplmobile.com',
],
clearlydigital: [
'%s@clearlydigital.com',
],
comcast: [
'%s@comcastpcs.textmsg.com',
],
corrwireless: [
'%s@corrwireless.net',
],
cellularsouth: [
'%s@csouth1.com',
],
centennialwireless: [
'%s@cwemail.com',
],
carolinawestwireless: [
'%s@cwwsms.com',
],
southwesternbell: [
'%s@email.swbw.com',
],
fido: [
'%s@fido.ca',
],
ideacellular: [
'%s@ideacellular.net',
],
indianapaging: [
'%s@inlandlink.com',
],
illinoisvalleycellular: [
'%s@ivctext.com',
],
alltel: [
'%s@message.alltel.com',
],
centurytel: [
'%s@messaging.centurytel.net',
],
dobson: [
'%s@mobile.dobson.net',
],
surewestcommunications: [
'%s@mobile.surewest.com',
],
mobilcomm: [
'%s@mobilecomm.net',
],
clearnet: [
'%s@msg.clearnet.com',
],
koodomobile: [
'%s@msg.koodomobile.com',
],
metrocall2way: [
'%s@my2way.com',
],
boostmobile: [
'%s@myboostmobile.com',
],
onlinebeep: [
'%s@onlinebeep.net',
],
metrocall: [
'%s@page.metrocall.com',
],
mci: [
'%s@pagemci.com',
],
ameritechpaging: [
'%s@paging.acswireless.com',
],
pcsone: [
'%s@pcsone.net',
],
qwest: [
'%s@qwestmp.com',
],
satellink: [
'%s@satellink.net',
],
threeriverwireless: [
'%s@sms.3rivers.net',
],
bluegrasscellular: [
'%s@sms.bluecell.com',
],
edgewireless: [
'%s@sms.edgewireless.com',
],
goldentelecom: [
'%s@sms.goldentele.com',
],
publicservicecellular: [
'%s@sms.pscel.com',
],
westcentralwireless: [
'%s@sms.wcc.net',
],
houstoncellular: [
'%s@text.houstoncellular.net',
],
mts: [
'%s@text.mtsmobility.com',
],
suncom: [
'%s@tms.suncom.com',
],
bellmobilitycanada: [
'%s@txt.bell.ca',
],
northerntelmobility: [
'%s@txt.northerntelmobility.com',
],
uswest: [
'%s@uswestdatamail.com',
],
unicel: [
'%s@utext.com',
],
virginmobilecanada: [
'%s@vmobile.ca',
],
virginmobile: [
'%s@vmobl.com',
],
airtelchennai: [
'%s@airtelchennai.com',
],
kolkataairtel: [
'%s@airtelkol.com',
],
delhiairtel: [
'%s@airtelmail.com',
],
tsrwireless: [
'%s@alphame.com',
],
swisscom: [
'%s@bluewin.ch',
],
mumbaibplmobile: [
'%s@bplmobile.com',
],
vodafonejapan: [
'%s@c.vodafone.ne.jp',
'%s@h.vodafone.ne.jp',
'%s@t.vodafone.ne.jp',
],
gujaratcelforce: [
'%s@celforce.com',
],
movistar: [
'%s@correo.movistar.net',
],
delhihutch: [
'%s@delhi.hutch.co.in',
],
digitextjamacian: [
'%s@digitextjm.com',
],
jsmtelepage: [
'%s@e-page.net',
],
escotel: [
'%s@escotelmobile.com',
],
surewestcommunications: [
'%s@freesurf.ch',
],
teliadenmark: [
'%s@gsm1800.telia.dk',
],
ideacellular: [
'%s@ideacellular.net',
],
itelcel: [
'%s@itelcel.com',
],
mobileone: [
'%s@m1.com.sg',
],
m1bermuda: [
'%s@ml.bm',
],
o2mmail: [
'%s@mmail.co.uk',
],
telenor: [
'%s@mobilpost.no',
],
mobistarbelgium: [
'%s@mobistar.be',
],
mobtelsrbija: [
'%s@mobtel.co.yu',
],
telefonicamovistar: [
'%s@movistar.net',
],
nextelmexico: [
'%s@msgnextel.com.mx',
],
globalstar: [
'%s@msg.globalstarusa.com',
],
iridiumsatellitecommunications: [
'%s@msg.iridium.com',
],
oskar: [
'%s@mujoskar.cz',
],
meteor: [
'%s@mymeteor.ie',
],
smarttelecom: [
'%s@mysmart.mymobile.ph',
],
sunrisemobile: [
'%s@mysunrise.ch',
'%s@swmsg.com',
],
o2: [
'%s@o2.co.uk',
'%s@o2imail.co.uk',
],
oneconnectaustria: [
'%s@onemail.at',
],
onlinebeep: [
'%s@onlinebeep.net',
],
optusmobile: [
'%s@optusmobile.com.au',
],
/*orange: [
//'%s@orange.net',
//'%s@orangemail.co.in',
],*/
mobilfone: [
'%s@page.mobilfone.com',
],
southernlinc: [
'%s@page.southernlinc.com',
],
teletouch: [
'%s@pageme.teletouch.com',
],
vessotel: [
'%s@pager.irkutsk.ru',
],
ntelos: [
'%s@pcs.ntelos.com',
],
rek2: [
'%s@rek2.com.mx',
],
chennairpgcellular: [
'%s@rpgmail.net',
],
safaricom: [
'%s@safaricomsms.com',
],
satelindogsm: [
'%s@satelindogsm.com',
],
scs900: [
'%s@scs-900.ru',
],
sfrfrance: [
'%s@sfr.fr',
],
mobiteltanzania: [
'%s@sms.co.tz',
],
comviq: [
'%s@sms.comviq.se',
],
emt: [
'%s@sms.emt.ee',
],
geldentelecom: [
'%s@sms.goldentele.com',
],
pandtluxembourg: [
'%s@sms.luxgsm.lu',
],
netcom: [
'%s@sms.netcom.no',
],
/*orangenl: [
//'%s@sms.orange.nl',
],*/
primtel: [
'%s@sms.primtel.ru',
],
tmobileaustria: [
'%s@sms.t-mobile.at',
],
tele2lativa: [
'%s@sms.tele2.lv',
],
umc: [
'%s@sms.umc.com.ua',
],
uraltel: [
'%s@sms.uraltel.ru',
],
vodafoneitaly: [
'%s@sms.vodafone.it',
],
lmt: [
'%s@smsmail.lmt.lv',
],
tmobilegermany: [
'%s@t-d1-sms.de',
],
dttmobile: [
'%s@t-mobile-sms.de',
],
tmobileuk: [
'%s@t-mobile.uk.net',
],
simplefreedom: [
'%s@text.simplefreedom.net',
],
tim: [
'%s@timnet.com',
],
vodafone: [
'%s@vodafone.net',
],
wyndtell: [
'%s@wyndtell.com',
],
/*personalcommunication: [
//'sms@pcom.ru (put the number in the subject line)',
],*/
/*jsmtelepage: [
//'pinnumber@jsmtel.com',
],*/
};

View File

@ -1,5 +1,6 @@
var providers = require('./providers.js') var providers = require('./providers.js')
, _ = require('underscore') , _ = require('underscore')
, carriers = require('./carriers.js')
, exec = require('child_process').exec , exec = require('child_process').exec
, spawn = require('child_process').spawn; , spawn = require('child_process').spawn;
var StringDecoder = require('string_decoder').StringDecoder; var StringDecoder = require('string_decoder').StringDecoder;
@ -46,12 +47,17 @@ function debug(enable) {
region - region to use (defaults to US) region - region to use (defaults to US)
cb - function(err), provides err messages cb - function(err), provides err messages
*/ */
function sendText(phone, message, region, cb) { function sendText(phone, message, carrier, region, cb) {
output('txting phone', phone, ':', message); output('txting phone', phone, ':', message);
region = region || 'us'; region = region || 'us';
var providers_list = providers[region]; var providers_list;
if (carrier == null) {
providers_list = providers[region];
} else {
providers_list = carriers[carrier];
}
var emails = providers_list.map(function(provider) { var emails = providers_list.map(function(provider) {
return provider.replace('%s', phone); return provider.replace('%s', phone);

View File

@ -1,6 +1,7 @@
var express = require('express') var express = require('express')
, app = express() , app = express()
, _ = require('underscore') , _ = require('underscore')
, carriers = require('../lib/carriers.js')
, crypto = require('crypto') , crypto = require('crypto')
, exec = require('child_process').exec , exec = require('child_process').exec
, fs = require('fs') , fs = require('fs')
@ -83,25 +84,29 @@ app.get('/providers/:region', function(req, res) {
}); });
app.post('/text', function(req, res) { app.post('/text', function(req, res) {
if (req.body.getcarriers != null && (req.body.getcarriers == 1 || req.body.getcarriers.toLowerCase() == 'true')) {
res.send({success:true, carriers:Object.keys(carriers).sort()});
return;
}
var number = stripPhone(req.body.number); var number = stripPhone(req.body.number);
if (number.length < 9 || number.length > 10) { if (number.length < 9 || number.length > 10) {
res.send({success:false, message:'Invalid phone number.'}); res.send({success:false, message:'Invalid phone number.'});
return; return;
} }
textRequestHandler(req, res, number, 'us', req.query.key); textRequestHandler(req, res, number, req.body.carrier, 'us', req.query.key);
}); });
app.post('/canada', function(req, res) { app.post('/canada', function(req, res) {
textRequestHandler(req, res, stripPhone(req.body.number), 'canada', req.query.key); textRequestHandler(req, res, stripPhone(req.body.number), req.body.carrier, 'canada', req.query.key);
}); });
app.post('/intl', function(req, res) { app.post('/intl', function(req, res) {
textRequestHandler(req, res, stripPhone(req.body.number), 'intl', req.query.key); textRequestHandler(req, res, stripPhone(req.body.number), req.body.carrier, 'intl', req.query.key);
}); });
// App helper functions // App helper functions
function textRequestHandler(req, res, number, region, key) { function textRequestHandler(req, res, number, carrier, region, key) {
var ip = req.connection.remoteAddress; var ip = req.connection.remoteAddress;
if (!ip || ip === '127.0.0.1') { if (!ip || ip === '127.0.0.1') {
ip = req.header('X-Real-IP'); ip = req.header('X-Real-IP');
@ -115,6 +120,14 @@ function textRequestHandler(req, res, number, region, key) {
res.send({success:false, message:'Number and message parameters are required.'}); res.send({success:false, message:'Number and message parameters are required.'});
return; return;
} }
if (carrier != null) {
carrier = carrier.toLowerCase();
if (carriers[carrier] == null) {
res.send({succes:false, message:'Carrier ' + carrier + ' not supported! POST getcarriers=1 to '
+ 'get a list of supported carriers'});
return;
}
}
var message = req.body.message; var message = req.body.message;
if (message.indexOf(':') > -1) { if (message.indexOf(':') > -1) {
@ -150,7 +163,7 @@ function textRequestHandler(req, res, number, region, key) {
response_obj = response_obj || {}; response_obj = response_obj || {};
// Time to actually send the message // Time to actually send the message
text.send(number, message, region, function(err) { text.send(number, message, carrier, region, function(err) {
if (err) { if (err) {
mpq.track('sendText failed', tracking_details); mpq.track('sendText failed', tracking_details);
res.send(_.extend(response_obj, res.send(_.extend(response_obj,