Minishlink / web-push-php-example

An example for sending Web Push notifications, using web-push-php
MIT License
252 stars 89 forks source link

image and link in message and title is not working #19

Closed way2enjoy2 closed 5 years ago

way2enjoy2 commented 5 years ago

i tried to add link and images to my notification but its not working. i have seen one thread and changed to json format but then also its showing raw html.

i tried several things to change the title but its not working and tried to add image like this its not working either.

it will be great if u add image, link and title option is example. here is my code

self.addEventListener('push', function (event) { if (!(self.Notification && self.Notification.permission === 'granted')) { return; }

const sendNotification = body => {
    // you could refresh a notification badge here with postMessage API
  const title = "test Request";
    const options = {
     icon: "/icon.png"
          };
    return self.registration.showNotification(title, options, {
        body,
    });
};

if (event.data) {

  const message = event.data.json();
    event.waitUntil(sendNotification(message));
}

});

in php i send like this

$webPush = new WebPush($auth);

$res = $webPush->sendNotification( $subscription2, "You have a new message!\n$chatlink ", true );

Minishlink commented 5 years ago

Please ask this on StackOverflow or other more appropriate forum