Coder Social home page Coder Social logo

laravel-fcm's Introduction

Laravel-FCM

Build Status Coverage Status Latest Stable Version Total Downloads License

Introduction

Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud Messaging (FCM).

It currently only supports HTTP protocol for :

  • sending a downstream message to one or multiple devices
  • managing groups and sending message to a group
  • sending topics messages

Note: The XMPP protocol is not currently supported.

Installation

To get the latest version of Laravel-FCM on your project, require it from "composer":

$ composer require brozot/laravel-fcm

Or you can add it directly in your composer.json file:

{
    "require": {
        "brozot/laravel-fcm": "1.3.*"
    }
}

Laravel

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

Laravel >= 5.5 provides package auto-discovery, thanks to rasmuscnielsen and luiztessadri who help to implement this feature in Laravel-FCM, the registration of the provider and the facades should not be necessary anymore.

'providers' => [
	// ...

	LaravelFCM\FCMServiceProvider::class,
]

Add the facade aliases in the same file:

'aliases' => [
	...
	'FCM'      => LaravelFCM\Facades\FCM::class,
	'FCMGroup' => LaravelFCM\Facades\FCMGroup::class, // Optional
]

Note: The FCMGroup facade is needed only if you want to manage groups messages in your application.

Publish the package config file using the following command:

$ php artisan vendor:publish --provider="LaravelFCM\FCMServiceProvider"

Lumen

Register the provider in your bootstrap app file boostrap/app.php

Add the following line in the "Register Service Providers" section at the bottom of the file.

$app->register(LaravelFCM\FCMServiceProvider::class);

For facades, add the following lines in the section "Create The Application" . FCMGroup facade is only necessary if you want to use groups message in your application.

class_alias(\LaravelFCM\Facades\FCM::class, 'FCM');
class_alias(\LaravelFCM\Facades\FCMGroup::class, 'FCMGroup');

Copy the config file fcm.php manually from the directory /vendor/brozot/laravel-fcm/config to the directory /config (you may need to create this directory).

Package Configuration

In your .env file, add the server key and the secret key for the Firebase Cloud Messaging:

FCM_SERVER_KEY=my_secret_server_key
FCM_SENDER_ID=my_secret_sender_id

To get these keys, you must create a new application on the firebase cloud messaging console.

After the creation of your application on Firebase, you can find keys in project settings -> cloud messaging.

Basic Usage

Two types of messages can be sent using Laravel-FCM:

  • Notification messages, sometimes thought of as "display messages"
  • Data messages, which are handled by the client app

More information is available in the official documentation.

Downstream Messages

A downstream message is a notification message, a data message, or both, that you send to a target device or to multiple target devices using its registration_Ids.

The following use statements are required for the examples below:

use LaravelFCM\Message\OptionsBuilder;
use LaravelFCM\Message\PayloadDataBuilder;
use LaravelFCM\Message\PayloadNotificationBuilder;
use FCM;

Sending a Downstream Message to a Device

$optionBuilder = new OptionsBuilder();
$optionBuilder->setTimeToLive(60*20);

$notificationBuilder = new PayloadNotificationBuilder('my title');
$notificationBuilder->setBody('Hello world')
				    ->setSound('default');

$dataBuilder = new PayloadDataBuilder();
$dataBuilder->addData(['a_data' => 'my_data']);

$option = $optionBuilder->build();
$notification = $notificationBuilder->build();
$data = $dataBuilder->build();

$token = "a_registration_from_your_database";

$downstreamResponse = FCM::sendTo($token, $option, $notification, $data);

$downstreamResponse->numberSuccess();
$downstreamResponse->numberFailure();
$downstreamResponse->numberModification();

// return Array - you must remove all this tokens in your database
$downstreamResponse->tokensToDelete();

// return Array (key : oldToken, value : new token - you must change the token in your database)
$downstreamResponse->tokensToModify();

// return Array - you should try to resend the message to the tokens in the array
$downstreamResponse->tokensToRetry();

// return Array (key:token, value:error) - in production you should remove from your database the tokens
$downstreamResponse->tokensWithError();

Sending a Downstream Message to Multiple Devices

$optionBuilder = new OptionsBuilder();
$optionBuilder->setTimeToLive(60*20);

$notificationBuilder = new PayloadNotificationBuilder('my title');
$notificationBuilder->setBody('Hello world')
				    ->setSound('default');

$dataBuilder = new PayloadDataBuilder();
$dataBuilder->addData(['a_data' => 'my_data']);

$option = $optionBuilder->build();
$notification = $notificationBuilder->build();
$data = $dataBuilder->build();

// You must change it to get your tokens
$tokens = MYDATABASE::pluck('fcm_token')->toArray();

$downstreamResponse = FCM::sendTo($tokens, $option, $notification, $data);

$downstreamResponse->numberSuccess();
$downstreamResponse->numberFailure();
$downstreamResponse->numberModification();

// return Array - you must remove all this tokens in your database
$downstreamResponse->tokensToDelete();

// return Array (key : oldToken, value : new token - you must change the token in your database)
$downstreamResponse->tokensToModify();

// return Array - you should try to resend the message to the tokens in the array
$downstreamResponse->tokensToRetry();

// return Array (key:token, value:error) - in production you should remove from your database the tokens present in this array
$downstreamResponse->tokensWithError();

Kindly refer Downstream message error response codes documentation for more information.

Topics Messages

A topics message is a notification message, data message, or both, that you send to all the devices registered to this topic.

Note: Topic names must be managed by your app and known by your server. The Laravel-FCM package or fcm doesn't provide an easy way to do that.

The following use statement is required for the examples below:

use LaravelFCM\Message\Topics;

Sending a Message to a Topic

$notificationBuilder = new PayloadNotificationBuilder('my title');
$notificationBuilder->setBody('Hello world')
				    ->setSound('default');

$notification = $notificationBuilder->build();

$topic = new Topics();
$topic->topic('news');

$topicResponse = FCM::sendToTopic($topic, null, $notification, null);

$topicResponse->isSuccess();
$topicResponse->shouldRetry();
$topicResponse->error();

Sending a Message to Multiple Topics

It sends notification to devices registered at the following topics:

  • news and economic
  • news and cultural

Note : Conditions for topics support two operators per expression

$notificationBuilder = new PayloadNotificationBuilder('my title');
$notificationBuilder->setBody('Hello world')
				    ->setSound('default');

$notification = $notificationBuilder->build();

$topic = new Topics();
$topic->topic('news')->andTopic(function($condition) {

	$condition->topic('economic')->orTopic('cultural');

});

$topicResponse = FCM::sendToTopic($topic, null, $notification, null);

$topicResponse->isSuccess();
$topicResponse->shouldRetry();
$topicResponse->error());

Group Messages

Sending a Notification to a Group

$notificationKey = ['a_notification_key'];


$notificationBuilder = new PayloadNotificationBuilder('my title');
$notificationBuilder->setBody('Hello world')
                        ->setSound('default');

$notification = $notificationBuilder->build();


$groupResponse = FCM::sendToGroup($notificationKey, null, $notification, null);

$groupResponse->numberSuccess();
$groupResponse->numberFailure();
$groupResponse->tokensFailed();

Creating a Group

$tokens = ['a_registration_id_at_add_to_group'];
$groupName = "a_group";
$notificationKey

// Save notification key in your database you must use it to send messages or for managing this group
$notification_key = FCMGroup::createGroup($groupName, $tokens);

Adding Devices to a Group

$tokens = ['a_registration_id_at_add_to_the_new_group'];
$groupName = "a_group";
$notificationKey = "notification_key_received_when_group_was_created";

$key = FCMGroup::addToGroup($groupName, $notificationKey, $tokens);

