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

addTopic in && non only in || #50

Open
VanManuel83 opened this issue May 20, 2021 · 9 comments
Open

addTopic in && non only in || #50

VanManuel83 opened this issue May 20, 2021 · 9 comments
Labels
enhancement New feature or request

Comments

@VanManuel83
Copy link

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

@rolinger
Copy link
Collaborator

@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.

@VanManuel83
Copy link
Author

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).

@rolinger
Copy link
Collaborator

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");

@VanManuel83
Copy link
Author

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

@rolinger
Copy link
Collaborator

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

@VanManuel83
Copy link
Author

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.

@AndyGaskell
Copy link
Collaborator

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.

@VanManuel83
Copy link
Author

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 ;)

@AndyGaskell
Copy link
Collaborator

AndyGaskell commented Jun 9, 2021

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

$request['condition'] = array_reduce($this->topics, function ($carry, string $topic) {

@AndyGaskell AndyGaskell added the enhancement New feature or request label Jun 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants