laravel-notification-channels / fcm

Firebase Cloud Messaging (FCM) notifications channel for Laravel
https://laravel-notification-channels.com/
MIT License
491 stars 126 forks source link

Cannot send push notification to topic using on-demand #86

Closed limsocheat closed 2 years ago

limsocheat commented 3 years ago

I tried to send push notification to a topic using on-demand as below:

on-demand:

public function created(Promotion $promotion)
    {
        Notification::route(FcmChannel::class, null)
            ->notify(new PromotionCreatedNotification($promotion));
    }

notification:

public function toFcm($notifiable)
    {

        return FcmMessage::create()
            ->setTopic('promotion')
            ->setData([
                'type'  => 'promotion',
                'uuid'  => $this->promotion->uuid,
            ])
            ->setNotification(\NotificationChannels\Fcm\Resources\Notification::create()
                ->setTitle('New Promotion')
                ->setBody($this->promotion->title)
                ->setImage($this->promotion->image_url))
            ->setAndroid(
                AndroidConfig::create()
                    ->setFcmOptions(AndroidFcmOptions::create()->setAnalyticsLabel('analytics'))
                    ->setNotification(AndroidNotification::create()->setColor('#0A0A0A'))
            )->setApns(
                ApnsConfig::create()
                    ->setFcmOptions(ApnsFcmOptions::create()->setAnalyticsLabel('analytics_ios'))
            );
    }
martinjoiner commented 3 years ago

@limsocheat This is a long-shot and there is only a slim chance this might be the cause but is your uuid an integer? If so, that might be the reason your code is not working. Try casting this to a string and let me know if that helps. I ask because I am currently discussing this exact problem in another issue on this repo.

limsocheat commented 3 years ago

@limsocheat This is a long-shot and there is only a slim chance this might be the cause but is your uuid an integer? If so, that might be the reason your code is not working. Try casting this to a string and let me know if that helps. I ask because I am currently discussing this exact problem in another issue on this repo.

Hi,

My UUID is a unique String, not an integer. I tried to send topic without data too, but didn't work.

dipesh008 commented 3 years ago

I am facing the same issue. Notification on Demand for topic not working.

dipesh008 commented 3 years ago

@limsocheat limsocheat were you able to solve?

fabiomlferreira commented 3 years ago

Did anyone find a solution to sent a notification to a topic?

vkyeswa commented 3 years ago

Did anyone find a solution to sent a notification to a topic?

checkout this PR https://github.com/laravel-notification-channels/fcm/pull/85#issue-607883789

atymic commented 2 years ago

@ankurk91 please make a PR to the repo :)