queelag / fcm

MIT License
6 stars 2 forks source link

Is there a way to subscribe to FCM topics? #3

Closed choiman1559 closed 1 month ago

choiman1559 commented 5 months ago

I looked at this library carefully and noticed that it makes no mention of the topic at all when it receives messages.

Is there a way to subscribe to a topic and receive messages via topic ? My app absolutely needs an implementation for topic because of technical reasons.

alchemicas commented 3 months ago

Hi @choiman1559 , this is a great question, I'm sure I've defined all that there was to define regarding topics on the send message API, but on the FCM client it's a bit of a mistery since I haven't tested it.

On paper you should still get the message with the relevant info on the client, then it's up to you how to handle it. Have you had a chance to try it out by sending a message with topic through the API and see what happens on the FCM client?

Sorry for the late reply! 🙏

alchemicas commented 3 months ago

I've looked a bit into it right now, seems like we just need to make an API call to subscribe a token to a topic. I'll see if I can expose it as a function in the following days.

https://firebase.google.com/docs/cloud-messaging/js/topic-messaging

suyog-bst commented 2 months ago

@choiman1559 If you're using this in FE, can't you simply make a call to your BE that runs in one of the FCM supported environments to subscribe directly?

alchemicas commented 1 month ago

Btw, dropping it here but you can subscribe to topics with the official firebase admin sdk: https://www.npmjs.com/package/firebase-admin

It also supports the send message, I'm wondering whether to still have those functions in my library at this point, or whether to just export them but use the ones from the firebase-admin package underneath.

Here's a direct link for reference for the subscribe topics feature: https://firebase.google.com/docs/cloud-messaging/manage-topics

alchemicas commented 1 month ago

I've exposed a couple of functions to manage topic subscriptions! They're called subscribeToFcmTopic and unsubscribeFromFcmTopic, they're available in the version v1.0.27-rc.0.

npm install @aracna/fcm@1.0.27-rc.0

Feel free to take a look and test the new version, if it works well I'll merge and close this issue! @choiman1559