Messaging class

Messaging service bound to the provided app.

Signature:

export declare class Messaging 

Properties

Property Modifiers Type Description
app App The App associated with the current Messaging service instance.

Methods

Method Modifiers Description
send(message, dryRun) Sends the given message via FCM.
sendAll(messages, dryRun) 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, meaning that none of the messages in the list could be sent. Partial failures are indicated by a BatchResponse return value.
sendEach(messages, dryRun) Sends each message in the given array via Firebase Cloud Messaging.Unlike Messaging.sendAll(), this method makes a single RPC call for each message in the given array.The responses list obtained from the return value corresponds to the order of messages. An error from this method or a BatchResponse with all failures indicates a total failure, meaning that none of the messages in the list could be sent. Partial failures or no failures are only indicated by a BatchResponse return value.
sendEachForMulticast(message, dryRun) Sends the given multicast message to all the FCM registration tokens specified in it.This method uses the Messaging.sendEach() 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 or a BatchResponse with all failures indicates a total failure, meaning that the messages in the list could be sent. Partial failures or failures are only indicated by a BatchResponse return value.
sendMulticast(message, dryRun) 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, meaning that the message was not sent to any of the tokens in the list. Partial failures are indicated by a BatchResponse return value.
sendToCondition(condition, payload, options) Sends an FCM message to a condition.See Send to a condition for code samples and detailed documentation.
sendToDevice(registrationTokenOrTokens, payload, options) 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.
sendToDeviceGroup(notificationKey, payload, options) 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.
sendToTopic(topic, payload, options) Sends an FCM message to a topic.See Send to a topic for code samples and detailed documentation.
subscribeToTopic(registrationTokenOrTokens, topic) Subscribes a device to an FCM topic.See Subscribe to a topic for code samples and detailed documentation. Optionally, you can provide an array of tokens to subscribe multiple devices.
unsubscribeFromTopic(registrationTokenOrTokens, topic) Unsubscribes a device from an FCM topic.See Unsubscribe from a topic for code samples and detailed documentation. Optionally, you can provide an array of tokens to unsubscribe multiple devices.

Messaging.app

The App associated with the current Messaging service instance.

Signature:

get app(): App;

Example

var app = messaging.app;

Messaging.send()

Sends the given message via FCM.

Signature:

send(message: Message, dryRun?: boolean): Promise<string>;

Parameters

Parameter Type Description
message Message The message payload.
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.

Messaging.sendAll()

Use Messaging.sendEach() instead.

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, meaning that none of the messages in the list could be sent. Partial failures are indicated by a BatchResponse return value.

Signature:

sendAll(messages: Message[], dryRun?: boolean): Promise<BatchResponse>;

Parameters

Parameter Type Description
messages Message[] A non-empty array containing up to 500 messages.
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.

Messaging.sendEach()

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

Unlike Messaging.sendAll(), this method makes a single RPC call for each message in the given array.

The responses list obtained from the return value corresponds to the order of messages. An error from this method or a BatchResponse with all failures indicates a total failure, meaning that none of the messages in the list could be sent. Partial failures or no failures are only indicated by a BatchResponse return value.

Signature:

sendEach(messages: Message[], dryRun?: boolean): Promise<BatchResponse>;

Parameters

Parameter Type Description
messages Message[] A non-empty array containing up to 500 messages.
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.

Messaging.sendEachForMulticast()

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

This method uses the Messaging.sendEach() 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 or a BatchResponse with all failures indicates a total failure, meaning that the messages in the list could be sent. Partial failures or failures are only indicated by a BatchResponse return value.

Signature:

sendEachForMulticast(message: MulticastMessage, dryRun?: boolean): Promise<BatchResponse>;

Parameters

Parameter Type Description
message MulticastMessage A multicast message containing up to 500 tokens.
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.

Messaging.sendMulticast()

Use Messaging.sendEachForMulticast() instead.

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, meaning that the message was not sent to any of the tokens in the list. Partial failures are indicated by a BatchResponse return value.

Signature:

sendMulticast(message: MulticastMessage, dryRun?: boolean): Promise<BatchResponse>;

Parameters

Parameter Type Description
message MulticastMessage A multicast message containing up to 500 tokens.
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.

Messaging.sendToCondition()

Sends an FCM message to a condition.

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

Signature:

sendToCondition(condition: string, payload: MessagingPayload, options?: MessagingOptions): Promise<MessagingConditionResponse>;

Parameters

Parameter Type Description
condition string The condition determining to which topics to send the message.
payload MessagingPayload The message payload.
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.

Messaging.sendToDevice()

Use Messaging.send() instead.

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.

Signature:

sendToDevice(registrationTokenOrTokens: string | string[], payload: MessagingPayload, options?: MessagingOptions): Promise<MessagingDevicesResponse>;

Parameters

Parameter Type Description
registrationTokenOrTokens string | string[]
payload MessagingPayload The message payload.
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.

Messaging.sendToDeviceGroup()

Use Messaging.send() instead.

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.

Signature:

sendToDeviceGroup(notificationKey: string, payload: MessagingPayload, options?: MessagingOptions): Promise<MessagingDeviceGroupResponse>;

Parameters

Parameter Type Description
notificationKey string The notification key for the device group to which to send the message.
payload MessagingPayload The message payload.
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.

Messaging.sendToTopic()

Sends an FCM message to a topic.

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

Signature:

sendToTopic(topic: string, payload: MessagingPayload, options?: MessagingOptions): Promise<MessagingTopicResponse>;

Parameters

Parameter Type Description
topic string The topic to which to send the message.
payload MessagingPayload The message payload.
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.

Messaging.subscribeToTopic()

Subscribes a device to an FCM topic.

See Subscribe to a topic for code samples and detailed documentation. Optionally, you can provide an array of tokens to subscribe multiple devices.

Signature:

subscribeToTopic(registrationTokenOrTokens: string | string[], topic: string): Promise<MessagingTopicManagementResponse>;

Parameters

Parameter Type Description
registrationTokenOrTokens string | string[]
topic string The topic to which to subscribe.

Returns:

Promise<MessagingTopicManagementResponse>

A promise fulfilled with the server's response after the device has been subscribed to the topic.

Messaging.unsubscribeFromTopic()

Unsubscribes a device from an FCM topic.

See Unsubscribe from a topic for code samples and detailed documentation. Optionally, you can provide an array of tokens to unsubscribe multiple devices.

Signature:

unsubscribeFromTopic(registrationTokenOrTokens: string | string[], topic: string): Promise<MessagingTopicManagementResponse>;

Parameters

Parameter Type Description
registrationTokenOrTokens string | string[]
topic string The topic from which to unsubscribe.

Returns:

Promise<MessagingTopicManagementResponse>

A promise fulfilled with the server's response after the device has been unsubscribed from the topic.