Search code examples
cordova-pluginsamazon-sns

AMAZON SNS SEND sns message via JavaScript SDK error


Trying to send SNS messages from JavaScript SDK. Messages that are being sent from amazon sns console are showing up nicely,

Below is the AMAZON SNS console JSON generator output, This is working fine for me.

({
"GCM": "{ \"data\": { \"message\": \"This is a test message\" } }"
})

But when SNS is sent through code, it is throwing a Message error; I am using the Cordova push notification plugin, which requires a message tag to be included.

1) How do I format the message for GCM (Android platform) and send it? 2) How do I include a message attribute?

   "  var params = {
       Message:JSON.stringify(j), 
       MessageAttributes: {
            message: {
             DataType: 'String',                             StringValue: '60'
           }
        }
  TargetArn: 'XXXXXXXXXXXXXXXXXXXXX
        };"

Solution

  • I had same problem in php.. I can try to translate it in Javascript :)

    var payload = {};
    payload.GCM = JSON.stringify({
      data: {
        message: "test",
        title: "my title
      }
    });
    
    var params = {
      Message: JSON.stringify(payload), 
      MessageStructure: "json",
      TargetArn: 'XXXXXXXXXXXXXXXXXXXXX'
    };
    

    I know this is a very strange flow but this is my php implementation and works