signalpoint / push_notifications

The Push Notifications module for DrupalGap.
0 stars 10 forks source link

Working with Custom Payloads with Message Stacking #25

Open mkinnan opened 7 years ago

mkinnan commented 7 years ago

On my Drupal site, I have the following in push_notifications_gcm_send_message (push_notifications.module) for building the payload:

// Fill the default values required for each payload.
$data['registration_ids'] = $bundle_tokens;
$data['collapse_key'] = (string) time();
$data['data']['message'] = $payload['alert'];
$data['data']['title'] = $payload['title'];
$data['data']['tag'] = 123;

if(isset($data['data']['thepath'])){
  $data['data']['thepath'] = $payload['thepath'];
}

I get a push notification to my phone with sound. I then use the following in __my_module.js__ in my app:

function my_module_push_notifications_receive(data) {
  alert( JSON.stringify(data) );
  drupalgap_goto(data.additionalData.thepath); 
}

and it correctly shows me the alert box and directs me to the page in the app. Typically the path is node/123 but may be other non-node pages which is why I send a path and not just a node ID.

I'm trying to implement stacking of messages so they don't overwrite each other if a user is notified of both a new event and a new discussion. I've been following the two links:

https://developers.google.com/cloud-messaging/http-server-ref https://developers.google.com/cloud-messaging/concept-options

So I try to modify things in push_notifications_gcm_send_message to:

// Fill the default values required for each payload.
$data['registration_ids'] = $bundle_tokens;
$data['collapse_key'] = (string) time();

$data['notification']['title'] = $payload['title'];
$data['notification']['body'] = $payload['alert'];
$data['notification']['sound'] = 'default';
$data['notification']['tag'] = 123456;

if(isset($data['data']['thepath'])){
  $data['data']['thepath'] = $payload['thepath'];
}

I get a notification with sound and get stacking when changing the tag parameter when sending multiple notifications ... BUT my_module_push_notifications_receive is not being triggered anymore.

What am I doing wrong?

mkinnan commented 7 years ago

It appears I got it figured out on Android thanks to: https://github.com/phonegap/phonegap-plugin-push/issues/1118

I'm using Adobe PhoneGap Build to compile my app with cli-6.3.0 (4.2.0 / 5.2.1 / 4.4.1)

I'm also using this push plugin: https://www.npmjs.com/package/phonegap-plugin-push

In the data payload, add notId for the notification ID ... I'm using the node ID so that when two different nodes get created, the first notification doesn't get erased. So, your JSON code going to GCM server would look something like this:

{
   "collapse_key":"testing",
   "data":{
      "title":"My Fun Title!",
      "message":"A new event has been added to your group.",
      "notId":"1234",
      "thepath":"node/1234"
   },
   "to":"the_token_for_your_test_device"
}

I'm using a modified version of the Drupal.org __push_notifications module in combination with rules__ to create my payload for sending because I use organic groups.