Created
January 4, 2017 12:13
-
-
Save avtaniket/9dcc1fe6c3ce24f2ca34c324dab505e6 to your computer and use it in GitHub Desktop.
AWS SNS send SMS to mobile number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var awsSdk = require('aws-sdk'); | |
| awsSdk.config.update({ | |
| accessKeyId: 'ACCESS_KEY_ID', | |
| secretAccessKey: 'SECRET_ACCESS_KEY' | |
| }); | |
| /** | |
| * [sendSMS - Send SMS to given number] | |
| * @param {object} params {message : string, number : number} | |
| * @param {Function} callback | |
| */ | |
| function sendSMS(params, callback) { | |
| var sns = new awsSdk.SNS({ | |
| region: 'us-east-1' | |
| }); | |
| var smsParams = { | |
| Message: params.message, | |
| MessageStructure: 'string', | |
| PhoneNumber: params.number | |
| }; | |
| sns.publish(smsParams, function(err, data) { | |
| if (err) { | |
| console.log(err); | |
| logger.error('sns sms', err); | |
| callback('Unable to send sms'); | |
| } else { | |
| callback(); | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment