I am implementing Webpush ruby pearls to send push notifications to users of my website.
Server Code:
Webpush.payload_send({
message: notification.message,
url: notification.url, # I can't figure out how to access this key
id: notification.id, # or this key from the service worker
endpoint: endpoint,
p256dh: p256dh_key,
vapid: vapid_keys,
ttl: 24 * 60 * 60,
auth: auth_key,
})
I have a working service configured on the client side to show the notification and make it available.
self.addEventListener("push", function (event) {
var title = (event.data && event.data.text()) || "New Message";
event.waitUntil(
self.registration.showNotification(title, {
body: "New push notification",
icon: "/images/logo@2x.png",
tag: "push-notification-tag",
data: {
url: event.data.url,
id: event.data.id
}
})
)
});
self.addEventListener('notificationclick', function(event) {
event.notification.close();
event.waitUntil(
clients.openWindow(event.data.url + "?notification_id=" + event.data.id)
);
})
Everything works fine, except that the user keys ( url
, id
) that I am viewing are not accessible from the working one.
Does anyone know how to pass user data through the gem of WebPush?
source
share