GithubHelp home page GithubHelp logo

laravel-fcm-notification-channel's Introduction

FCM notification channel for Laravel 5.3

This package makes it easy to send notifications using Firebase Cloud Messaging (FCM) with Laravel 5.3. This package is based on brozot/laravel-fcm, so please read that documentation for more information.

Contents

Installation

You can install this package via composer:

composer require enniel/laravel-fcm-notification-channel:1.*

Register the provider directly in your app configuration file config/app.php:

'providers' => [
    // ...

    NotificationChannels\FCM\ServiceProvider::class 
]

Usage

Now you can use the channel in your via() method inside the notification:

use NotificationChannels\FCM\FCMMessage;
use Illuminate\Notifications\Notification;

class ExampleNotification extends Notification
{
    public function via($notifiable)
    {
        return ['fcm'];
    }

    public function toFCM($notifiable)
    {
        return (new FCMMessage())
            ->notification([
                'title' => 'Notification title',
                'body' => 'Notification body',
            ]);
    }
}

Available message types:

  • FCMMessage: Send notifications to device(s).
  • FCMMessageTopic: Send notifications to topic(s).
  • FCMMessageGroup: Send notifications to group(s).

In order for your notice to know who to send messages, you must add routeNotificationForFCM method to your notification model.

Available message methods

  • data(): Notification data. array | LaravelFCM\Message\PayloadData | LaravelFCM\Message\PayloadDataBuilder
  • options(): Notification options. array | LaravelFCM\Message\Options | LaravelFCM\Message\OptionsBuilder
  • notification(): Notification content. array | LaravelFCM\Message\PayloadNotification | LaravelFCM\Message\PayloadNotificationBuilder

Proxy methods. See brozot/laravel-fcm for more information about this methods.

  • setDryRun
  • setPriority
  • setTimeToLive
  • setCollapseKey
  • setDelayWhileIdle
  • setMutableContent
  • setContentAvailable
  • setRestrictedPackageName
  • isDryRun
  • getPriority
  • getTimeToLive
  • getCollapseKey
  • isDelayWhileIdle
  • isMutableContent
  • isContentAvailable
  • getRestrictedPackageName
  • setTag
  • setBody
  • setIcon
  • setTitle
  • setSound
  • setBadge
  • setColor
  • setChannelId
  • setClickAction
  • setBodyLocationKey
  • setBodyLocationArgs
  • setTitleLocationKey
  • setTitleLocationArgs
  • getTag
  • getBody
  • getIcon
  • getTitle
  • getSound
  • getBadge
  • getColor
  • getChannelId
  • getClickAction
  • getBodyLocationKey
  • getBodyLocationArgs
  • getTitleLocationKey
  • getTitleLocationArgs

Testing

$ composer test

Credits

Support

Having trouble? Open an issue!

License

The MIT License (MIT). Please see License File for more information.

laravel-fcm-notification-channel's People

Contributors

enniel avatar tssujt avatar yuesh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

laravel-fcm-notification-channel's Issues

CouldNotSendNotification thrown even when notification was sent successfully

Hello,

"Notification was not sent. You should specify device token(s), topic(s) or group(s) for sending notification."

However, laravel-fcm.log logs
[2017-05-13 20:37:29] Laravel-FCM.INFO: notification send to 1 devices success: 1 failures: 0 number of modified token : 0 [] [] and the push notification was successfully delivered.

How can I catch DownstreamResponse?

Hello,
im trying get the downstreamresponse just in case some of the tokens need updating. I can't figure it out on how to get it, is there a way ?

CouldNotSendNotification thrown when empty array is returned

I have various notifications that get sent to users via a number of channels depending on how they registered. It can be APN, FCM or email. Not all notifications will be sent via all channels and when no FCM user can be found, routeNotificationForFCM returns an empty array.

The APN and Email channels handle this fine; if there are no recipients (empty array), the notification is not sent via these channels.

This FCM library, however, throws an exception when that occurs, while it is a perfectly viable flow.

For comparison, here is the APN channel source;

        $tokens = (array) $notifiable->routeNotificationFor('apn');
        if (! $tokens) {
            return;
        }

        $message = $notification->toApn($notifiable);
        if (! $message) {
            return;
        }

... [actual sending] ...

vs the FCM source

        $message = $notification->toFCM($notifiable);
        if ($message->recipientNotGiven()) {
            if (! $to = $notifiable->routeNotificationFor('FCM')) {
                throw CouldNotSendNotification::missingRecipient();
            }
            $message->to($to);
        }
... [actual sending] ...

Could this please be resolved to behave like the other notification channels out there?

Not able to install the package

I tried installing the package, but I got the following error

 - Installation request for enniel/laravel-fcm-notification-channel 1.*@dev -> satisfiable by enniel/laravel-fcm-notification-channel[1.0.x-dev].
- enniel/laravel-fcm-notification-channel 1.0.x-dev requires brozot/laravel-fcm dev-master -> satisfiable by brozot/laravel-fcm[dev-master] but these conflict with your requirements or minimum-stability.

How to send to topic ?

I have no problem sending message to single device with user token, but now i need to send notification to a topic what should i do?

This is my code

use NotificationChannels\FCM\FCMMessageTopic;

.....
  public function toFCM($notifiable)
    {
        return (new FCMMessageTopic())
            ->to($this->topic)
            ->notification([
                'title' => 'Notification title',
                'body' => 'Notification body',
            ]);
    }

and it return this error

FatalThrowableError in FirebaseNotification.php line 43:
Call to undefined method NotificationChannels\FCM\Exceptions\InvalidArgumentException::notification()

Not working with Laravel 5.8

When used with Laravel 5.8 an exception is thrown: Illuminate\Events\Dispatcher::fire()

From the upgrade docs:
The fire method (which was deprecated in Laravel 5.4) of the Illuminate/
Events/Dispatcher class has been removed
<laravel/framework#26392>. You should use the
dispatch method instead.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.