Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloud messaging report say successful send 1 but no notification send or visible in firebase console #18

Closed
laTruffe79 opened this issue Feb 12, 2020 · 6 comments

Comments

@laTruffe79
Copy link

laTruffe79 commented Feb 12, 2020

Hello I'm using this via ajax :
`
public function fcmSendMessageToAll(Request $request)
{

    $firebaseInstance = new FirebaseInstance();

    //$title,$body,$imageUrl
    if ($request->input('title')==null || $request->input('body')==null){
        throw new InvalidArgumentException("Le champ titre ou texte est vide");
    }

    $firebaseUserRepository = new FirebaseUserRepo();
    try {
        $allUsers = $firebaseUserRepository->getAll();
    }catch (\Exception $exception){
        dd('erreur : '.$exception->getMessage());
    }


    $arrayTokens = array();
    foreach ($allUsers as $key => $firebaseUser) {
        if($firebaseUser->getToken() != null){
            echo 'token : '.$firebaseUser->getToken().PHP_EOL;
            $arrayTokens[] = $firebaseUser->getToken();
        }
    }

    //dd($arrayTokens);//test

    if (count($arrayTokens)>0){

        //$messaging = (new Firebase\Factory())->createMessaging();
        $messaging = $firebaseInstance->factory->createMessaging();

        $message = CloudMessage::new();


        $notification = Notification::fromArray([
            'title' => $request->input('title'),
            'body' => $request->input('body'),
            'image' => $request->input('imageurl'),
        ]);

        $message->withNotification($notification);

        try {
            $report = $messaging->sendMulticast($message, $arrayTokens);
            echo 'Successful sends: '.$report->successes()->count().PHP_EOL;
        }catch(Firebase\Exception\MessagingException $messagingException){
            echo 'Failed sends: '.$report->failures()->count().PHP_EOL;
            dd('erreur : '.$messagingException->getMessage());
        }

        if ($report->hasFailures()) {
            foreach ($report->failures()->getItems() as $failure) {
                echo $failure->error()->getMessage().PHP_EOL;
            }
        }

    }

}

`
unfortunately it says "successful sends : 1" (I've got just one test user with token) but no notification is in the firebase console or received on my phone ?
Do you see where is my error or is it a bug ? Thanks.

@jeromegamez
Copy link
Member

Unfortunately, there is no way of telling from our side whether there is a problem with message delivery. The Firebase console doesn't display messages sent over the Firebase APIs, and we can only say:

If the Firebase API doesn't return an error, we can assume:

  • the message was syntactically correct
  • the target of the message exists (in case of an invalid, expired or non-existing registration token for the current project, topics and conditions always work)
  • The Firebase API has accepted the message (that's represented by the "success")

From there on it's out of our vision - we can't tell when the message will be actually delivered or if it will be delivered at all. In the past years it was sometimes the case that https://status.firebase.google.com/ et.al. was green, but the APIs returned errors, or that messages took hours to arrive at their target.

Sometimes the notification was received at the target, but the app didn't recognize it or crashed, or the message was a data only message and didn't trigger a notification on the target device(s) (your message contains a notification, so that wouldn't apply).

Long story short: Sadly I'm unable to give you more information from the SDK perspective, but perhaps https://firebase.google.com/support/troubleshooter/fcm/delivery/diagnose can provide some further help 🤞

@laTruffe79
Copy link
Author

Am I the only one to face problems to send notifications with your library ? My code seems correct, otherwise I would get an error ?
Is there an update on fcm that your library don't support ?
Thank you for your answer.

@jeromegamez
Copy link
Member

No, you're not the only one, but it's rather rare that I hear of issues like this (or, if there are more, they don't get reported). But again: your code is correct, and the library works (otherwise you would get an error because Firebase rejects the requests).

Of course, the SDK will always be "late": if a new feature or change is implemented by Firebase, this SDK will only implement it later - but if you don't get an error, it should be fine on the SDK level.

@laTruffe79
Copy link
Author

Ok, thanks for your reply, I will investigate on my side because I can't give up this feature for my backoffice application. All advices are welcomed.

@jeromegamez
Copy link
Member

I'm closing this now, but feel free to add further comments or create a new issue.

FYI: If the issue is with the Laravel Package, create a new issue, here. If it's an issue with the functionality, open an issue at https://github.com/kreait/firebase-php

@laTruffe79
Copy link
Author

laTruffe79 commented Feb 24, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants