Messaging service bound to the provided app.
Signature:
export declare class Messaging
Constructors
| Constructor | Modifiers | Description |
|---|---|---|
| (constructor)(app) | Gets the service for the current app. |
Properties
| Property | Modifiers | Type | Description |
|---|---|---|---|
| app | App | The 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 -- i.e. none of the messages in the list could be sent. Partial failures are 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 -- i.e. 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](/docs/cloud-messaging/admin/legacy-fcm#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](/docs/cloud-messaging/admin/legacy-fcm#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](/docs/cloud-messaging/admin/legacy-fcm#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](/docs/cloud-messaging/admin/legacy-fcm#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](/docs/cloud-messaging/manage-topics#suscribe_and_unsubscribe_using_the) 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](/docs/cloud-messaging/admin/manage-topic-subscriptions#unsubscribe_from_a_topic) for code samples and detailed documentation. Optionally, you can provide an array of tokens to unsubscribe multiple devices. |
Messaging.(constructor)
Gets the service for the current app.
Signature:
constructor(app: App);
Parameters
| Parameter | Type | Description |
|---|---|---|
| app | App |
Example
var messaging = app.messaging();
// The above is shorthand for:
// var messaging = admin.messaging(app);
The Messaging service for the current app.
Messaging.app
The 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. A promise fulfilled with a unique message ID string after the message has been successfully handed off to the FCM service for delivery. |
Returns:
Promise<string>
Messaging.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.
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. A Promise fulfilled with an object representing the result of the send operation. |
Returns:
Promise<BatchResponse>
Messaging.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.
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. A Promise fulfilled with an object representing the result of the send operation. |
Returns:
Promise<BatchResponse>
Messaging.sendToCondition()
Sends an FCM message to a condition.
See [Send to a condition](/docs/cloud-messaging/admin/legacy-fcm#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. A promise fulfilled with the server's response after the message has been sent. |
Returns:
Promise<MessagingConditionResponse>
Messaging.sendToDevice()
Sends an FCM message to a single device corresponding to the provided registration token.
See [Send to individual devices](/docs/cloud-messaging/admin/legacy-fcm#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. A promise fulfilled with the server's response after the message has been sent. |
Returns:
Promise<MessagingDevicesResponse>
Messaging.sendToDeviceGroup()
Sends an FCM message to a device group corresponding to the provided notification key.
See [Send to a device group](/docs/cloud-messaging/admin/legacy-fcm#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. A promise fulfilled with the server's response after the message has been sent. |
Returns:
Promise<MessagingDeviceGroupResponse>
Messaging.sendToTopic()
Sends an FCM message to a topic.
See [Send to a topic](/docs/cloud-messaging/admin/legacy-fcm#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. A promise fulfilled with the server's response after the message has been sent. |
Returns:
Promise<MessagingTopicResponse>
Messaging.subscribeToTopic()
Subscribes a device to an FCM topic.
See [Subscribe to a topic](/docs/cloud-messaging/manage-topics#suscribe_and_unsubscribe_using_the) 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. A promise fulfilled with the server's response after the device has been subscribed to the topic. |
Returns:
Promise<MessagingTopicManagementResponse>
Messaging.unsubscribeFromTopic()
Unsubscribes a device from an FCM topic.
See [Unsubscribe from a topic](/docs/cloud-messaging/admin/manage-topic-subscriptions#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. A promise fulfilled with the server's response after the device has been unsubscribed from the topic. |
Returns:
Promise<MessagingTopicManagementResponse>