Deleting Devices from a Group

Note if all devices are removed from the group, the group is automatically removed in "fcm".

$tokens = ['a_registration_id_at_remove_from_the_group'];
$groupName = "a_group";
$notificationKey = "notification_key_received_when_group_was_created";

$key = FCMGroup::removeFromGroup($groupName, $notificationKey, $tokens);

Options

Laravel-FCM supports options based on the options of Firebase Cloud Messaging. These options can help you to define the specificity of your notification.

You can construct an option as follows:

$optionsBuilder = new OptionsBuilder();

$optionsBuilder->setTimeToLive(42*60)
                ->setCollapseKey('a_collapse_key');

$options = $optionsBuilder->build();

Notification Messages

Notification payload is used to send a notification, the behaviour is defined by the App State and the OS of the receptor device.

Notification messages are delivered to the notification tray when the app is in the background. For apps in the foreground, messages are handled by these callbacks:

  • didReceiveRemoteNotification: on iOS
  • onMessageReceived() on Android. The notification key in the data bundle contains the notification.

See the official documentation.

$notificationBuilder = new PayloadNotificationBuilder();
$notificationBuilder->setTitle('title')
            		->setBody('body')
            		->setSound('sound')
            		->setBadge('badge');

$notification = $notificationBuilder->build();

Data Messages

Set the data key with your custom key-value pairs to send a data payload to the client app. Data messages can have a 4KB maximum payload.

  • iOS, FCM stores the message and delivers it only when the app is in the foreground and has established a FCM connection.
  • Android, a client app receives a data message in onMessageReceived() and can handle the key-value pairs accordingly.

See the official documentation.

$dataBuilder = new PayloadDataBuilder();
$dataBuilder->addData([
	'data_1' => 'first_data'
]);

$data = $dataBuilder->build();

Notification & Data Messages

App behavior when receiving messages that include both notification and data payloads depends on whether the app is in the background or the foreground—essentially, whether or not it is active at the time of receipt (source).

  • Background, apps receive notification payload in the notification tray, and only handle the data payload when the user taps on the notification.
  • Foreground, your app receives a message object with both payloads available.

Topics

For topics message, Laravel-FCM offers an easy to use api which abstract firebase conditions. To make the condition given for example in the firebase official documentation it must be done with Laravel-FCM like below:

Official documentation condition

'TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics)
$topics = new Topics();

$topics->topic('TopicA')
       ->andTopic(function($condition) {
	       $condition->topic('TopicB')->orTopic('TopicC');
       });

Testing

For integration testing, you can mock the responses with mockery and Mocks provided by the package.

There are 3 kinds of "MockResponse" given by the package:

  • MockDownstreamResponse
  • MockGroupResponse
  • MockTopicResponse

You can mock the FCM call as in the following example:

$numberSucess = 2;
$mockResponse = new \LaravelFCM\Mocks\MockDownstreamResponse(numberSucess);

$mockResponse->addTokenToDelete('token_to_delete');
$mockResponse->addTokenToModify('token_to_modify', 'token_modified');
$mockResponse->setMissingToken(true);

$sender = Mockery::mock(\LaravelFCM\Sender\FCMSender::class);
$sender->shouldReceive('sendTo')->once()->andReturn($mockResponse);

$this->app->singleton('fcm.sender', function($app) use($sender) {
	return $sender;
});

API Documentation

You can find more documentation about the API in the API reference.

Licence

This library is open-sourced software licensed under the MIT license.

Some of this documentation is coming from the official documentation. You can find it completely on the Firebase Cloud Messaging Website.

laravel-fcm's People

Contributors

alvsconcelos avatar anich avatar appkr avatar arubacao avatar brozot avatar chimit avatar codehimanshu avatar darius-sv avatar enniel avatar fawzanm avatar gaffel avatar gcphost avatar hsharghi avatar jacovdbosch avatar luiztessadri avatar marfurt avatar rasmuscnielsen avatar slpixe avatar vigneshgurusamy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-fcm's Issues

Incompatibility with Service Worker

HI, been using your library to send notifications to apps for a while, now Im implementing a js client with a service worker.

As referenced in this issue from firebaseJs firebase/quickstart-js#71

When sending in a notification the field notification this takes over and the custom handler does not trigger

Theres a way to call the notification field sent to firebase something else, or even skip it?

Cant get it to work

Hello i am using your plugin but it does not send a push notificiation for me, is there something wrong with these lines of code?

$notificationBuilder = new PayloadNotificationBuilder('my title');
$notificationBuilder->setBody('body')
->setSound('default');

$notification = $notificationBuilder->build();

$optionBuilder = new OptionsBuilder();

$deviceResponse = FCM::sendTo($userKey, $optionBuilder->build(), $notification);

Having issue with ios.

Working fine on android. Ios is receiving push through firebase console but not through laravel.
Please somebody help.

When does tokensToModify get populated?

I've been implementing your package to send FCM notifications, which is working fine. Currently I'm implementing a case for tokensToModify.

By reinstalling my client-app, I am able to generate or refresh tokens. At this moment though the old token is still in my database.

So when sending to the old token, ( after refreshing tokens from the client ), I expect to see the old token as key with the new token as value in the tokensToModify() array. This never happens though. The old tokens will always be inserted in to the tokensToDelete array.

I might have misunderstood the tokensToModify method. But i would like some explanation on how to use this method on the server side.

How can I make phone vibrate when push is send

Push notification working fine but the phone which receives push notification does not vibrate. Vibration is on and I can see vibration with other apps. Is there any way we can send vibration command through this package.

Does not install in Laravel 4

I tried to install Laravel-FCM but was unable to do so.

Here is what I did:

  1. I included "brozot/laravel-fcm": "^0.9.3" in the require array of composer.json but it refuses to install. It returns an error message which tells me that I need to update my guzzle to ~6.0.

cms

  1. I tried replacing my current guzzle to ~6.0 which in turn tells me that I need to update my laravel framework.

Is there a way or a work around to make it work in laravel 4.2.

Missing Namespace for Topics in documentation (minor)

Hey @brozot Great library, got some great use from it.

I just noticed that the namespace for Topics wasn't included in the documentation. Shouldn't be difficult to add use LaravelFCM\Message\Topics; to the "Topics Messages" section of the documentation to make it immediately obvious to users. I can open a PR if you'd like.

Thanks again 👍

Is it possible add the notification buttons

Hello,
first of all congratulations for the excellent work and thanks for share!
I would like ask you (as title says) if it is possible add buttons on notification, for example like "whatsapp" that show if you want reply to message or close notification.

thank you!!

Subscribe/Unsubscribe Topic for User ?

Hi,
how i can achieve subscribe and unsubscribe topic from user token with this library ?
I saw others php library fcm can do it like e.x https://github.com/sngrl/php-firebase-cloud-messaging

#Subscribe user to the topic

use sngrl\PhpFirebaseCloudMessaging\Client;

$server_key = '_YOUR_SERVER_KEY_';
$client = new Client();
$client->setApiKey($server_key);
$client->injectGuzzleHttpClient(new \GuzzleHttp\Client());

$response = $client->addTopicSubscription('_SOME_TOPIC_ID_', ['_FIRST_TOKEN_', '_SECOND_TOKEN_']);
var_dump($response->getStatusCode());
var_dump($response->getBody()->getContents());

#Remove user subscription to the topic

use sngrl\PhpFirebaseCloudMessaging\Client;

$server_key = '_YOUR_SERVER_KEY_';
$client = new Client();
$client->setApiKey($server_key);
$client->injectGuzzleHttpClient(new \GuzzleHttp\Client());

$response = $client->removeTopicSubscription('_SOME_TOPIC_ID_', ['_FIRST_TOKEN_', '_SECOND_TOKEN_']);
var_dump($response->getStatusCode());
var_dump($response->getBody()->getContents());

Undefined Property $Failure in FCMGROUP::GroupResponse

Hi,
I am receiving this kind of new error, after updating composer

Undefined Property $Failure in FCMGROUP::GroupResponse
Seems like you didnt define the Failure variable or you would have changed any naming convention in GroupResponse class.

kindly check & update it

Thanks

Consuming too much memory and CPU resources when sending push to large number of users

I am trying to send push notifications in bulk. Now I've 400 devices registered on my live server. When we are sending a push notification to all of them our memory and CPU usage rises drastically thus slowing down our system. When I check with the server logs 400-500 new processes are being generated when push notification is triggered. I am using the same code from package readme example i.e
`$tokens = array of push tokens;
$downstreamResponse = FCM::sendTo($tokens, $option, $notification, $additionalData);

if ($downstreamResponse->tokensToDelete()) {
Device::whereIn('device_push_token',$downstreamResponse->tokensToDelete())->delete();
}
`
Is there anything I am doing wrong? Or there are any limitations from FCM/this package? Or should I try any alternate method like groups, topics?

Ios and android notification not sending

LaravelFCM\Response\DownstreamResponse Object
(
[numberTokensSuccess:protected] => 0
[numberTokensFailure:protected] => 1
[numberTokenModify:protected] => 0
[messageId:protected] =>
[tokensToDelete:protected] => Array
(
[0] => dppE1iQTuec:APA91bHHrKccNItw9ZHevSaw6MfVrNbvv_XI1XRcqSS2-n-8EKpLt9AwTJCk97UyyYZrrkl8jHTGiprmpDSRCDHZfY5gzX80oWV5x0Qlpci4sYMJaio8Qy8jG298-As8ogBmQ_x0FxEE
)

[tokensToModify:protected] => Array
    (
    )

[tokensToRetry:protected] => Array
    (
    )

[tokensWithError:protected] => Array
    (
    )

[hasMissingToken:protected] => 
[tokens:LaravelFCM\Response\DownstreamResponse:private] => Array
    (
        [0] => dppE1iQTuec:APA91bHHrKccNItw9ZHevSaw6MfVrNbvv_XI1XRcqSS2-n-8EKpLt9AwTJCk97UyyYZrrkl8jHTGiprmpDSRCDHZfY5gzX80oWV5x0Qlpci4sYMJaio8Qy8jG298-As8ogBmQ_x0FxEE
    )

[logEnabled:protected] => 1

)

chunk tokens?

hello. thankyou for amazing package.
Do I need tokens are sent be chunk of 999 ?

Type error: Too few arguments to function Illuminate\\Support\\Manager::createDriver()

I installed the package in my laravel, and when I'm trying to send a push notification to my device using the exact same code in the readme, I get the following error:

Type error: Too few arguments to function Illuminate\\Support\\Manager::createDriver(), 0 passed in \/home\/pokemoti\/public_html\/api\/vendor\/laravel\/framework\/src\/Illuminate\/Support\/Manager.php on line 87 and exactly 1 expected

The line caused the error is:

$downstreamResponse = FCM::sendTo($token, $option, $notification, $data);

I couldn't figure out what's wrong as soon as it's the documentation code..

What's could have gone wrong?

log_enabled is set to default

setting log_enabled to false is more production oriented and therefore one is not so much required to publish the config file

Class fcm.sender does not exist

when i call:
$downstreamResponse = FCM::sendTo($this->tokens, $this->options, $this->notification,$this->data);

can someone help?

Missing argument 1

ErrorException in Manager.php line 77: Missing argument 1 for Illuminate\Support\Manager::createDriver(), called in /var/www/html/API-DIR/events/vendor/illuminate/support/Manager.php on line 87 and defined

When i try to send notification i service above mentioned error. i am using lumen framework.

Here is my code :

`$optionBuiler = new OptionsBuilder();
$optionBuiler->setTimeToLive(60*20);

    $notificationBuilder = new PayloadNotificationBuilder('My test notification');
    $notificationBuilder->setBody('Hello world')
                         ->setSound('default');


    $dataBuilder = new PayloadDataBuilder();
    $dataBuilder->addData(['a_data' => 'my_data']);

    $option = $optionBuiler->build();
    $notification = $notificationBuilder->build();
    $data = $dataBuilder->build();

    $token = "token";

   $downstreamResponse = FCM::sendTo($token, $option, $notification, $data);`

Thanks

fcm.php is not generated

When I install the package and run the command php artisan vendor:publish, fcm.php is expected to be found in config directory , but it's not found. any idea about why this issue happens ?

Ios not receiving notifications

Working fine with android, but doesn't work with ios. Tried set priority to high and content_available to true. No effect. In the same time, it works fine when I'm sending notification via firebase console or curl (both from php or linux console). Can you help me? Is it bug or I'm doing smth wrong? I tried the example from documentation (downstream Messages)

Undefined variable: response

what is the variable response passed to "new DownstreamResponse" under Downstream Messages example. I am getting an error with this.

Data & Icon not showing in the browser notification

I've followed the steps correctly but when I send browser push notification, neither shows data(title, body) correctly nor shows icon image. I'm not sure whether it is about this package or about FCM itself? Can someone help me in this?

TopicResponse issue

For multiple topics defined, in TopicResponse on line 102 there is array to string conversion error for $logMessage. The problem is in $topic, problem is solved using json encode on $topic. Can you check this?

How get my id´s token devices

Hello, i´m newer and hi have a question:
How can i get my tokens id´s phone ? ( $tokens = MYDATABASE::pluck('fcm_token')->toArray(); )
Thanks very much.

Trouble with additional parameters

Hello! First of all, thank you very much for great lib! Im using it on laravel 5.1)
In testing i have a same problem.

        $optionBuilder = new OptionsBuilder();
        $optionBuilder->setTimeToLive(30);

        $notificationBuilder = new PayloadNotificationBuilder('Auth');
        $notificationBuilder->setBody('Auth request...')
            ->setSound('default');

        $dataBuilder = new PayloadDataBuilder();
        $dataBuilder->addData(['a_data'=>[
            'mode'=>'auth',
            'private_key'=>'12345678901234567890123456789012'
        ]
]);

        $option = $optionBuilder->build();
        $notification = $notificationBuilder->build();
        $data = $dataBuilder->build();

        $token = '...';

        $downstreamResponse = FCM::sendTo($token, $option, $notification, $data);

and on Android i receive:

{a_data={“mode”:“auth”,“private_key”:“MXaFORX1dKZpXMCaiLl5uNo74yOqOTJW”}}

thats Ok! I can use a_data as json/object...

BUT on iOS i have a problem!

Push notification received: {
    “a_data” = “{\“mode\“:\“auth\“,\“private_key\“:\“TpbgLUn1Zq6WwREJxy3yGvgjEeaun75z\“}”;
    aps =     {
        alert =         {
            body = “Auth request...“;
            title = Auth;
        };
        sound = default;
    };
    “gcm.message_id” = “0:1496937050152314%939d13c6939d13c6";
}

a_data variable have string type, i can not use it.

Can you explain, how can i use sub-array in $dataBuilder->addData for iOS json/object type?

crashing after fresh install

Hi,

I had followed the step by step explanation, but I'm getting an error when trying to send a message.

ErrorException in Manager.php line 77:
Missing argument 1 for Illuminate\Support\Manager::createDriver(), called in D:\vendor\laravel\framework\src\Illuminate\Support\Manager.php on line 88 and defined
in Manager.php line 77
at HandleExceptions->handleError(2, 'Missing argument 1 for Illuminate\\Support\\Manager::createDriver(), called in D:\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\Manager.php on line 88 and defined', 'D:\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\Manager.php', 77, array('this' => object(FCMManager))) in Manager.php line 77
at Manager->createDriver() in Manager.php line 88
at Manager->createDriver(null) in Manager.php line 63
at Manager->driver() in FCMServiceProvider.php line 27
at FCMServiceProvider->LaravelFCM\{closure}(object(Application), array()) in Container.php line 716
at Container->build(object(Closure)) in Container.php line 598
at Container->resolve('fcm.client') in Container.php line 567
at Container->make('fcm.client') in Application.php line 708
at Application->make('fcm.client') in Container.php line 1139
at Container->offsetGet('fcm.client') in FCMServiceProvider.php line 38
at FCMServiceProvider->LaravelFCM\{closure}(object(Application), array()) in Container.php line 716
at Container->build(object(Closure)) in Container.php line 598
at Container->resolve('fcm.sender') in Container.php line 567
at Container->make('fcm.sender') in Application.php line 708
at Application->make('fcm.sender') in Container.php line 1139
at Container->offsetGet('fcm.sender') in Facade.php line 159
at Facade::resolveFacadeInstance('fcm.sender') in Facade.php line 128
at Facade::getFacadeRoot() in Facade.php line 215
at Facade::__callStatic('sendTo', array(array('dFQwbIxI3J0:APA91bFzXpm4atxUHhtAYvZLfZsx78kCI711'), object(Options), object(PayloadNotification), object(PayloadData))) in ApiController.php line 190
at FCM::sendTo(array('dFQwbIxI3J0:Ch6HGrkAqe6p0ra969kjBa_HzdqAsgfi67EMbLI711'), object(Options), object(PayloadNotification), object(PayloadData)) in ApiController.php line 190
at ApiController::sendMessageToToken(object(Collection), 'Testing') in ApiController.php line 166
at ApiController->alertTeacherForDelay('15')
at call_user_func_array(array(object(ApiController), 'alertTeacherForDelay'), array('min' => '15')) in Controller.php line 55
at Controller->callAction('alertTeacherForDelay', array('min' => '15')) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(ApiController), 'alertTeacherForDelay') in Route.php line 204
at Route->runController() in Route.php line 160

Any idea what I'm doing wrong? Or is this a real bug?

PS: I already cleaned the cache in all the possible ways that I found in the internet and still no luck.

Thanks,
Joao

DownstreamResponse messageId property is not set and not logged.

In \LaravelFCM\Response\DownstreamResponse::parse() the messageId is not set, seems unfinished.
Right now it looks like this:

if (array_key_exists(self::MULTICAST_ID, $responseInJson)) {
    $this->messageId;
}

Also a getter is missing for messageId property and it is not logged at all in the logResponse method.
The messageId is really important for debugging, only reliable way to cross reference firebase statistics and logs with server logs.

On another note:
Logging is probably not ideally solved here by just instantiating a new StreamHandler. It's hardcoded and cannot be configured/adjusted. You should probably use Laravel's Log service.
Maybe something along the lines of:

Log::useDailyFiles(storage_path() . '/logs/laravel-fcm.log');
Log::info($logMessage);

How set action on Closed App

Hello,
I would like to ask if I can set equivalent of .addAction() and .setStyle() of notification or how use app notification builder on closed app.
Because my problem is that when my app is closed does not execute code in onMessageReceived and I can't notification.setStyle or .addAction().

thank you for share!

Mutliple Android Applications

How am I to integrate it for two different Android Applications using the same Laravel Application.

Both Andoid Application would have different Sender IDs.

Use multiple sender id for multiple apps using brozot

I have multiple mobile apps (for each app I manage different server key and sender id) and I am using same laravel backend to send notifications to all different mobile apps.
How can I send notification to different app using different sender id (not using single sender id) with laravel brozot package?

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.