notifme / notifme-sdk

A Node.js library to send all kinds of transactional notifications.
https://notifme.github.io/www/
MIT License
1.94k stars 149 forks source link

SMS/Voice from number should be dynamic #60

Closed armiiller closed 5 years ago

armiiller commented 5 years ago

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)
BDav24 commented 5 years ago

We can now customize requests: https://github.com/notifme/notifme-sdk/releases/tag/v1.9.0