[英]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 " “ John Doe邀请您参加会议。下载会议材料http://alink.com ”
This message will be Transactional
此消息将是
Transactional
I have a Node.js running on an EC2. 我有一个在EC2上运行的Node.js。 I am a mobile app developer and new to AWS.
我是移动应用程序开发人员,并且是AWS的新手。
In my SNS console I created a Topic. 在我的SNS控制台中,我创建了一个主题。 This created an ARN:
arn:aws:sns:us-east-1:xxx1234xxxx:MyAppName
这创建了一个ARN:
arn:aws:sns:us-east-1:xxx1234xxxx:MyAppName
I have the following code in NodeJS: 我在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. 您可以使用订阅API通过短信向主题订阅电话号码。 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
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.