-
Notifications
You must be signed in to change notification settings - Fork 127
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
Fix for "A message can only have one of the following targets" error #116
Fix for "A message can only have one of the following targets" error #116
Conversation
https://github.com/kreait/firebase-php/blob/6.x/src/Firebase/Messaging/CloudMessage.php#L75 It checks array keys but does not check if they are empty or not, so it causes "A message can only have one of the following targets: condition, token, topic, unknown" error.
please merge this PR. |
@HAstaShakiba Meanwhile you can use https://github.com/symplify/vendor-patches to patch the error |
@atymic please merge this PR |
@atymic kindly merge this PR |
temporary resolution of the problem... |
up |
1 similar comment
up |
@atymic Why is this PR taking so long time to merge? |
up |
For real..? PR with such tiny changes takes forever to merge? |
@atymic, could you take a look here? Thanks |
up @atymic |
👍 |
any solutions found for this ? |
|
"kreait/firebase-php": "6.3.1" |
If the maintainer doesn't merge the PR, you could use your FcmMessage class to extend the original ones from the last version of the package. namespace App\Notifications\Concerns;
class FcmMessage extends \NotificationChannels\Fcm\FcmMessage
{
public function toArray(): array
{
$data = [
'name' => $this->getName(),
'data' => $this->getData(),
'notification' => ! is_null($this->getNotification()) ? $this->getNotification()->toArray() : null,
'android' => ! is_null($this->getAndroid()) ? $this->getAndroid()->toArray() : null,
'webpush' => ! is_null($this->getWebpush()) ? $this->getWebpush()->toArray() : null,
'apns' => ! is_null($this->getApns()) ? $this->getApns()->toArray() : null,
'fcm_options' => ! is_null($this->getFcmOptions()) ? $this->getFcmOptions()->toArray() : null,
];
if ($token = $this->getToken()) {
$data['token'] = $token;
}
if ($topic = $this->getTopic()) {
$data['topic'] = $topic;
}
if ($condition = $this->getCondition()) {
$data['condition'] = $condition;
}
return $data;
}
} Then, replace your notifications to use your own FcmMessage like so: class PushNotification extends Notification
{
// ...
public function toFcm($notifiable)
{
return \App\Notifications\Concerns\FcmMessage::create();
}
// ...
} |
=> "A message can only have one of the following targets: condition, token, topic, unknown" again the same issue generates. |
Any news here? |
@masterix21 The create function needs to be overridden as well. namespace App\Notifications\Concerns;
class FcmMessage extends \NotificationChannels\Fcm\FcmMessage
{
public static function create(): self
{
return new self;
}
public function toArray(): Array
{
$data = [
'name' => $this->getName(),
'data' => $this->getData(),
'notification' => ! is_null($this->getNotification()) ? $this->getNotification()->toArray() : null,
'android' => ! is_null($this->getAndroid()) ? $this->getAndroid()->toArray() : null,
'webpush' => ! is_null($this->getWebpush()) ? $this->getWebpush()->toArray() : null,
'apns' => ! is_null($this->getApns()) ? $this->getApns()->toArray() : null,
'fcm_options' => ! is_null($this->getFcmOptions()) ? $this->getFcmOptions()->toArray() : null,
];
if ($token = $this->getToken()) {
$data['token'] = $token;
}
if ($topic = $this->getTopic()) {
$data['topic'] = $topic;
}
if ($condition = $this->getCondition()) {
$data['condition'] = $condition;
}
return $data;
}
} class PushNotification extends Notification
{
// ...
public function toFcm($notifiable)
{
return \App\Notifications\Concerns\FcmMessage::create();
}
// ...
} |
Apologies for the delay, I'm not the maintainer of this specific package and had notifications off. I'll merge shortly, if anyone is interested in joining as maintainer please email me. |
@atymic - happy to help out with maintenance. I already look after the APN and Facebook channels as well. |
https://github.com/kreait/firebase-php/blob/6.x/src/Firebase/Messaging/CloudMessage.php#L75
It checks array keys but does not check if they are empty or not, so it causes "A message can only have one of the following targets: condition, token, topic, unknown" error.