AWS: SNS sending SMS message to multiple phone numbers
From my mobile app, I'd like to send the following message to multiple phone numbers:
"John Doe invited you to a meeting. Download meeting material http://alink.com"
This message will be Transactional
I have a Node.js running on an EC2. I am a mobile app developer and new to AWS.
In my SNS console I created a Topic. This created an ARN: arn:aws:sns:us-east-1:xxx1234xxxx:MyAppName
I have the following code in NodeJS:
var AWS = require('aws-sdk');
var auth = require('../snsAuth');
AWS.config.update = auth
var sns = new AWS.SNS();
var params = {
Message: "John Doe invited you to a meeting. Download meeting material http://alink.com",
MessageStructure: 'string',
PhoneNumber: '1xxx1234',
Subject: 'MyApp'
};
sns.setSMSAttributes(
{
attributes: {
DefaultSMSType: "Transactional"
}
},
function (error) {
if (error) {
console.log(error);
}
}
);
sns.publish(params, function (err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
I don't know how to send multiple phone numbers as parameters. Based on the docs, it appears that I need to subscribe to a Topic first and then publish the topic. If those are the right steps, how do I do that in code?
You can use the subscribe API to subscribe a phone number to a topic by sms. But the user has to confirm their subscription to the topic before they will get any published events.
var params = {
Protocol: 'sms',
TopicArn: 'arn:aws:sns:us-east-1:xxx1234xxxx:MyAppName',
Endpoint: '1xxx1234'
};
sns.subscribe(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
链接地址: http://www.djcxy.com/p/32240.html