I need to send push notifications to multiple devices using aws-sns-javascript
when I create createPlatformEndpoint I can just add one device token but I need to send notifications to multiple devices like an array token
Create Platform Application
var params = {
Attributes: {
'PlatformCredential': 'My API KEY'
},
Name: 'dist-ba-dist',
Platform: 'GCM'
};
sns.createPlatformApplication(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
Create Platform Endpoint
var params = {
PlatformApplicationArn:`data.PlatformApplicationArn` ,
Token: 'My Device Token',
CustomUserData: 'STRING_VALUE'
};
sns.createPlatformEndpoint(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
Sends a message to an Amazon SNS topic
var payload = {
default: 'Hello World',
GCM: {
notification: {
body: "Sample message",
title: "Hello World"
}
}
};
console.log("endpointArn", data.EndpointArn)
payload.GCM = JSON.stringify(payload.GCM);
payload = JSON.stringify(payload);
console.log('payload', payload)
console.log('sending push');
sns.publish({
Message: payload,
MessageStructure: 'json',
TargetArn: data.EndpointArn,
}, function (err, data) {
if (err) {
console.log(err.stack);
return;
}
console.log('push sent');
console.log(data);
});
To deliver push notifications to multiple devices you can either