typpo / textbelt

Free API for outgoing SMS
https://textbelt.com/
MIT License
3.02k stars 509 forks source link

Question: How are you looking up the correct SMS gateway for a given number? #93

Open keepsense opened 7 years ago

keepsense commented 7 years ago

I'm sorry if this isn't the correct area to ask this. I was reviewing the code, and I see where carriers are listed by country, but I don't see the mechanism that you are using to figure out the correct carrier, and SMS gateway, for a given phone number. Do you mind sharing how you are doing that? Are you using a free service for that feature? Or, are you just sending a message to all carrier formats within that country group?

Thanks! -Ryan

arturtamborski commented 7 years ago

Hi, I am pretty sure that textbelt just sends a message to all emails from selected providers list.

This is the code responsible for sending messages using mutt.

region = region || 'us'; // 4

var providers_list;
if (carrier) { // 3
  providers_list = carriers[carrier];
} else {
  providers_list = providers[region];
}

var emails = providers_list.map(function(provider) { // 2
  return provider.replace('%s', phone);
}).join(',');
var args = ['-s', 'txt', '-e', 'set from=' + config.fromAddress,
  '-e', 'set use_from=yes', '-e', 'set envelope_from=yes', '-b', emails]; // 1
var child = spawn('mutt', args);
  1. Mutt gets an array of emails as an argument (in args).
  2. This arrray contains emails from providers_list,
  3. providers_list is filtered at top based on the carrier variable. if carrier is set then emails will come from carriers[carrier].
  4. If carrier is not set, then providers_list will contain emails from providers[region] where region will fall back to us as default if not set.

And yes, its a late answer but it might come in handy for others.