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

Support for sending batches of messages in API/v1 #114

Open
gersonazgo opened this issue Jun 20, 2023 · 8 comments
Open

Support for sending batches of messages in API/v1 #114

gersonazgo opened this issue Jun 20, 2023 · 8 comments

Comments

@gersonazgo
Copy link

Feature Request

Is your feature request related to a problem? Please describe.
I'm using the 'fcm' gem in my Rails project to send my push notifications via Firebase. The problem I'm encountering is that the gem does not currently support batch messages (API/v1, the legacy works perfect). This means that I have to send each message individually, which is quite inefficient

Describe the solution you'd like
According to the Firebase Documentation, the REST API and Admin SDKs support sending messages in batches of up to 500 messages. This feature allows developers to group messages together and send them in a single API call, providing significant performance improvement over sending individual HTTP requests for each message.

Describe alternatives you've considered
Without this feature, I'm forced to loop through each message and send it individually or build the batch logic myself — which I think should belong in this gem.

Thank you for your consideration.

@flivni
Copy link

flivni commented Aug 1, 2023

I'd like batch support as well. Any plans to implement?

If not, would you accept a PR that adds? For now, either:

Option (a) add a method called send_all_v1(messages)
Option (b) allow send_v1(...) to take either an individual message or an array of messages.

@JerakRus
Copy link

JerakRus commented Dec 6, 2023

It seems to me that the problem is not entirely relevant, this API will soon be deleted from Google and it will be necessary to think about how to switch to supporting a new one. https://firebase.google.com/support/faq?hl=ru#fcm-23-deprecation. If I understood everything correctly of course.

@AllanKlaus
Copy link

It seems to me that the problem is not entirely relevant, this API will soon be deleted from Google and it will be necessary to think about how to switch to supporting a new one. https://firebase.google.com/support/faq?hl=ru#fcm-23-deprecation. If I understood everything correctly of course.

The gem already support the new standard the format that will be deprecated will be the send thought POST https://fcm.googleapis.com/fcm/send and the API already implements the new request POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send. https://firebase.google.com/docs/cloud-messaging/migrate-v1?hl=pt-br#update-the-server-endpoint

you can check on code https://github.com/decision-labs/fcm/blob/master/lib/fcm.rb#L8

So we still need this implementation to send in batches

@sabman sabman closed this as completed Aug 29, 2024
@JerakRus
Copy link

JerakRus commented Aug 29, 2024

@sabman Hello, I see that you have closed the issue, but I do not see any changes in the functionality of the library over the past year?

@sabman sabman reopened this Aug 29, 2024
@sabman
Copy link
Member

sabman commented Sep 18, 2024

Can you please try with new version 2.0.0 https://github.com/decision-labs/fcm?tab=readme-ov-file#send-messages-to-topics

@JerakRus
Copy link

JerakRus commented Sep 20, 2024

We would love to, but using topics is not suitable for us, because... We send messages containing sensitive information to our users. And we also have a system for delineating user rights, which is processed in the backend. Shifting this task to the frontend with subscribing/unsubscribing to topics is not safe 😢

@erimicel
Copy link
Contributor

erimicel commented Sep 20, 2024

@JerakRus According to firebase doc:

Important: The batch send methods described in this section were deprecated on June 21, 2023, and will be removed in June 2024. For protocol, instead use the standard HTTP v1 API send method, implementing your own batch send by iterating through the list of recipients and sending to each recipient's token.

This means you can just loop your tokens and send messages one by one, adding this batch method to gem would be doing the same I believe

@JerakRus
Copy link

JerakRus commented Sep 27, 2024

@erimicel What you described is implemented using the send_v1 sending method - we have already done this earlier, otherwise we would now be sitting without push notifications.

The method shared above seems to still send messages to “topics” and this requires managing channel subscriptions on the application side. As I wrote above, this approach does not suit us and we cannot test it. But I'm sure this will suit someone else, and it's a useful feature, thanks!

I wrote so that someone else who finds the method suitable would test it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants