Send Json Payload to MPNS by AWS SNS

965 Views Asked by At

I want to send a json payload to Windows phone 7+ in push notification. I am using MPNS. I am using AWS SNS service for sending push notification. IF i am sending a String payload .Everything works for string payload. I got stuck with Json payload.

paylaod = {default: "None", MPNS:  "<?xml version=\"1.0\" encoding=\"utf-8\"?><wp:Notification xmlns=\"WPNotification\"><wp:Toast><wp:Text1>SNS Test Message</wp:Text1></wp:Toast></wp:Notification>"}

resp = SNS.publish( target_arn: "arn:aws:sns:usXXXb64", message: paylaod.to_json,  message_structure: 'json')
1

There are 1 best solutions below

1
vzsg On

I'm awfully unfamiliar with the Ruby language, but it seems to me that your call lacks message attributes, which are mandatory for JSON-based MPNS messages.

The two attributes are as follows:

For reference, the attributes are the following:

  1. Attribute name: AWS.SNS.MOBILE.MPNS.Type
    Type: string
    Possible values: token (for tile notifications), toast or raw

  2. Attribute name: AWS.SNS.MOBILE.MPNS.NotificationClass
    Type: string
    Possible values: realtime*, priority, regular (realtime worked for me with the Java SDK)

So your last line should look like this:

resp = SNS.publish(
    target_arn: "arn:aws:sns:usXXXb64",
    message: paylaod.to_json,
    message_structure: 'json',
    message_attributes: {
        "AWS.SNS.MOBILE.MPNS.Type" => {
            data_type: "String",
            string_value: "toast"
        },
        "AWS.SNS.MOBILE.MPNS.NotificationClass" => {
            data_type: "String",
            string_value: "realtime"
        }
    })

Note that the message_structure: 'json' line is equally important.