Gets the Messaging service for the current app.

example
var messaging = app.messaging();
// The above is shorthand for:
// var messaging = admin.messaging(app);
returns

The Messaging service for the current app.

Index

Properties

app

app: App

The app associated with the current Messaging service instance.

example
var app = messaging.app;

Methods

send

  • send(message: Message, dryRun?: boolean): Promise<string>
  • Sends the given message via FCM.

    Parameters

    • message: Message

      The message payload.

    • Optional dryRun: boolean

      Whether to send the message in the dry-run (validation only) mode.

    Returns Promise<string>

    A promise fulfilled with a unique message ID string after the message has been successfully handed off to the FCM service for delivery.

sendAll

  • Sends all the messages in the given array via Firebase Cloud Messaging. Employs batching to send the entire list as a single RPC call. Compared to the send() method, this method is a significantly more efficient way to send multiple messages.

    The responses list obtained from the return value corresponds to the order of tokens in the MulticastMessage. An error from this method indicates a total failure -- i.e. none of the messages in the list could be sent. Partial failures are indicated by a BatchResponse return value.

    Parameters

    • messages: Array<Message>

      A non-empty array containing up to 500 messages.

    • Optional dryRun: boolean

      Whether to send the messages in the dry-run (validation only) mode.

    Returns Promise<BatchResponse>

    A Promise fulfilled with an object representing the result of the send operation.

sendMulticast

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

    This method uses the sendAll() API under the hood to send the given message to all the target recipients. The responses list obtained from the return value corresponds to the order of tokens in the MulticastMessage. An error from this method indicates a total failure -- i.e. the message was not sent to any of the tokens in the list. Partial failures are indicated by a BatchResponse return value.

    Parameters

    • message: MulticastMessage

      A multicast message containing up to 500 tokens.

    • Optional dryRun: boolean

      Whether to send the message in the dry-run (validation only) mode.

    Returns Promise<BatchResponse>

    A Promise fulfilled with an object representing the result of the send operation.

sendToCondition

  • Sends an FCM message to a condition.

    See Send to a condition for code samples and detailed documentation.

    Parameters

    • condition: string

      The condition determining to which topics to send the message.

    • payload: MessagingPayload

      The message payload.

    • Optional options: MessagingOptions

      Optional options to alter the message.

    Returns Promise<MessagingConditionResponse>

    A promise fulfilled with the server's response after the message has been sent.

sendToDevice

  • Sends an FCM message to a single device corresponding to the provided registration token.

    See Send to individual devices for code samples and detailed documentation. Takes either a registrationToken to send to a single device or a registrationTokens parameter containing an array of tokens to send to multiple devices.

    Parameters

    • registrationToken: string | string[]

      A device registration token or an array of device registration tokens to which the message should be sent.

    • payload: MessagingPayload

      The message payload.

    • Optional options: MessagingOptions

      Optional options to alter the message.

    Returns Promise<MessagingDevicesResponse>

    A promise fulfilled with the server's response after the message has been sent.

sendToDeviceGroup

  • Sends an FCM message to a device group corresponding to the provided notification key.

    See Send to a device group for code samples and detailed documentation.

    Parameters

    • notificationKey: string

      The notification key for the device group to which to send the message.

    • payload: MessagingPayload

      The message payload.

    • Optional options: MessagingOptions

      Optional options to alter the message.

    Returns Promise<MessagingDeviceGroupResponse>

    A promise fulfilled with the server's response after the message has been sent.

sendToTopic

  • Sends an FCM message to a topic.

    See Send to a topic for code samples and detailed documentation.

    Parameters

    • topic: string

      The topic to which to send the message.

    • payload: MessagingPayload

      The message payload.

    • Optional options: MessagingOptions

      Optional options to alter the message.

    Returns Promise<MessagingTopicResponse>

    A promise fulfilled with the server's response after the message has been sent.

subscribeToTopic