activitree / meteor-push

Meteor Push Notifications for Cordova and Web/PWA with Firebase (FCM).
MIT License
28 stars 19 forks source link

How do I send a payload? #5

Closed jamauro closed 5 years ago

jamauro commented 5 years ago

Thanks for the package @paulincai. I see in /example/app/startup/client/index.js there's the option to send a payload so that you can take action on that data. I'd like to route to a specific place in the app.

But when I try to use Push.send(notification) with a notification that looks like:

const notification = {
  title: title,
  body: body,
  badge: badge,
  userId: userId,
  notId: Math.round(new Date().getTime() / 1000),
  payload: { gotoView: 'view', path: 'path' }
}

I get a Match error: Unknown key in field payload. I've also tried replacing payload with data with the same result.

Looks like it's getting hung up here: https://github.com/activitree/meteor-push/blob/45d97977c37d70d561fcdc4cd78e3af3bc910e88/lib/server/push.js#L63

I'm assuming that's because neither payload or data are in the check here: https://github.com/activitree/meteor-push/blob/45d97977c37d70d561fcdc4cd78e3af3bc910e88/lib/server/push.js#L17

Am I missing something or Is there another way to go about this? :)

paulincai commented 5 years ago

Ok, so it is the same problem present in the the other opened ticket. Pfff...not sure I still have a valid Apple developer subscription. Do you think you could test this if I implement the missing parts?

paulincai commented 5 years ago

@jamauro I live under GMT+4 and if we could have a "professional date" :)) and a pseudo-online chat option, I could totally exploit your kindness ... just to coat it with some sugary begging wording :)))).

jamauro commented 5 years ago

Yeah I'm up for it. I'm GMT -5. :) So it might work best if you have time on Saturday or Sunday. Shoot me an email: jamauro [at] gmail.com

jamauro commented 5 years ago

hey @paulincai, are you still up for collaborating on this? I'm planning on pushing my app live soon and would love to get this in there.

AleF1 commented 5 years ago

I'm loving this package compared to raix:push, notifications work way better but... I really need payload in order to implement it fully in my app :( Any updates @paulincai?

AleF1 commented 5 years ago

I've been able to send data but I can't process it at the client. Browser console is not showing anything while in raix, I can console.log(notification) and the Route notification.data.url for example... Any ideas?

paulincai commented 5 years ago

@AleF1 coming this week

AleF1 commented 5 years ago

@AleF1 coming this week

I managed to send and route data, dunno if it is the optimal way though. The main issue is having the app in the background, therefore you must change notification for data in the androidnote. Check it out at: https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/PAYLOAD.md#notification-vs-data-payloads

My recommended format for your push payload when using this plugin (while it differs from Google's docs) works 100% of the time:

{ "data": { "title": "Test Notification", "body": "This offer expires at 11:30 or whatever", "notId": 10, "surveyID": "ewtawgreg-gragrag-rgarhthgbad" } }

paulincai commented 5 years ago

Fixed in V2. I am still writing the documentation and some hooks to make the package more workable for developers. There is a "global" data object where you can add anything you need same for all 3 types (Android, IOS, Web). However, if you send data to Android, you can only send String keys. For Android, we send the entire message within the 'data' key (as per the cordova-push-plugin documentation). For only Android, you will have to have all keys as strings. Then the API provides a data object separate for each vendor: adnroidData, iosData, webData. If you need to send only strings, to all, use the global object. All other cases, use the individual objects. Ok... coming in a day or 2

wreiske commented 3 years ago

For me imageUrl: '', needed to exist. I removed it thinking "I'm not sending an image." but it has to be there for this error to go away.