How to send Extra parameters in payload via Amazon SNS Push Notification

前端 未结 4 1938
走了就别回头了
走了就别回头了 2020-12-13 02:18

This is something new i am asking as i haven\'t got it any answers for it on SO.

I am using Amazon SNS Push for sending push to my registered devices, everything is

4条回答
  •  囚心锁ツ
    2020-12-13 02:52

    From a Lambda function (Node.js) the call should be:

    exports.handler = function(event, context) {
    
      var params = {
        'TargetArn' : $EndpointArn,
        'MessageStructure' : 'json',
        'Message' : JSON.stringify({
          'default' : $title,
          'APNS' : JSON.stringify({
            'aps' : { 
              'alert' : $title,
              'badge' : '0',
              'sound' : 'default'
            },
            'id' : '123',
            's' : 'section',
          }),
          'APNS_SANDBOX' : JSON.stringify({
            'aps' : { 
              'alert' : $title,
              'badge' : '0',
              'sound' : 'default'
            },
            'id' : '123',
            's' : 'section',
          })
        })
      };
    
      var sns = new AWS.SNS({apiVersion: '2010-03-31', region: 'us-east-1' });
      sns.publish(params, function(err, data) {
        if (err) {
          // Error
          context.fail(err);
        }
        else {
          // Success
          context.succeed();
        }
      });
    }

    You can simplify by specifying only one protocol: APNS or APNS_SANDBOX.

提交回复
热议问题