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

Defination of payload #155

Open
SurajBhari opened this issue Jul 2, 2023 · 1 comment
Open

Defination of payload #155

SurajBhari opened this issue Jul 2, 2023 · 1 comment

Comments

@SurajBhari
Copy link

SurajBhari commented Jul 2, 2023

I am new to this webdev thing.
I was making a small project that requires me to send notification(s).
I have managed to get through everything and get it to send notification.

Readme says "data" can be anything serial. even serialized JSON
but when I send a message like this it arrives as it is

Is there any documents where you find the payload keys names?

image

my code is simple.

def send_web_push(subscription_information, message_body):
    return webpush(
        subscription_info=subscription_information,
        data=message_body,
        vapid_private_key=VAPID_PRIVATE_KEY,
        vapid_claims=VAPID_CLAIMS
    )

notification_payload = {
            "title": "New Video",
            "body": "New Video from xyz",
}
data = json.dumps(notification_payload)
send_web_push(sub, data)
@jrconlin
Copy link
Member

jrconlin commented Jul 3, 2023

So... "Payload" (or data) is kinda undefined for a few reasons. Really, it's up to the recipient system to make sense out of it.

In your case, if you're sending JSON, you're getting JSON back out. (JSON is a fairly human readable format. You could do all sorts of things like, set the values of the Notification popup (to be fair, you probably should do that inside of the Service Worker, and just save the message for the content, possibly the title.

There are a bunch of good practices for webpush notifications, as well. Hope that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants