Skip to content

Instantly share code, notes, and snippets.

@NguyenTungs
Forked from shinoda-ak/notify-awssns2fcm.js
Created December 22, 2017 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NguyenTungs/24af0baf5a00979e87770e83b39bbb32 to your computer and use it in GitHub Desktop.
Save NguyenTungs/24af0baf5a00979e87770e83b39bbb32 to your computer and use it in GitHub Desktop.
Notify FCM for Android via AWS SNS
// Notify Target ARN for Android device
'use strict';
const AWS = require('aws-sdk');
const sns = new AWS.SNS({
apiVersion: '2010-03-31',
region: 'MY_REGION'
});
if (process.argv.length < 3) {
console.log('Usage: node notify.js ENDPOINT_ARN');
process.exit();
}
const TARGET_ARN = process.argv[2];
const TITLE = 'Node.js on ' + process.platform;
const MSG = 'Hi Node.js ' + new Date();
const GCM_MSG_JSON = JSON.stringify({
notification: {
title: TITLE,
body: MSG,
icon: 'myicon'
}
});
const msg = {
default: MSG,
GCM: GCM_MSG_JSON
};
const params = {
Message: JSON.stringify(msg),
MessageStructure: 'json',
TargetArn: TARGET_ARN
};
sns.publish(params, (err, data) => {
if (err)
console.log(err, err.stack);
else
console.log(data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment