Add support for sending FCM messages to topics
Closed this issue · 2 comments
I noticed that while FCM device tokens are supported, there’s currently no way to send messages to a topic (e.g. /topics/news). This is part of the official FCM API and would be very useful when broadcasting notifications to a group of users.
Reference:
FCM documentation
Feature request:
Add support for passing a topic parameter when sending via FCM. Although this requires subscribing/unsubscribing users to Firebase Topics, which might not align with the existing notification model, it would be great to have the option available.
Example payload:
POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1
Content-Type: application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA
{
"message":{
"topic" : "foo-bar",
"notification" : {
"body" : "This is a Firebase Cloud Messaging Topic Message!",
"title" : "FCM Message"
}
}
}
There are a few reasons Topics aren’t first-class:
- They're FCM-only
- As you mentioned, they don't align well with the current workflow
- You can already broadcast today by fanning out to multiple devices in the library:
devices = [device_a, device_b, ...]
notification.deliver_later_to(devices)That said, if you're managing Firebase Topic subscriptions yourself, you can send to a topic via the .with_google payload override:
notification = ApplicationPushNotification.with_google(topic: "topic").new(title: "hello")
# This will generate the following payload:
ActionNativePush.service_for("google", notification).send(:payload_from, notification)
{
message: {
data: {},
android: {notification: {title: "hello"}, priority: "high"},
topic: "topic"
}
}
# Send it via
ActionNativePush.service_for("google", notification).push(notification)Thank you for the details. I guess it makes sense, anyone who wants to use the topic can manage it themselves and override if needed.
I will close this issue