Property

app

non-null admin.app.App

The app associated with the current Messaging service instance.

Example

var app = messaging.app;

Methods

send

send(message, dryRun) returns Promise containing string

Sends the given message via FCM.

Parameter

message

admin.messaging.Message

The message payload.

Value must not be null.

dryRun

Optional

boolean

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

Returns

non-null Promise containing 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

sendAll(messages, dryRun) returns Promise containing non-null admin.messaging.BatchResponse

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.

Parameter

messages

Array of non-null admin.messaging.Message

A non-empty array containing up to 100 messages.

Value must not be null.

dryRun

Optional

boolean

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

Returns

non-null Promise containing non-null admin.messaging.BatchResponse A Promise fulfilled with an object representing the result of the send operation.

sendMulticast

sendMulticast(message, dryRun) returns Promise containing non-null admin.messaging.BatchResponse

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.

Parameter

message

admin.messaging.MulticastMessage

A multicast message containing up to 100 tokens.

Value must not be null.

dryRun

Optional

boolean

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

Returns

non-null Promise containing non-null admin.messaging.BatchResponse A Promise fulfilled with an object representing the result of the send operation.

sendToCondition

sendToCondition(condition, payload, options) returns Promise containing non-null admin.messaging.MessagingConditionResponse

Sends an FCM message to a condition.

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

Parameter

condition

string

The condition determining to which topics to send the message.

payload

admin.messaging.MessagingPayload

The message payload.

Value must not be null.

options

Optional

admin.messaging.MessagingOptions

Optional options to alter the message.

Value must not be null.

Returns

non-null Promise containing non-null admin.messaging.MessagingConditionResponse A promise fulfilled with the server's response after the message has been sent.

sendToDevice

sendToDevice(registrationToken, payload, options) returns Promise containing non-null admin.messaging.MessagingDevicesResponse

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.

Parameter

registrationToken

string

The registration token for the device to which to send the message.

payload

admin.messaging.MessagingPayload

The message payload.

Value must not be null.

options

Optional

admin.messaging.MessagingOptions

Optional options to alter the message.

Value must not be null.

Returns

non-null Promise containing non-null admin.messaging.MessagingDevicesResponse A promise fulfilled with the server's response after the message has been sent.

sendToDevice

sendToDevice(registrationTokens, payload, options) returns Promise containing non-null admin.messaging.MessagingDevicesResponse

Sends an FCM message to an array of devices corresponding to the provided registration tokens.

See Send to individual devices for code samples and detailed documentation.

Parameter

registrationTokens

Array of string

An array of registration tokens for the devices to which to send the message.

Value must not be null.

payload

admin.messaging.MessagingPayload

The message payload.

Value must not be null.

options

Optional

admin.messaging.MessagingOptions

Optional options to alter the message.

Value must not be null.

Returns

non-null Promise containing non-null admin.messaging.MessagingDevicesResponse A promise fulfilled with the server's response after the message has been sent.

sendToDeviceGroup

sendToDeviceGroup(notificationKey, payload, options) returns Promise containing non-null admin.messaging.MessagingDeviceGroupResponse

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.

Parameter

notificationKey

string

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

payload

admin.messaging.MessagingPayload

The message payload.

Value must not be null.

options

Optional

admin.messaging.MessagingOptions

Optional options to alter the message.

Value must not be null.

Returns

non-null Promise containing non-null admin.messaging.MessagingDeviceGroupResponse A promise fulfilled with the server's response after the message has been sent.

sendToTopic

sendToTopic(topic, payload, options) returns Promise containing non-null admin.messaging.MessagingTopicResponse

Sends an FCM message to a topic.

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

Parameter

topic

string

The topic to which to send the message.

payload

admin.messaging.MessagingPayload

The message payload.

Value must not be null.

options

Optional

admin.messaging.MessagingOptions

Optional options to alter the message.

Value must not be null.

Returns

non-null Promise containing non-null admin.messaging.MessagingTopicResponse A promise fulfilled with the server's response after the message has been sent.

subscribeToTopic

subscribeToTopic(registrationTokens, topic) returns Promise containing non-null admin.messaging.MessagingTopicManagementResponse

Subscribes an array of devices to an FCM topic.

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

Parameter

registrationTokens

Array of string

An array of registration tokens for the devices for which to subscribe to the topic.

Value must not be null.

topic

string

The topic to which to subscribe.

Returns

non-null Promise containing non-null admin.messaging.MessagingTopicManagementResponse A promise fulfilled with the server's response after the devices have been subscribed to the topic.

subscribeToTopic

subscribeToTopic(registrationToken, topic) returns Promise containing non-null admin.messaging.MessagingTopicManagementResponse

Subscribes a single device to an FCM topic.

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

Parameter

registrationToken

string

The registration token for the device for which to subscribe to the topic.

topic

string

The topic to which to subscribe.

Returns

non-null Promise containing non-null admin.messaging.MessagingTopicManagementResponse A promise fulfilled with the server's response after the device has been subscribed to the topic.

unsubscribeFromTopic

unsubscribeFromTopic(registrationToken, topic) returns Promise containing non-null admin.messaging.MessagingTopicManagementResponse

Unsubscribes a single device from an FCM topic.

See Unsubscribe from a topic for code samples and detailed documentation.

Parameter

registrationToken

string

The registration token for the device for which to unsubscribe from the topic.

topic

string

The topic from which to unsubscribe.

Returns

non-null Promise containing non-null admin.messaging.MessagingTopicManagementResponse A promise fulfilled with the server's response after the device has been unsubscribed from the topic.

unsubscribeFromTopic

unsubscribeFromTopic(registrationTokens, topic) returns Promise containing non-null admin.messaging.MessagingTopicManagementResponse

Unsubscribes an array of devices from an FCM topic.

See Unsubscribe from a topic for code samples and detailed documentation.

Parameter

registrationTokens

Array of string

An array of registration tokens for the devices for which to unsubscribe from the topic.

Value must not be null.

topic

string

The topic from which to unsubscribe.

Returns

non-null Promise containing non-null admin.messaging.MessagingTopicManagementResponse A promise fulfilled with the server's response after the devices have been unsubscribed from the topic.