Search code examples
javascriptquickblox

Push Notification to android device with custom GCM parameters


I am using JavaScript SDK - v2.1.2 :

My Query : How to send push notification with custom gcm parameters in android device using JavaScript.

I am trying to send push notification to android devices with my JavaScript code but in our app we are using third party receiver called CleverTap for notification. Following are the mandatory parameters for CleverTap receiver: "wzrk_pn" "wzrk_sound" "nt" "nm" "wzrk_dl" which I need to send as custom parameters.

Following is my code for Push Notification :

var pushCustomParams = {
    message: 'Message received from Bob',
    wzrk_pn: 1,
    wzrk_sound: 1,
    nt: 'Revofit',
    nm: 'This msg is from application',
    wzrk_dl: ''
}
var params = {
    notification_type : 'push',
    push_type : 'gcm', // 'gcm' is for Android, 'apns' - for iOS.
    user : { ids: [14411551] }, // recipients.
    environment : 'development', // environment, can be 'production' as well.
    message :   QB.pushnotifications.base64Encode(JSON.stringify(pushCustomParams)), // See how to form iOS or Android spesific push notifications
};

 QB.pushnotifications.events.create(params, function(err, response) {
    if (err) {
        console.log(err);
    } else {
        // success
        console.log(response);
    }
  });

Logs generated after executing the above code is as follows:

 {
    "notification": {
        "registration_ids": ["dFCRdN7MJD0:APA91bFsaOdorqhvRyMuUGH-Ds8Z_EB6pQWHpQIYy5YVUefwYFwqK39E5BsLtJ2cHYDLv9mPXDQc4mAQRhJTdM2unUgy6-kmWSWMorp0ZSbBL1EdjFZLiorh4LQT3JR454dqEP1bL2_l"],
        "delay_while_idle": false,
        "data": {
             "message": "{\"message\":\"Message received from Bob\",\"wzrk_pn\":1,\"wzrk_sound\":1,\"nt\":\"Revofit\",\"nm\":\"This msg is from application\"}",
             "collapse_key": "event7637817"
    },
          "priority": "high",
         "time_to_live": 86400
     },
     "log": [{
        "device_token": null,
        "created_at": "2016-06-30T14:26:46Z",
        "delivered_at": "2016-06-30T14:26:47Z",
        "failed_at": null,
        "error_code": null,
       "error_description": null
     }]
    }

But when I tried to send push notification from admin panel with my customized channel setting of GCM Parameters it worked fine. Log generated for notification from admin panel :

 {
     "notification": {
        "registration_ids":     ["eShiPWpBngA:APA91bFzFeaB0LryAt9FmEJ9xl2KHWhZWlfzpYhng4KONN60yr3ySl2R58Eye-qSmhzQ56T2Fyuzr0Yg4y1VWMIm20LH74U7BWO_Az7MgogBD2IGvmWEKvJWWgVH6sD-3wP_gaIgJEAY"],
        "delay_while_idle": false,
         "data": {
            "message": "hii",
            "wzrk_pn": "1",
            "nm": "New message",
            "nt": "revofit",
            "collapse_key": "event7632938"
         },
        "priority": "high",
        "time_to_live": 86400
     },
    "log": [{
        "device_token": null,
        "created_at": "2016-06-30T08:17:25Z",
         "delivered_at": "2016-06-30T08:17:26Z",
        "failed_at": null,
        "error_code": null,
        "error_description": null
    }]
 }

I am unable to rectify my mistake Kindly Help me out with this.

Sorry for my bad English. I tried my best.


Solution

  • Since we weren't able to get the solution as required we changed the GCM receiver.