php-fcm icon indicating copy to clipboard operation
php-fcm copied to clipboard

addTopic in && non only in ||

Open VanManuel83 opened this issue 3 years ago • 9 comments

Is it possibile to implement the feature wich we can control the push condition by ourself. So we can control the query to select the correct user to sent notification direct, in OR, AND or a both method!

Thanks

VanManuel83 avatar May 20 '21 09:05 VanManuel83

@VanManuel83 - could you elaborate on the request please. I am not fully understanding the request. Provide an example of what you are looking to do.

rolinger avatar May 20 '21 14:05 rolinger

Yes...

In Data and Notification php file in the getBody function there is this lines of code:

`if (!empty($this->topics)) { $request['condition'] = array_reduce($this->topics, function ($carry, string $topic) { $topicSyntax = "'%s' in topics";

            if (end($this->topics) === $topic) {
                return $carry .= sprintf($topicSyntax, $topic);
            }

            return $carry .= sprintf($topicSyntax, $topic) . '||';
        });
    }`

As you can see, it is manage only an equal topi, or a query in OR logic operator. So, if a set an array of topi Ex: ['sports','food'] it will send notification to all users subscribed to sports or food. If i wanto to send a notification only to user that are subscribed to Sports AND Food, i'm not able now, or i didn't find the way (i add by myself the condition).

VanManuel83 avatar May 20 '21 14:05 VanManuel83

Thanks for clarifying. Unless I am misunderstanding the request, you can already do this, up to 5 topics per message:

$notification = $client->pushNotification($title, $body, "");
$notification->addTopic("mytopic_all");
$notification->addTopic("mytopic_nursery");
$notification->addTopic("mytopic_year1");
$notification->addTopic("mytopic_year2");
$notification->addTopic("mytopic_year3");

rolinger avatar May 20 '21 14:05 rolinger

Thanks @rolinger , i saw thi condition, but it doesn't seem to work. It send the notification on both topic!

VanManuel83 avatar May 20 '21 14:05 VanManuel83

@VanManuel83 - I don't understand. Isn't that what you want....to send messages on both Sport AND Food?

rolinger avatar May 21 '21 14:05 rolinger

Sorry, no!

Make an exampe:

Registration form with classic user data and a checkboxes with interesting (Sport, Food, Travel, AI, VR ... )

User A select Sport and Food User B select Sport and Travel

If i use the code above, Firebase send the notification to user a and the user b, beacuse both are in the topic Sport.

I need to send notification only to user a beacuse it had the interesting sport and food. I just test a lot of case and are all the she same, i did not found the way to use AND instead of OR.

VanManuel83 avatar May 21 '21 15:05 VanManuel83

Hi @VanManuel83

Is this a feature provided by the Firebase Cloud Messaging system?

I can't find any mention of it in google's documentation, like at https://firebase.google.com/docs/cloud-messaging/android/topic-messaging

I think PHP-FCM can only really provide a wrapper API for features provided by the underlying FCM system.

AndyGaskell avatar May 26 '21 08:05 AndyGaskell

Hi @AndyGaskell , here we talk about php, or javascript, so the link to referrer to is:

At the bottom, you can find: "TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics)" That's the point i was looking for and i was tring to do by myself ;)

VanManuel83 avatar Jun 03 '21 13:06 VanManuel83

Hi @VanManuel83

Ah, I see it, sorry, I'd not made it that far down the document https://firebase.google.com/docs/cloud-messaging/js/topic-messaging#build_send_requests

So, we'd have to add the condition element to the message.

We could probably work this into Push -> Notification -> getBody but it'd need a few changes, I'll have a think about how we'd implement it https://github.com/EdwinHoksberg/php-fcm/blob/8b13d1a38dbcd14773c815cdde45a093cf6c9481/src/Push/Notification.php#L221

AndyGaskell avatar Jun 09 '21 14:06 AndyGaskell