node-sms-sdk
Sdk for working with multiple sms gateway.
Install
npm i --save node-sms-sdk
or
yarn add node-sms-sdk
then you use in your project
const nodeSmsSdk =
Api
/** * @param sdk : The name of the sdk. This could be anything, except * when using an internally shipped sdk like 'twilio' or 'infobip'. * You can override any of the internally shipped ones with yours by calling this * method and passing an adapter * @param config : (object) the configuration needed by this sdk * @param adapter : (module) the sdk's adapter. This is used when using an external sdk **/ nodeSmsSdk : void /** * @param sdk : the name of the sdk * * @return : returns the config for that sdk, if not available, it * returns all available config **/ nodeSmsSdk : Object /** * @param sdk : the name of the sdk that you want to set as the * default **/ nodeSmsSdk : void /** * @param sdk : the name of the sdk that you want to get * @return : returns the instance of the raw sdk. **/ nodeSmsSdk : sdk /** * @param data : (object) * data = { * from: 'sender', * to: 'recipient', //this could be an array * body: 'message to be sent' * } * @return : Promise **/ nodeSmsSdk : Promise<any>
Build your own adapter
Building your own adapter is pretty easy and straight forward. Simply write a module that has the following exports. What to do when you're done??
- Publish to npm and have others used it.
- Fork this repo
- Add your sdk to the list of available sdk below, add link to your repo so others can find, send a PR
moduleexports = /** * This takes a config object that it can use to initialize * module **/ { } /** * Returns a tbe current instance of the adapter. * Gives you access to the raw module by the provider * * @return adapter **/ { } /** * This method should send a message and return a promise * * @param from: number or name sending the message * @parm to: the number(s) you're sending the message to. * This could also be an array * @parm body: The message to be sent **/ { }
SDKs available
- twilio (internal)
- infobip (internal)
- ADD_YOURS_HERE (send PR)
Example usage
//require module const nodeSmsSdk = //add config for an sdk. twilio ships internally nodeSmsSdk //use twilio as default nodeSmsSdk //send message nodeSmsSdk