Service for Sails framework with SMS features.
- Twilio (Docs)
Install this module.
npm install sails-service-sms
Then require it in your service and create sms instance.
// api/services/SmsService.js
import SmsService from 'sails-service-sms';
export default SmsService('twilio', {
sender: '<TWILIO_NUMBER>',
provider: {
accountSid: '',
authToken: ''
}
});
// api/controllers/SMSController.js
export default {
send: function(req, res) {
SmsService
.send({
recipient: ['ANOTHER', 'NUMBERS'],
message: 'You can override message'
})
.then(res.ok)
.catch(res.negotiate);
}
};
When you instantiate new instance via SmsService(type, config)
you can provide configuration object with next keys:
config.provider
- {Object} Options that will go to each of SDKsconfig.sender
- {String} Number of senderconfig.recipient
- {Array} Array of strings with phone numbers of recipientsconfig.message
- {String} Default message to send (you can override it insend()
)
Each of SMS instances has only one method:
Sends SMS and returns Promise.
config
- Configuration object for sending SMS:
config.sender
- {String} Sender's numberconfig.recipient
- {Array} Phone numbers to which need to send (mixed up with pre-defined recipients).config.message
- {String} Message body text
let twilio = SMSService('twilio', {
sender: '+123456789',
recipient: [],
message: 'Hey, there!',
provider: {
accountSid: '<ACCOUNT_SID>',
authToken: '<AUTH_TOKEN>'
}
});
twilio
.send({
recipient: ['+0987654321'],
message: 'You can override here predefined config'
})
.then(console.log.bind(console))
.catch(console.error.bind(console));
The MIT License (MIT)
Copyright (c) 2015 Eugene Obrezkov
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.