2

I have built spring java service using API logic in firebase cloud messaging.

Here is the URL for sample spring service https://github.com/petya0111/firebase-spring-service

Reproduce: set the request

Run project

POST http://localhost:8080/notification/messages

Headers: 
firebase-server-key : [your generated server key]
Body:

{
    "condition": " 'topic' in topics",
    "title": "Hello,Via Multiple Topics",
    "body": "Hello,Via Multiple Topics"
}

To send messages to condition you must first create topic

Reproduce: create topic

POST https://iid.googleapis.com/iid/v1/{token}/rel/topics/{topic}

headers 
Authorization  : key=[firebase-server-key]

200 OK 

According to the API's documentation, condition field is defined as case-insensitive. But in practice, it is actually case sensitive.

I am doing two tests with the same topic name (using upper and lower case chars). The original name of the topic I'm trying to send a message is defined as "Topic". Since the field must be case-insensitive, I am trying to use "topiC" and it should still send the message. Unfortunately, it doesn't. The field is actually case-sensitive and this is a huge problem from my perspective.

My second question:

When a non-existent topic is presented. Exchange with URL https://fcm.googleapis.com/fcm/send doesn't return an error.

My third question on this topic is: Condition OR '||'

 "condition": "  'topicChrome' in topics || 'topicFirefox' in topics "

is not working, I have subscribed one token on topic 'topicChrome' and another token on topic 'topicFirefox'.

petq0111
  • 33
  • 1
  • 6
  • Hi. Are you sending the notifications to an Android client app or iOS? Also, could you post a sample payload? – AL. Dec 05 '17 at 19:16
  • @AL. I've edited my question with sample code and request description. I'm sending notifications to browser devices and also Android devices. – petq0111 Dec 07 '17 at 07:34
  • Cool. For the 2nd question, it's just the usual behavior for FCM topics, regardless if the topic exists or not, it would just return a `messageId`. I'll try to repro the others if I have extra time and get back to you here. Cheers! – AL. Dec 07 '17 at 07:51
  • @AL. I can give you my sample web project and my server key, but I think this must remain private? – petq0111 Dec 07 '17 at 08:01
  • It's fine. I have some stuff here for FCM. And yes, your Server Key must remain secure. – AL. Dec 07 '17 at 09:11
  • Hi @petq0111 Sorry wasn't able to get back here for quite some time. I reviewed the docs. The part where it says *"case-insensitive"* is for the `condition` parameter -- i.e. you could use `"'yourTopic' IN TOPICS && 'topic2' IN TOPICS"`. Nothing is mentioned in the docs that the *topic name* itself is case-insensitive though. Even before during the GCM era, I'm pretty sure that topic names have always been case sensitive. – AL. Dec 11 '17 at 10:56
  • Nice, thank you, did you tested conditional or operator? :) – petq0111 Dec 11 '17 at 14:20
  • Yup. It works fine on my end. – AL. Dec 12 '17 at 06:54
  • Please, can you explain to me how to reproduce conditional OR operation? – petq0111 Dec 12 '17 at 08:38
  • I pretty much did the same thing as you were. If you're getting a `messageId` in the response, that means the notification was accepted by the FCM server. There might be a different reason as to why you're not receiving the notification on your clients. – AL. Dec 12 '17 at 09:25
  • I have subscribed one device for topic 'topic1' and another for 'topic2'. I send with condition field "condition": " 'topic1' in topics || 'topic2' in topics " The expected behavior is to send to two devices? – petq0111 Dec 12 '17 at 12:01
  • Yup. If the token is subscribed to either of the topics, then yes it should receive the payload. – AL. Dec 13 '17 at 01:03
  • I have used this project https://github.com/firebase/quickstart-js/tree/master/messaging for front-end javascript app. But I can't understand, why conditional AND is working and OR is not working :( – petq0111 Dec 13 '17 at 13:27
  • That is odd. If you think that this is an unexpected behavior, I suggest reaching out to Firebase support to be able to look into this further. AFAICT and test, this should work just fine. – AL. Dec 14 '17 at 04:58

1 Answers1

4

Gonna go on ahead and add an answer, details similar to my comments.

According to the API's documentation, condition field is defined as case-insensitive. But in practice, it is actually case sensitive.

The topic name always has been case sensitive. The case-insensitive mentioned in the docs refers to the condition parameter. In other words, using:

"condition": "'topicChrome' IN TOPICS || 'topicFirefox' in topics"

(see the upper and lower case words) would be fine.

When a non-existent topic is presented. Exchange with URL https://fcm.googleapis.com/fcm/send doesn't return an error

This is working as expected. It's the developer's responsibility to keep track of which topic exists or doesn't exist (i.e. which ones have subscribers or not), similar to a device group (see my answer here).

For your third question, I've tested the conditions and it was working as expected on my end. I would suggest posting more details (hopefully in a separate question, since multi-questions in a single post isn't really a good practice here), specially showing the response -- is it an error or a success?

AL.
  • 36,815
  • 10
  • 142
  • 281
  • Regarding your last answer. In my case it is not working. see https://stackoverflow.com/questions/50496202/firebase-messaging-conditions-with-multiple-topics-not-working for example code to reproduce the issue – Gillis Haasnoot May 23 '18 at 22:44
  • I just want to confirm that the topics at FCM is case sensitive. news <> NEWS. so keep an eye on it! – Yohanim Sep 18 '21 at 07:14