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

Getting error - Unsupported message type, when using sendMulticast #6

Closed
MuronOu opened this issue Dec 22, 2019 · 2 comments
Closed

Comments

@MuronOu
Copy link

MuronOu commented Dec 22, 2019

Hello!

When I try to sen multiple message with sendMulticast from Kreait\Firebase\Messaging I recive an exception - _Unsupported message type. Use an array or a class implementing %sKreait\Firebase\Messaging\Message, despite the fact that I use CloudMessage or Notification.

use Kreait\Firebase\Messaging;
use Kreait\Firebase\Messaging\CloudMessage;
use Kreait\Firebase\Messaging\Message;
use Kreait\Firebase\Messaging\Notification;        

.....

        $message = [
            'title' => __('mobile_notifications_messages.posts.' . $eventName, [
                $author,
                $post->title,
            ]),
            'body' => 'Something'
        ];
        $message = Notification::fromArray($message);
        $response = $this->messaging->sendMulticast($message, $deviceTokens);

I use Laravel 5.8

Could you please help me with this?

@jeromegamez
Copy link
Member

You've almost got it!

The first $message array is actually the notification data, not a full message. You have two possibilities here:

Write the whole message as an array and use CloudMessage

$messageData = [
    'notification' => [ // <- This is the difference to your code
        'title' => __('mobile_notifications_messages.posts.' . $eventName, [
            $author,
            $post->title,
        ]),
        'body' => 'Something'
    ]
];
$message = CloudMessage::fromArray($messageData);

Write only the notification as an array and append it to a new CloudMessage

// Note that this variable is named $notification and passed
// to a new $message below
$notification = [
    'title' => __('mobile_notifications_messages.posts.' . $eventName, [
        $author,
        $post->title,
    ]),
    'body' => 'Something'
];

$message = CloudMessage::new()->withNotification($notification);

I hope this helps!

@MuronOu
Copy link
Author

MuronOu commented Dec 24, 2019

Yee, it works!
Thank you very much! :)

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