kutia-software-company/larafirebase

How to pass optional data

bluelupin opened this issue · 4 comments

I want to send optional data like. ["url" => "https://www.google.com"]
I don't see any option.

Additionally, how can I get a downstream response for failed tokens?

Hi @bluelupin,

  1. On next release you can pass optional/everything data you need.
  2. For response from firebase you just need to return or dump like this:
return Larafirebase::withTitle('Test Title')
            ->withBody('Test body')
            ->sendNotification($this->deviceTokens);

And you get response like this:

{
    "multicast_id": 4457181225109722248,
    "success": 0,
    "failure": 1,
    "canonical_ids": 0,
    "results": [
        {
            "error": "InvalidRegistration"
        }
    ]
}

@bluelupin I had the same problem, you can use fromArray on both methods(sendNotification and sendMessage) that will bypass the title, body ,... . Below is the part that builds the dataArray.

$fields = array(
            'registration_ids' => $tokens,
            'notification' => ($this->fromArray) ? $this->fromArray : [
                'title' => $this->title,
                'body' => $this->body,
                'image' => $this->image,
                'click_action' => $this->clickAction
            ],
            'priority' => $this->priority
        );

@alchalade yes you can use fromArray if you want to pass whatever you want for notification or data object.

Hi @bluelupin,

  1. On next release you can pass optional data.
  2. For response from firebase you just need to return or dump like this:
return Larafirebase::withTitle('Test Title')
            ->withBody('Test body')
            ->sendNotification($this->deviceTokens);

And you get response like this:

{
    "multicast_id": 4457181225109722248,
    "success": 0,
    "failure": 1,
    "canonical_ids": 0,
    "results": [
        {
            "error": "InvalidRegistration"
        }
    ]
}

Is there any way we can know which were the failed tokens.