symfony: The "firebase" scheme is not supported.

Symfony version(s) affected

5.4.*

Description

Hi, when I try to use Firebase Notifier i got this error. image

How to reproduce

I try to inject TexterInterface in Command (only for testing) image This is my config\packages\notifier.yaml image And this is .env image

Possible Solution

No response

Additional Context

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (5 by maintainers)

Most upvoted comments

I’ve got a working POC extending Notification and Recipient classes:

class FirebaseAwareRecipient extends Recipient
{
    private string $firebaseToken;

    public function __construct(string $email = '', string $phone = '', string $firebaseToken = '')
    {
        parent::__construct($email, $phone);
        $this->firebaseToken = $firebaseToken;
    }

    public function getFirebaseToken(): string
    {
        return $this->firebaseToken;
    }

}

class FirebaseAwareNotification extends Notification implements ChatNotificationInterface
{
    public function asChatMessage(RecipientInterface $recipient, string $transport = null): ?ChatMessage
    {
        $message = ChatMessage::fromNotification($this);
        if('firebase' === $transport) {
            $message->subject($this->getContent())
            ->options(new AndroidNotification(
                $recipient->getFirebaseToken(),
                ['title' => $this->getSubject()]
            ));
        }
        return $message;    
    }
}

$notification = (new FirebaseAwareNotification('New Invoice'))
    ->content('You got a new invoice for 15 EUR.')
    ->importance(Notification::IMPORTANCE_HIGH);
$this->notifier->send($notification, new FirebaseAwareRecipient('user@example.com', '', 'FIREBASE-TOKEN-HERE')));

Thanks a lot for the answer. Thanks to your help, I fixed all the problems and now the notifications work perfectly. Hopefully someone will work on improving the Notifier documentation.

I am sorry for my last comment. I had a deeper look at the firebase-notifier and its poor documentation. This code (https://github.com/symfony/firebase-notifier/blob/5.4/FirebaseTransport.php#L48:L51) is the key. You have to use firebase with ChatMessage instances and recording to the notifier documentation please try the following (as I don’t use firebase):

use Symfony\Component\Notifier\Bridge\Firebase\Notification\AndroidNotification;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\ChatterInterface;

public function __invoke(ChatterInterface $chatter)
{
    // you can also use WebNotification or IOSNotification with their special options
    // the second array is used for payload options
    $options = new AndroidNotification('to', []);

    $message = (new ChatMessage('Hello world!'))
        ->transport('firebase')
        ->options($options);

    $sentMessage = $chatter->send($message);
}

Edit: And don’t forget to move firebase: '%env(FIREBASE_DSN)%' from texter_transports to chatter_transports in notifier.yaml.