Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I send a payload? #5

Closed
jamauro opened this issue Sep 12, 2019 · 10 comments
Closed

How do I send a payload? #5

jamauro opened this issue Sep 12, 2019 · 10 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@jamauro
Copy link

jamauro commented Sep 12, 2019

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:

validateDocument(notification)

I'm assuming that's because neither payload or data are in the check here:

check(notification, {

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

@paulincai
Copy link
Contributor

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
Copy link
Contributor

@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
Copy link
Author

jamauro commented Sep 12, 2019

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

@paulincai paulincai added enhancement New feature or request help wanted Extra attention is needed labels Sep 18, 2019
@jamauro
Copy link
Author

jamauro commented Oct 1, 2019

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
Copy link

AleF1 commented Oct 16, 2019

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
Copy link

AleF1 commented Oct 18, 2019

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
Copy link
Contributor

@AleF1 coming this week

@paulincai paulincai self-assigned this Oct 20, 2019
@AleF1
Copy link

AleF1 commented Oct 21, 2019

@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
Copy link
Contributor

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
Copy link

wreiske commented Sep 20, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants