FirebaseAdmin.Messaging.FirebaseMessaging

This is the entry point to all server-side Firebase Cloud Messaging (FCM) operations.

Summary

You can get an instance of this class via FirebaseMessaging.DefaultInstance.

Inheritance

Inherits from: FirebaseAdmin.IFirebaseService

Properties

DefaultInstance
Gets the messaging instance associated with the default Firebase app.

Public static functions

GetMessaging(FirebaseApp app)
Returns the messaging instance for the specified app.

Public functions

SendAllAsync(IEnumerable< Message > messages)
async Task< BatchResponse >
Sends all the messages in the given list via Firebase Cloud Messaging.
SendAllAsync(IEnumerable< Message > messages, CancellationToken cancellationToken)
async Task< BatchResponse >
Sends all the messages in the given list via Firebase Cloud Messaging.
SendAllAsync(IEnumerable< Message > messages, bool dryRun)
async Task< BatchResponse >
Sends all the messages in the given list via Firebase Cloud Messaging.
SendAllAsync(IEnumerable< Message > messages, bool dryRun, CancellationToken cancellationToken)
async Task< BatchResponse >
Sends all the messages in the given list via Firebase Cloud Messaging.
SendAsync(Message message)
async Task< string >
Sends a message to the FCM service for delivery.
SendAsync(Message message, CancellationToken cancellationToken)
async Task< string >
Sends a message to the FCM service for delivery.
SendAsync(Message message, bool dryRun)
async Task< string >
Sends a message to the FCM service for delivery.
SendAsync(Message message, bool dryRun, CancellationToken cancellationToken)
async Task< string >
Sends a message to the FCM service for delivery.
SendEachAsync(IEnumerable< Message > messages)
async Task< BatchResponse >
Sends each message in the given list via Firebase Cloud Messaging.
SendEachAsync(IEnumerable< Message > messages, CancellationToken cancellationToken)
async Task< BatchResponse >
Sends each message in the given list via Firebase Cloud Messaging.
SendEachAsync(IEnumerable< Message > messages, bool dryRun)
async Task< BatchResponse >
Sends each message in the given list via Firebase Cloud Messaging.
SendEachAsync(IEnumerable< Message > messages, bool dryRun, CancellationToken cancellationToken)
async Task< BatchResponse >
Sends each message in the given list via Firebase Cloud Messaging.
SendEachForMulticastAsync(MulticastMessage message)
async Task< BatchResponse >
Sends the given multicast message to all the FCM registration tokens specified in it.
SendEachForMulticastAsync(MulticastMessage message, CancellationToken cancellationToken)
async Task< BatchResponse >
Sends the given multicast message to all the FCM registration tokens specified in it.
SendEachForMulticastAsync(MulticastMessage message, bool dryRun)
async Task< BatchResponse >
Sends the given multicast message to all the FCM registration tokens specified in it.
SendEachForMulticastAsync(MulticastMessage message, bool dryRun, CancellationToken cancellationToken)
async Task< BatchResponse >
Sends the given multicast message to all the FCM registration tokens specified in it.
SendMulticastAsync(MulticastMessage message)
async Task< BatchResponse >
Sends the given multicast message to all the FCM registration tokens specified in it.
SendMulticastAsync(MulticastMessage message, CancellationToken cancellationToken)
async Task< BatchResponse >
Sends the given multicast message to all the FCM registration tokens specified in it.
SendMulticastAsync(MulticastMessage message, bool dryRun)
async Task< BatchResponse >
Sends the given multicast message to all the FCM registration tokens specified in it.
SendMulticastAsync(MulticastMessage message, bool dryRun, CancellationToken cancellationToken)
async Task< BatchResponse >
Sends the given multicast message to all the FCM registration tokens specified in it.
SubscribeToTopicAsync(IReadOnlyList< string > registrationTokens, string topic)
async Task< TopicManagementResponse >
Subscribes a list of registration tokens to a topic.
UnsubscribeFromTopicAsync(IReadOnlyList< string > registrationTokens, string topic)
async Task< TopicManagementResponse >
Unsubscribes a list of registration tokens from a topic.

Properties

DefaultInstance

static FirebaseMessaging DefaultInstance

Gets the messaging instance associated with the default Firebase app.

This property is null if the default app doesn't yet exist.

Public static functions

GetMessaging

FirebaseMessaging GetMessaging(
  FirebaseApp app
)

Returns the messaging instance for the specified app.

Details
Exceptions
System.ArgumentNullException
If the app argument is null.
Parameters
app
An app instance.
Returns
The FirebaseMessaging instance associated with the specified app.

Public functions

SendAllAsync

async Task< BatchResponse > SendAllAsync(
  IEnumerable< Message > messages
)

Sends all the messages in the given list via Firebase Cloud Messaging.

Employs batching to send the entire list as a single RPC call. Compared to the SendAsync(Message) method, this is a significantly more efficient way to send multiple messages.

Details
Exceptions
FirebaseMessagingException
If an error occurs while sending the messages.
Parameters
messages
Up to 500 messages to send in the batch. Cannot be null.
Returns
A BatchResponse containing details of the batch operation's outcome.

SendAllAsync

async Task< BatchResponse > SendAllAsync(
  IEnumerable< Message > messages,
  CancellationToken cancellationToken
)

Sends all the messages in the given list via Firebase Cloud Messaging.

Employs batching to send the entire list as a single RPC call. Compared to the SendAsync(Message) method, this is a significantly more efficient way to send multiple messages.

Details
Exceptions
FirebaseMessagingException
If an error occurs while sending the messages.
Parameters
messages
Up to 500 messages to send in the batch. Cannot be null.
cancellationToken
A cancellation token to monitor the asynchronous operation.
Returns
A BatchResponse containing details of the batch operation's outcome.

SendAllAsync

async Task< BatchResponse > SendAllAsync(
  IEnumerable< Message > messages,
  bool dryRun
)

Sends all the messages in the given list via Firebase Cloud Messaging.

Employs batching to send the entire list as a single RPC call. Compared to the SendAsync(Message) method, this is a significantly more efficient way to send multiple messages.

Details
Exceptions
FirebaseMessagingException
If an error occurs while sending the messages.
Parameters
messages
Up to 500 messages to send in the batch. Cannot be null.
dryRun
A boolean indicating whether to perform a dry run (validation only) of the send. If set to true, the message will be sent to the FCM backend service, but it will not be delivered to any actual recipients.
Returns
A BatchResponse containing details of the batch operation's outcome.

SendAllAsync

async Task< BatchResponse > SendAllAsync(
  IEnumerable< Message > messages,
  bool dryRun,
  CancellationToken cancellationToken
)

Sends all the messages in the given list via Firebase Cloud Messaging.

Employs batching to send the entire list as a single RPC call. Compared to the SendAsync(Message) method, this is a significantly more efficient way to send multiple messages.

Details
Exceptions
FirebaseMessagingException
If an error occurs while sending the messages.
Parameters
messages
Up to 500 messages to send in the batch. Cannot be null.
dryRun
A boolean indicating whether to perform a dry run (validation only) of the send. If set to true, the message will be sent to the FCM backend service, but it will not be delivered to any actual recipients.
cancellationToken
A cancellation token to monitor the asynchronous operation.
Returns
A BatchResponse containing details of the batch operation's outcome.

SendAsync

async Task< string > SendAsync(
  Message message
)

Sends a message to the FCM service for delivery.

The message gets validated both by the Admin SDK, and the remote FCM service. A successful return value indicates that the message has been successfully sent to FCM, where it has been accepted by the FCM service.

Details
Exceptions
ArgumentNullException
If the message argument is null.
ArgumentException
If the message contains any invalid fields.
FirebaseMessagingException
If an error occurs while sending the message.
Parameters
message
The message to be sent. Must not be null.
Returns
A task that completes with a message ID string, which represents successful handoff to FCM.

SendAsync

async Task< string > SendAsync(
  Message message,
  CancellationToken cancellationToken
)

Sends a message to the FCM service for delivery.

The message gets validated both by the Admin SDK, and the remote FCM service. A successful return value indicates that the message has been successfully sent to FCM, where it has been accepted by the FCM service.

Details
Exceptions
ArgumentNullException
If the message argument is null.
ArgumentException
If the message contains any invalid fields.
FirebaseMessagingException
If an error occurs while sending the message.
Parameters
message
The message to be sent. Must not be null.
cancellationToken
A cancellation token to monitor the asynchronous operation.
Returns
A task that completes with a message ID string, which represents successful handoff to FCM.

SendAsync

async Task< string > SendAsync(
  Message message,
  bool dryRun
)

Sends a message to the FCM service for delivery.

The message gets validated both by the Admin SDK, and the remote FCM service. A successful return value indicates that the message has been successfully sent to FCM, where it has been accepted by the FCM service.

If the dryRun option is set to true, the message will not be actually sent to the recipients. Instead, the FCM service performs all the necessary validations, and emulates the send operation. This is a good way to check if a certain message will be accepted by FCM for delivery.

Details
Exceptions
ArgumentNullException
If the message argument is null.
ArgumentException
If the message contains any invalid fields.
FirebaseMessagingException
If an error occurs while sending the message.
Parameters
message
The message to be sent. Must not be null.
dryRun
A boolean indicating whether to perform a dry run (validation only) of the send. If set to true, the message will be sent to the FCM backend service, but it will not be delivered to any actual recipients.
Returns
A task that completes with a message ID string, which represents successful handoff to FCM.

SendAsync

async Task< string > SendAsync(
  Message message,
  bool dryRun,
  CancellationToken cancellationToken
)

Sends a message to the FCM service for delivery.

The message gets validated both by the Admin SDK, and the remote FCM service. A successful return value indicates that the message has been successfully sent to FCM, where it has been accepted by the FCM service.

If the dryRun option is set to true, the message will not be actually sent to the recipients. Instead, the FCM service performs all the necessary validations, and emulates the send operation. This is a good way to check if a certain message will be accepted by FCM for delivery.

Details
Exceptions
ArgumentNullException
If the message argument is null.
ArgumentException
If the message contains any invalid fields.
FirebaseMessagingException
If an error occurs while sending the message.
Parameters
message
The message to be sent. Must not be null.
dryRun
A boolean indicating whether to perform a dry run (validation only) of the send. If set to true, the message will be sent to the FCM backend service, but it will not be delivered to any actual recipients.
cancellationToken
A cancellation token to monitor the asynchronous operation.
Returns
A task that completes with a message ID string, which represents successful handoff to FCM.

SendEachAsync

async Task< BatchResponse > SendEachAsync(
  IEnumerable< Message > messages
)

Sends each message in the given list via Firebase Cloud Messaging.

Unlike SendAllAsync(IEnumerable{Message}), this method makes an HTTP call for each message in the given list.

Details
Exceptions
FirebaseMessagingException
If an error occurs while sending the messages.
Parameters
messages
Up to 500 messages to send in the batch. Cannot be null or empty.
Returns
A BatchResponse containing details of the batch operation's outcome.

SendEachAsync

async Task< BatchResponse > SendEachAsync(
  IEnumerable< Message > messages,
  CancellationToken cancellationToken
)

Sends each message in the given list via Firebase Cloud Messaging.

Unlike SendAllAsync(IEnumerable{Message}, CancellationToken), this method makes an HTTP call for each message in the given list.

Details
Exceptions
FirebaseMessagingException
If an error occurs while sending the messages.
Parameters
messages
Up to 500 messages to send in the batch. Cannot be null or empty.
cancellationToken
A cancellation token to monitor the asynchronous operation.
Returns
A BatchResponse containing details of the batch operation's outcome.

SendEachAsync

async Task< BatchResponse > SendEachAsync(
  IEnumerable< Message > messages,
  bool dryRun
)

Sends each message in the given list via Firebase Cloud Messaging.

Unlike SendAllAsync(IEnumerable{Message}, bool), this method makes an HTTP call for each message in the given list.

Details
Exceptions
FirebaseMessagingException
If an error occurs while sending the messages.
Parameters
messages
Up to 500 messages to send in the batch. Cannot be null or empty.
dryRun
A boolean indicating whether to perform a dry run (validation only) of the send. If set to true, the message will be sent to the FCM backend service, but it will not be delivered to any actual recipients.
Returns
A BatchResponse containing details of the batch operation's outcome.

SendEachAsync

async Task< BatchResponse > SendEachAsync(
  IEnumerable< Message > messages,
  bool dryRun,
  CancellationToken cancellationToken
)

Sends each message in the given list via Firebase Cloud Messaging.

Unlike SendAllAsync(IEnumerable{Message}, bool, CancellationToken), this method makes an HTTP call for each message in the given list.

Details
Exceptions
FirebaseMessagingException
If an error occurs while sending the messages.
Parameters
messages
Up to 500 messages to send in the batch. Cannot be null or empty.
dryRun
A boolean indicating whether to perform a dry run (validation only) of the send. If set to true, the message will be sent to the FCM backend service, but it will not be delivered to any actual recipients.
cancellationToken
A cancellation token to monitor the asynchronous operation.
Returns
A BatchResponse containing details of the batch operation's outcome.

SendEachForMulticastAsync

async Task< BatchResponse > SendEachForMulticastAsync(
  MulticastMessage message
)

Sends the given multicast message to all the FCM registration tokens specified in it.

Unlike SendMulticastAsync(MulticastMessage), this method makes an HTTP call for each token in the given multicast message.

Details
Exceptions
FirebaseMessagingException
If an error occurs while sending the messages.
Parameters
message
The message to be sent. Must not be null or empty.
Returns
A BatchResponse containing details of the batch operation's outcome.

SendEachForMulticastAsync

async Task< BatchResponse > SendEachForMulticastAsync(
  MulticastMessage message,
  CancellationToken cancellationToken
)

Sends the given multicast message to all the FCM registration tokens specified in it.

Unlike SendMulticastAsync(MulticastMessage, CancellationToken), this method makes an HTTP call for each token in the given multicast message.

Details
Exceptions
FirebaseMessagingException
If an error occurs while sending the messages.
Parameters
message
The message to be sent. Must not be null or empty.
cancellationToken
A cancellation token to monitor the asynchronous operation.
Returns
A BatchResponse containing details of the batch operation's outcome.

SendEachForMulticastAsync

async Task< BatchResponse > SendEachForMulticastAsync(
  MulticastMessage message,
  bool dryRun
)

Sends the given multicast message to all the FCM registration tokens specified in it.

Unlike SendMulticastAsync(MulticastMessage, bool), this method makes an HTTP call for each token in the given multicast message.

If the dryRun option is set to true, the message will not be actually sent to the recipients. Instead, the FCM service performs all the necessary validations, and emulates the send operation. This is a good way to check if a certain message will be accepted by FCM for delivery.

Details
Exceptions
FirebaseMessagingException
If an error occurs while sending the messages.
Parameters
message
The message to be sent. Must not be null or empty.
dryRun
A boolean indicating whether to perform a dry run (validation only) of the send. If set to true, the message will be sent to the FCM backend service, but it will not be delivered to any actual recipients.
Returns
A BatchResponse containing details of the batch operation's outcome.

SendEachForMulticastAsync

async Task< BatchResponse > SendEachForMulticastAsync(
  MulticastMessage message,
  bool dryRun,
  CancellationToken cancellationToken
)

Sends the given multicast message to all the FCM registration tokens specified in it.

Unlike SendMulticastAsync(MulticastMessage, bool, CancellationToken), this method makes an HTTP call for each token in the given multicast message.

If the dryRun option is set to true, the message will not be actually sent to the recipients. Instead, the FCM service performs all the necessary validations, and emulates the send operation. This is a good way to check if a certain message will be accepted by FCM for delivery.

