Minishlink / web-push-bundle

Bundle around the WebPush library
MIT License
45 stars 10 forks source link

Sending with payload not working #11

Closed Roman9961 closed 6 years ago

Roman9961 commented 6 years ago

I am unable to send notifications with payloads. Each time the payload is not empty, the request is sent and sendNotification method returns true (when I dumped response, status code was 201), but no notification is delivered.

$webPush = $this->get('minishlink_web_push');

        $notifications = [
            [
                'subscription' => Subscription::create([
                    'endpoint' => 'https://fcm.googleapis.com/fcm/send/chvo9gq76WU:APA91bHh661rEeUWR14F9VTyghQTu1qNAQOGFEH0rbwWSsKRjxR9NP2hzyoryMOYLNHBgGnEnCeOuPwXOtTd2uSd8Ks8lWeLyzzXvNWWBj-H1DzN5rQGgsij7lv-2sZWPu6kZJ9dlUZm', // Firefox 43+,
                    'publicKey' => 'publicKey', // base 64 encoded, should be 88 chars
                    'authToken' => 'authToken', // base 64 encoded, should be 24 chars
                ]),
                'payload' => 'hello !',
            ]
        ];

        foreach ($notifications as $notification) {
            $webPush->sendNotification(
                $notification['subscription'],
                $notification['payload']
            );
        }
        $webPush->flush();
Minishlink commented 6 years ago

If you get a 2xx and you don't have a notification, it's either because your credentials are wrong or your client JS code is wrong. Check those :)