Skip to content

Instantly share code, notes, and snippets.

@luisloaiza
Forked from bachvtuan/send_sms.js
Created January 31, 2018 21:27
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save luisloaiza/a01e96606ab0b68a9a61538c280b003e to your computer and use it in GitHub Desktop.
Save luisloaiza/a01e96606ab0b68a9a61538c280b003e to your computer and use it in GitHub Desktop.
Send SMS Amazon SNS Nodejs
/*
AWS implementation of SMS messaging
A simple sample that can become a lib.
*/
// npm install aws-sdk -g
const AWS = require('aws-sdk');
AWS.config.update({
accessKeyId: process.env.AMAZON_ACCESS_KEY_ID,
secretAccessKey: process.env.AMAZON_SECRET_ACCESS_KEY,
region: 'us-west-2'
});
const sns = new AWS.SNS();
//exports.sendSMS =
function sendSMS(to_number, message, cb) {
sns.publish({
Message: message,
Subject: 'Admin',
PhoneNumber:to_number
}, cb);
}
// Example
sendSMS("+525....", "Sms text message", (err, result)=>{
console.log("RESULTS: ",err,result)
})
@mail2asik
Copy link

mail2asik commented Apr 19, 2020

Thanks for the above information.

In the recent version, subject not working as expected.
Just to mentioned here about update of publish request payload.

{
      PhoneNumber: mobile,
      Message: message,
      MessageAttributes: {
        'AWS.SNS.SMS.SenderID' : {
          DataType : 'String',
          StringValue: 'Subject here'
        }
      }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment