-
-
Save NguyenTungs/24af0baf5a00979e87770e83b39bbb32 to your computer and use it in GitHub Desktop.
Notify FCM for Android via AWS SNS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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