Details
Exceptions
FirebaseMessagingException
If an error occurs while sending the messages.
Parameters
message
The message to be sent. Must not be null or empty.
dryRun
A boolean indicating whether to perform a dry run (validation only) of the send. If set to true, the message will be sent to the FCM backend service, but it will not be delivered to any actual recipients.
cancellationToken
A cancellation token to monitor the asynchronous operation.
Returns
A BatchResponse containing details of the batch operation's outcome.

SendMulticastAsync

async Task< BatchResponse > SendMulticastAsync(
  MulticastMessage message
)

Sends the given multicast message to all the FCM registration tokens specified in it.

Details
Exceptions
FirebaseMessagingException
If an error occurs while sending the messages.
Parameters
message
The message to be sent. Must not be null.
Returns
A BatchResponse containing details of the batch operation's outcome.

SendMulticastAsync

async Task< BatchResponse > SendMulticastAsync(
  MulticastMessage message,
  CancellationToken cancellationToken
)

Sends the given multicast message to all the FCM registration tokens specified in it.

Details
Exceptions
FirebaseMessagingException
If an error occurs while sending the messages.
Parameters
message
The message to be sent. Must not be null.
cancellationToken
A cancellation token to monitor the asynchronous operation.
Returns
A BatchResponse containing details of the batch operation's outcome.

SendMulticastAsync

async Task< BatchResponse > SendMulticastAsync(
  MulticastMessage message,
  bool dryRun
)

Sends the given multicast message to all the FCM registration tokens specified in it.

If the dryRun option is set to true, the message will not be actually sent to the recipients. Instead, the FCM service performs all the necessary validations, and emulates the send operation. This is a good way to check if a certain message will be accepted by FCM for delivery.

Details
Exceptions
FirebaseMessagingException
If an error occurs while sending the messages.
Parameters
message
The message to be sent. Must not be null.
dryRun
A boolean indicating whether to perform a dry run (validation only) of the send. If set to true, the message will be sent to the FCM backend service, but it will not be delivered to any actual recipients.
Returns
A BatchResponse containing details of the batch operation's outcome.

SendMulticastAsync

async Task< BatchResponse > SendMulticastAsync(
  MulticastMessage message,
  bool dryRun,
  CancellationToken cancellationToken
)

Sends the given multicast message to all the FCM registration tokens specified in it.

If the dryRun option is set to true, the message will not be actually sent to the recipients. Instead, the FCM service performs all the necessary validations, and emulates the send operation. This is a good way to check if a certain message will be accepted by FCM for delivery.

Details
Exceptions
FirebaseMessagingException
If an error occurs while sending the messages.
Parameters
message
The message to be sent. Must not be null.
dryRun
A boolean indicating whether to perform a dry run (validation only) of the send. If set to true, the message will be sent to the FCM backend service, but it will not be delivered to any actual recipients.
cancellationToken
A cancellation token to monitor the asynchronous operation.
Returns
A BatchResponse containing details of the batch operation's outcome.

SubscribeToTopicAsync

async Task< TopicManagementResponse > SubscribeToTopicAsync(
  IReadOnlyList< string > registrationTokens,
  string topic
)

Subscribes a list of registration tokens to a topic.

Details
Parameters
registrationTokens
A list of registration tokens to subscribe.
topic
The topic name to subscribe to. /topics/ will be prepended to the topic name provided if absent.
Returns
A task that completes with a TopicManagementResponse, giving details about the topic subscription operations.

UnsubscribeFromTopicAsync

async Task< TopicManagementResponse > UnsubscribeFromTopicAsync(
  IReadOnlyList< string > registrationTokens,
  string topic
)

Unsubscribes a list of registration tokens from a topic.

Details
Parameters
registrationTokens
A list of registration tokens to unsubscribe.
topic
The topic name to unsubscribe from. /topics/ will be prepended to the topic name provided if absent.
Returns
A task that completes with a TopicManagementResponse, giving details about the topic unsubscription operations.