brozot / laravel-fcm Goto Github PK
View Code? Open in Web Editor NEWLaravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud Messaging (FCM).
License: MIT License
Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud Messaging (FCM).
License: MIT License
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?
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?
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
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)
in src/Sender/FCMGroup.php
Thanks for sharing this!
I wonder if its possible to set the priority of a message?
https://firebase.google.com/docs/cloud-messaging/concept-options#setting-the-priority-of-a-message
Thanks,
Hi,
Thanks for this amazing plugin.
Would like to know how do I push notifications to all users using my app?
setting log_enabled
to false
is more production oriented and therefore one is not so much required to publish the config file
Hi, how can we add an icon to notification ?!!
I tried to install Laravel-FCM but was unable to do so.
Here is what I did:
Is there a way or a work around to make it work in laravel 4.2.
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?
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
)
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?
In this example i see this part, but i don't know how to replace this line:
$token = "a_registration_from_your_database";
I don't know how to get the token, can you give explanation.
I would like to send the notification in background task. Need special settings?
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
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 👍
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.
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?
post
is not available in GuzzleHttp\ClientInterface
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.
$notificationBuilder = new PayloadNotificationBuilder();
$notificationBuilder->setTitle('title')
->setBody('body')
->setSound('sound');
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);
In sendTo (FCMSender) if "to" is an empty array, it return a null response and not an InvalidRequestException
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
followed the instructions strictly still the error exists while using FCM::sendTo
Hi , i have problem.
how to send data click_action from laravel to android ?
How am I to integrate it for two different Android Applications using the same Laravel Application.
Both Andoid Application would have different Sender IDs.
PayloadNotificationBuilder
doesn't have addData
method. So how to add custom key-value pairs into a push notification?
I would like to use FCM in Laravel Notifications and while I found https://github.com/douglasresendemaciel/fcm-laravel-notification that has that part, I found this project to be better for building the actual Push Notification.
I can give it a go in trying to build a wrapper around your Data/Notification/Options classes, unless you have already thought about going that way?
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());
Trying to send a Notification and I got the above error, how do I fix this?
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);
hello. thankyou for amazing package.
Do I need tokens are sent be chunk of 999 ?
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!!
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!
Working fine on android. Ios is receiving push through firebase console but not through laravel.
Please somebody help.
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?
i have an error
cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
i tried to add file cacert.pem in php.ini but error remains
help please
what is the variable response passed to "new DownstreamResponse" under Downstream Messages example. I am getting an error with this.
when i call:
$downstreamResponse = FCM::sendTo($this->tokens, $this->options, $this->notification,$this->data);
can someone help?
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 ?
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.
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?
I m trying to send notifications but I am receiving this error.
Laravel-FCM.INFO: notification send to 3 devices success: 0 failures: 3 number of modified token : 0
I am using (Sending a Downstream Message to Multiple Devices) code
cURL error 35: OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to fcm.googleapis.com:443
I have a issue like that. But, How to use curl_setopt?
http://stackoverflow.com/questions/19822075/fb-sdk-and-curl-unknown-ssl-protocol-error-in-connection-to-graph-facebook-com
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.