kreait / firebase-bundle

A Symfony Bundle for the Firebase PHP Admin SDK
https://github.com/kreait/firebase-php
MIT License
135 stars 25 forks source link

Messaging sendAll() does not return correct feedback when there's an errorneous request #15

Closed bds-viktoras closed 4 years ago

bds-viktoras commented 4 years ago

When using messaging component's sendAll() method to attempt sending multiple messages at once, if at least one of those messages bounces or there's an issue with FCM token, then the returned MulticastSendReport object is always empty.

In case there are no issues with any of sub-requests, the returned MulticastSendReport object contains all the feedback correctly.

jeromegamez commented 4 years ago

The sendAll() method currently needs to return a MulticastSendReport because of backward compatibility reasons, so it might be that not everything is included there, but could you be more specific on what's missing exactly?

I just tried with the following and got what I expected

$factory = (new Factory())->withServiceAccount('/path/to/firebase_service_account.json');
$messaging = $factory->createMessaging();

$messages = [
    ['token' => $androidToken, 'notification' => ['title' => 'Android title']],
    ['token' => 'failure', 'notification' => ['title' => 'Failed title']],
    ['token' => $testToken, 'notification' => ['title' => 'Test title']],
];

try {
    $report = $messaging->sendAll($messages);
} catch (MessagingException $e) {
    echo $e->getMessage();
    exit;
}

print_r([
    'failures' => $report->failures()->count(),
    'successes' => $report->successes()->count(),
]);

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

⬇️

❯ php test.php
Array
(
    [failures] => 1
    [successes] => 2
)
The registration token is not a valid FCM registration token
bds-viktoras commented 4 years ago

Running the exact same code as in your example returns an empty feedback list:

MulticastSendReport {#914
  -items: []
}

If the line with incorrect token is removed, then feedback array returns two items with their information.

In both cases two notifications are being delivered. so middle line failure does affect status reporting, but not the actual send process.

github-actions[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.