notifme / notifme-sdk

A Node.js library to send all kinds of transactional notifications.

Home Page:https://notifme.github.io/www/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SMS/Voice from number should be dynamic

armiiller opened this issue · comments

The SMS/Voice from number should be a a string|function.

Why? When using a strategy (such as fallback) the from number will likely be tied to a provider. For example you might have one number for Twilio and another number for Plivo. Additionally this configuration should not be moved to the provider since it would be naive to assume that you only have 1 number you can send from in any Provider (aka you could have multiple numbers in Twilio). Therefore because of these reasons the from phone number should either be a string or a function that returns the string.

Proposed example:

import NotifmeSdk from 'notifme-sdk'

const dynamicFromNumber = function(provider){
  switch(provider.type){
    case "twilio": return "555-555-5555";
    case "plivo": return "444-444-4444";
  }
}

const notifmeSdk = new NotifmeSdk({}) // empty config = all providers are set to console.log
notifmeSdk
  .send({sms: {from: dynamicFromNumber, to: '+15000000001', text: 'Hello, how are you?'}})
  .then(console.log)