-
-
Save gomezalcuadrado/cae8a201ac3114a05d106ee35bc21910 to your computer and use it in GitHub Desktop.
Ejemplo envio SNS
This file contains hidden or 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
| var AWS = require('aws-sdk'); | |
| //Esto no aplica | |
| AWS.config.update({ | |
| accessKeyId: '{AWS_KEY}', | |
| secretAccessKey: '{AWS_SECRET}', | |
| region: '{SNS_REGION}' | |
| }); | |
| var sns = new AWS.SNS(); | |
| //Registrar el nuevo dispositivo y obtener un id que lo representa | |
| sns.createPlatformEndpoint({ | |
| PlatformApplicationArn: '{APPLICATION_ARN}', | |
| Token: '{DEVICE_TOKEN}' | |
| }, function(err, data) { | |
| if (err) { | |
| console.log(err.stack); | |
| return; | |
| } | |
| //Envio de notificaciones (Se arma el mensaje: ejemplo de apple) | |
| var endpointArn = data.EndpointArn; | |
| var payload = { | |
| default: 'Hello World', | |
| APNS: { | |
| aps: { | |
| alert: 'Hello World', | |
| sound: 'default', | |
| badge: 1 | |
| } | |
| } | |
| }; | |
| // first have to stringify the inner APNS object... | |
| payload.APNS = JSON.stringify(payload.APNS); | |
| // then have to stringify the entire message payload | |
| payload = JSON.stringify(payload); | |
| //Se envía finalmente | |
| console.log('sending push'); | |
| sns.publish({ | |
| Message: payload, | |
| MessageStructure: 'json', | |
| TargetArn: endpointArn | |
| }, function(err, data) { | |
| if (err) { | |
| console.log(err.stack); | |
| return; | |
| } | |
| console.log('push sent'); | |
| console.log(data); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment