1 | /*! firebase-admin v12.0.0 */
|
2 | /*!
|
3 | * @license
|
4 | * Copyright 2021 Google Inc.
|
5 | *
|
6 | * Licensed under the Apache License, Version 2.0 (the "License");
|
7 | * you may not use this file except in compliance with the License.
|
8 | * You may obtain a copy of the License at
|
9 | *
|
10 | * http://www.apache.org/licenses/LICENSE-2.0
|
11 | *
|
12 | * Unless required by applicable law or agreed to in writing, software
|
13 | * distributed under the License is distributed on an "AS IS" BASIS,
|
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15 | * See the License for the specific language governing permissions and
|
16 | * limitations under the License.
|
17 | */
|
18 | import { FirebaseArrayIndexError, FirebaseError } from '../app/index';
|
19 | export interface BaseMessage {
|
20 | data?: {
|
21 | [key: string]: string;
|
22 | };
|
23 | notification?: Notification;
|
24 | android?: AndroidConfig;
|
25 | webpush?: WebpushConfig;
|
26 | apns?: ApnsConfig;
|
27 | fcmOptions?: FcmOptions;
|
28 | }
|
29 | export interface TokenMessage extends BaseMessage {
|
30 | token: string;
|
31 | }
|
32 | export interface TopicMessage extends BaseMessage {
|
33 | topic: string;
|
34 | }
|
35 | export interface ConditionMessage extends BaseMessage {
|
36 | condition: string;
|
37 | }
|
38 | /**
|
39 | * Payload for the {@link Messaging.send} operation. The payload contains all the fields
|
40 | * in the BaseMessage type, and exactly one of token, topic or condition.
|
41 | */
|
42 | export type Message = TokenMessage | TopicMessage | ConditionMessage;
|
43 | /**
|
44 | * Payload for the {@link Messaging.sendMulticast} method. The payload contains all the fields
|
45 | * in the BaseMessage type, and a list of tokens.
|
46 | */
|
47 | export interface MulticastMessage extends BaseMessage {
|
48 | tokens: string[];
|
49 | }
|
50 | /**
|
51 | * A notification that can be included in {@link Message}.
|
52 | */
|
53 | export interface Notification {
|
54 | /**
|
55 | * The title of the notification.
|
56 | */
|
57 | title?: string;
|
58 | /**
|
59 | * The notification body
|
60 | */
|
61 | body?: string;
|
62 | /**
|
63 | * URL of an image to be displayed in the notification.
|
64 | */
|
65 | imageUrl?: string;
|
66 | }
|
67 | /**
|
68 | * Represents platform-independent options for features provided by the FCM SDKs.
|
69 | */
|
70 | export interface FcmOptions {
|
71 | /**
|
72 | * The label associated with the message's analytics data.
|
73 | */
|
74 | analyticsLabel?: string;
|
75 | }
|
76 | /**
|
77 | * Represents the WebPush protocol options that can be included in an
|
78 | * {@link Message}.
|
79 | */
|
80 | export interface WebpushConfig {
|
81 | /**
|
82 | * A collection of WebPush headers. Header values must be strings.
|
83 | *
|
84 | * See {@link https://tools.ietf.org/html/rfc8030#section-5 | WebPush specification}
|
85 | * for supported headers.
|
86 | */
|
87 | headers?: {
|
88 | [key: string]: string;
|
89 | };
|
90 | /**
|
91 | * A collection of data fields.
|
92 | */
|
93 | data?: {
|
94 | [key: string]: string;
|
95 | };
|
96 | /**
|
97 | * A WebPush notification payload to be included in the message.
|
98 | */
|
99 | notification?: WebpushNotification;
|
100 | /**
|
101 | * Options for features provided by the FCM SDK for Web.
|
102 | */
|
103 | fcmOptions?: WebpushFcmOptions;
|
104 | }
|
105 | /** Represents options for features provided by the FCM SDK for Web
|
106 | * (which are not part of the Webpush standard).
|
107 | */
|
108 | export interface WebpushFcmOptions {
|
109 | /**
|
110 | * The link to open when the user clicks on the notification.
|
111 | * For all URL values, HTTPS is required.
|
112 | */
|
113 | link?: string;
|
114 | }
|
115 | /**
|
116 | * Represents the WebPush-specific notification options that can be included in
|
117 | * {@link WebpushConfig}. This supports most of the standard
|
118 | * options as defined in the Web Notification
|
119 | * {@link https://developer.mozilla.org/en-US/docs/Web/API/notification/Notification | specification}.
|
120 | */
|
121 | export interface WebpushNotification {
|
122 | /**
|
123 | * Title text of the notification.
|
124 | */
|
125 | title?: string;
|
126 | /**
|
127 | * An array of notification actions representing the actions
|
128 | * available to the user when the notification is presented.
|
129 | */
|
130 | actions?: Array<{
|
131 | /**
|
132 | * An action available to the user when the notification is presented
|
133 | */
|
134 | action: string;
|
135 | /**
|
136 | * Optional icon for a notification action.
|
137 | */
|
138 | icon?: string;
|
139 | /**
|
140 | * Title of the notification action.
|
141 | */
|
142 | title: string;
|
143 | }>;
|
144 | /**
|
145 | * URL of the image used to represent the notification when there is
|
146 | * not enough space to display the notification itself.
|
147 | */
|
148 | badge?: string;
|
149 | /**
|
150 | * Body text of the notification.
|
151 | */
|
152 | body?: string;
|
153 | /**
|
154 | * Arbitrary data that you want associated with the notification.
|
155 | * This can be of any data type.
|
156 | */
|
157 | data?: any;
|
158 | /**
|
159 | * The direction in which to display the notification. Must be one
|
160 | * of `auto`, `ltr` or `rtl`.
|
161 | */
|
162 | dir?: 'auto' | 'ltr' | 'rtl';
|
163 | /**
|
164 | * URL to the notification icon.
|
165 | */
|
166 | icon?: string;
|
167 | /**
|
168 | * URL of an image to be displayed in the notification.
|
169 | */
|
170 | image?: string;
|
171 | /**
|
172 | * The notification's language as a BCP 47 language tag.
|
173 | */
|
174 | lang?: string;
|
175 | /**
|
176 | * A boolean specifying whether the user should be notified after a
|
177 | * new notification replaces an old one. Defaults to false.
|
178 | */
|
179 | renotify?: boolean;
|
180 | /**
|
181 | * Indicates that a notification should remain active until the user
|
182 | * clicks or dismisses it, rather than closing automatically.
|
183 | * Defaults to false.
|
184 | */
|
185 | requireInteraction?: boolean;
|
186 | /**
|
187 | * A boolean specifying whether the notification should be silent.
|
188 | * Defaults to false.
|
189 | */
|
190 | silent?: boolean;
|
191 | /**
|
192 | * An identifying tag for the notification.
|
193 | */
|
194 | tag?: string;
|
195 | /**
|
196 | * Timestamp of the notification. Refer to
|
197 | * https://developer.mozilla.org/en-US/docs/Web/API/notification/timestamp
|
198 | * for details.
|
199 | */
|
200 | timestamp?: number;
|
201 | /**
|
202 | * A vibration pattern for the device's vibration hardware to emit
|
203 | * when the notification fires.
|
204 | */
|
205 | vibrate?: number | number[];
|
206 | [key: string]: any;
|
207 | }
|
208 | /**
|
209 | * Represents the APNs-specific options that can be included in an
|
210 | * {@link Message}. Refer to
|
211 | * {@link https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html |
|
212 | * Apple documentation} for various headers and payload fields supported by APNs.
|
213 | */
|
214 | export interface ApnsConfig {
|
215 | /**
|
216 | * A collection of APNs headers. Header values must be strings.
|
217 | */
|
218 | headers?: {
|
219 | [key: string]: string;
|
220 | };
|
221 | /**
|
222 | * An APNs payload to be included in the message.
|
223 | */
|
224 | payload?: ApnsPayload;
|
225 | /**
|
226 | * Options for features provided by the FCM SDK for iOS.
|
227 | */
|
228 | fcmOptions?: ApnsFcmOptions;
|
229 | }
|
230 | /**
|
231 | * Represents the payload of an APNs message. Mainly consists of the `aps`
|
232 | * dictionary. But may also contain other arbitrary custom keys.
|
233 | */
|
234 | export interface ApnsPayload {
|
235 | /**
|
236 | * The `aps` dictionary to be included in the message.
|
237 | */
|
238 | aps: Aps;
|
239 | [customData: string]: any;
|
240 | }
|
241 | /**
|
242 | * Represents the {@link https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html |
|
243 | * aps dictionary} that is part of APNs messages.
|
244 | */
|
245 | export interface Aps {
|
246 | /**
|
247 | * Alert to be included in the message. This may be a string or an object of
|
248 | * type `admin.messaging.ApsAlert`.
|
249 | */
|
250 | alert?: string | ApsAlert;
|
251 | /**
|
252 | * Badge to be displayed with the message. Set to 0 to remove the badge. When
|
253 | * not specified, the badge will remain unchanged.
|
254 | */
|
255 | badge?: number;
|
256 | /**
|
257 | * Sound to be played with the message.
|
258 | */
|
259 | sound?: string | CriticalSound;
|
260 | /**
|
261 | * Specifies whether to configure a background update notification.
|
262 | */
|
263 | contentAvailable?: boolean;
|
264 | /**
|
265 | * Specifies whether to set the `mutable-content` property on the message
|
266 | * so the clients can modify the notification via app extensions.
|
267 | */
|
268 | mutableContent?: boolean;
|
269 | /**
|
270 | * Type of the notification.
|
271 | */
|
272 | category?: string;
|
273 | /**
|
274 | * An app-specific identifier for grouping notifications.
|
275 | */
|
276 | threadId?: string;
|
277 | [customData: string]: any;
|
278 | }
|
279 | export interface ApsAlert {
|
280 | title?: string;
|
281 | subtitle?: string;
|
282 | body?: string;
|
283 | locKey?: string;
|
284 | locArgs?: string[];
|
285 | titleLocKey?: string;
|
286 | titleLocArgs?: string[];
|
287 | subtitleLocKey?: string;
|
288 | subtitleLocArgs?: string[];
|
289 | actionLocKey?: string;
|
290 | launchImage?: string;
|
291 | }
|
292 | /**
|
293 | * Represents a critical sound configuration that can be included in the
|
294 | * `aps` dictionary of an APNs payload.
|
295 | */
|
296 | export interface CriticalSound {
|
297 | /**
|
298 | * The critical alert flag. Set to `true` to enable the critical alert.
|
299 | */
|
300 | critical?: boolean;
|
301 | /**
|
302 | * The name of a sound file in the app's main bundle or in the `Library/Sounds`
|
303 | * folder of the app's container directory. Specify the string "default" to play
|
304 | * the system sound.
|
305 | */
|
306 | name: string;
|
307 | /**
|
308 | * The volume for the critical alert's sound. Must be a value between 0.0
|
309 | * (silent) and 1.0 (full volume).
|
310 | */
|
311 | volume?: number;
|
312 | }
|
313 | /**
|
314 | * Represents options for features provided by the FCM SDK for iOS.
|
315 | */
|
316 | export interface ApnsFcmOptions {
|
317 | /**
|
318 | * The label associated with the message's analytics data.
|
319 | */
|
320 | analyticsLabel?: string;
|
321 | /**
|
322 | * URL of an image to be displayed in the notification.
|
323 | */
|
324 | imageUrl?: string;
|
325 | }
|
326 | /**
|
327 | * Represents the Android-specific options that can be included in an
|
328 | * {@link Message}.
|
329 | */
|
330 | export interface AndroidConfig {
|
331 | /**
|
332 | * Collapse key for the message. Collapse key serves as an identifier for a
|
333 | * group of messages that can be collapsed, so that only the last message gets
|
334 | * sent when delivery can be resumed. A maximum of four different collapse keys
|
335 | * may be active at any given time.
|
336 | */
|
337 | collapseKey?: string;
|
338 | /**
|
339 | * Priority of the message. Must be either `normal` or `high`.
|
340 | */
|
341 | priority?: ('high' | 'normal');
|
342 | /**
|
343 | * Time-to-live duration of the message in milliseconds.
|
344 | */
|
345 | ttl?: number;
|
346 | /**
|
347 | * Package name of the application where the registration tokens must match
|
348 | * in order to receive the message.
|
349 | */
|
350 | restrictedPackageName?: string;
|
351 | /**
|
352 | * A collection of data fields to be included in the message. All values must
|
353 | * be strings. When provided, overrides any data fields set on the top-level
|
354 | * {@link Message}.
|
355 | */
|
356 | data?: {
|
357 | [key: string]: string;
|
358 | };
|
359 | /**
|
360 | * Android notification to be included in the message.
|
361 | */
|
362 | notification?: AndroidNotification;
|
363 | /**
|
364 | * Options for features provided by the FCM SDK for Android.
|
365 | */
|
366 | fcmOptions?: AndroidFcmOptions;
|
367 | }
|
368 | /**
|
369 | * Represents the Android-specific notification options that can be included in
|
370 | * {@link AndroidConfig}.
|
371 | */
|
372 | export interface AndroidNotification {
|
373 | /**
|
374 | * Title of the Android notification. When provided, overrides the title set via
|
375 | * `admin.messaging.Notification`.
|
376 | */
|
377 | title?: string;
|
378 | /**
|
379 | * Body of the Android notification. When provided, overrides the body set via
|
380 | * `admin.messaging.Notification`.
|
381 | */
|
382 | body?: string;
|
383 | /**
|
384 | * Icon resource for the Android notification.
|
385 | */
|
386 | icon?: string;
|
387 | /**
|
388 | * Notification icon color in `#rrggbb` format.
|
389 | */
|
390 | color?: string;
|
391 | /**
|
392 | * File name of the sound to be played when the device receives the
|
393 | * notification.
|
394 | */
|
395 | sound?: string;
|
396 | /**
|
397 | * Notification tag. This is an identifier used to replace existing
|
398 | * notifications in the notification drawer. If not specified, each request
|
399 | * creates a new notification.
|
400 | */
|
401 | tag?: string;
|
402 | /**
|
403 | * URL of an image to be displayed in the notification.
|
404 | */
|
405 | imageUrl?: string;
|
406 | /**
|
407 | * Action associated with a user click on the notification. If specified, an
|
408 | * activity with a matching Intent Filter is launched when a user clicks on the
|
409 | * notification.
|
410 | */
|
411 | clickAction?: string;
|
412 | /**
|
413 | * Key of the body string in the app's string resource to use to localize the
|
414 | * body text.
|
415 | *
|
416 | */
|
417 | bodyLocKey?: string;
|
418 | /**
|
419 | * An array of resource keys that will be used in place of the format
|
420 | * specifiers in `bodyLocKey`.
|
421 | */
|
422 | bodyLocArgs?: string[];
|
423 | /**
|
424 | * Key of the title string in the app's string resource to use to localize the
|
425 | * title text.
|
426 | */
|
427 | titleLocKey?: string;
|
428 | /**
|
429 | * An array of resource keys that will be used in place of the format
|
430 | * specifiers in `titleLocKey`.
|
431 | */
|
432 | titleLocArgs?: string[];
|
433 | /**
|
434 | * The Android notification channel ID (new in Android O). The app must create
|
435 | * a channel with this channel ID before any notification with this channel ID
|
436 | * can be received. If you don't send this channel ID in the request, or if the
|
437 | * channel ID provided has not yet been created by the app, FCM uses the channel
|
438 | * ID specified in the app manifest.
|
439 | */
|
440 | channelId?: string;
|
441 | /**
|
442 | * Sets the "ticker" text, which is sent to accessibility services. Prior to
|
443 | * API level 21 (Lollipop), sets the text that is displayed in the status bar
|
444 | * when the notification first arrives.
|
445 | */
|
446 | ticker?: string;
|
447 | /**
|
448 | * When set to `false` or unset, the notification is automatically dismissed when
|
449 | * the user clicks it in the panel. When set to `true`, the notification persists
|
450 | * even when the user clicks it.
|
451 | */
|
452 | sticky?: boolean;
|
453 | /**
|
454 | * For notifications that inform users about events with an absolute time reference, sets
|
455 | * the time that the event in the notification occurred. Notifications
|
456 | * in the panel are sorted by this time.
|
457 | */
|
458 | eventTimestamp?: Date;
|
459 | /**
|
460 | * Sets whether or not this notification is relevant only to the current device.
|
461 | * Some notifications can be bridged to other devices for remote display, such as
|
462 | * a Wear OS watch. This hint can be set to recommend this notification not be bridged.
|
463 | * See {@link https://developer.android.com/training/wearables/notifications/bridger#existing-method-of-preventing-bridging |
|
464 | * Wear OS guides}.
|
465 | */
|
466 | localOnly?: boolean;
|
467 | /**
|
468 | * Sets the relative priority for this notification. Low-priority notifications
|
469 | * may be hidden from the user in certain situations. Note this priority differs
|
470 | * from `AndroidMessagePriority`. This priority is processed by the client after
|
471 | * the message has been delivered. Whereas `AndroidMessagePriority` is an FCM concept
|
472 | * that controls when the message is delivered.
|
473 | */
|
474 | priority?: ('min' | 'low' | 'default' | 'high' | 'max');
|
475 | /**
|
476 | * Sets the vibration pattern to use. Pass in an array of milliseconds to
|
477 | * turn the vibrator on or off. The first value indicates the duration to wait before
|
478 | * turning the vibrator on. The next value indicates the duration to keep the
|
479 | * vibrator on. Subsequent values alternate between duration to turn the vibrator
|
480 | * off and to turn the vibrator on. If `vibrate_timings` is set and `default_vibrate_timings`
|
481 | * is set to `true`, the default value is used instead of the user-specified `vibrate_timings`.
|
482 | */
|
483 | vibrateTimingsMillis?: number[];
|
484 | /**
|
485 | * If set to `true`, use the Android framework's default vibrate pattern for the
|
486 | * notification. Default values are specified in {@link https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/config.xml |
|
487 | * config.xml}. If `default_vibrate_timings` is set to `true` and `vibrate_timings` is also set,
|
488 | * the default value is used instead of the user-specified `vibrate_timings`.
|
489 | */
|
490 | defaultVibrateTimings?: boolean;
|
491 | /**
|
492 | * If set to `true`, use the Android framework's default sound for the notification.
|
493 | * Default values are specified in {@link https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/config.xml |
|
494 | * config.xml}.
|
495 | */
|
496 | defaultSound?: boolean;
|
497 | /**
|
498 | * Settings to control the notification's LED blinking rate and color if LED is
|
499 | * available on the device. The total blinking time is controlled by the OS.
|
500 | */
|
501 | lightSettings?: LightSettings;
|
502 | /**
|
503 | * If set to `true`, use the Android framework's default LED light settings
|
504 | * for the notification. Default values are specified in {@link https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/config.xml |
|
505 | * config.xml}.
|
506 | * If `default_light_settings` is set to `true` and `light_settings` is also set,
|
507 | * the user-specified `light_settings` is used instead of the default value.
|
508 | */
|
509 | defaultLightSettings?: boolean;
|
510 | /**
|
511 | * Sets the visibility of the notification. Must be either `private`, `public`,
|
512 | * or `secret`. If unspecified, defaults to `private`.
|
513 | */
|
514 | visibility?: ('private' | 'public' | 'secret');
|
515 | /**
|
516 | * Sets the number of items this notification represents. May be displayed as a
|
517 | * badge count for Launchers that support badging. See {@link https://developer.android.com/training/notify-user/badges |
|
518 | * NotificationBadge}.
|
519 | * For example, this might be useful if you're using just one notification to
|
520 | * represent multiple new messages but you want the count here to represent
|
521 | * the number of total new messages. If zero or unspecified, systems
|
522 | * that support badging use the default, which is to increment a number
|
523 | * displayed on the long-press menu each time a new notification arrives.
|
524 | */
|
525 | notificationCount?: number;
|
526 | }
|
527 | /**
|
528 | * Represents settings to control notification LED that can be included in
|
529 | * {@link AndroidNotification}.
|
530 | */
|
531 | export interface LightSettings {
|
532 | /**
|
533 | * Required. Sets color of the LED in `#rrggbb` or `#rrggbbaa` format.
|
534 | */
|
535 | color: string;
|
536 | /**
|
537 | * Required. Along with `light_off_duration`, defines the blink rate of LED flashes.
|
538 | */
|
539 | lightOnDurationMillis: number;
|
540 | /**
|
541 | * Required. Along with `light_on_duration`, defines the blink rate of LED flashes.
|
542 | */
|
543 | lightOffDurationMillis: number;
|
544 | }
|
545 | /**
|
546 | * Represents options for features provided by the FCM SDK for Android.
|
547 | */
|
548 | export interface AndroidFcmOptions {
|
549 | /**
|
550 | * The label associated with the message's analytics data.
|
551 | */
|
552 | analyticsLabel?: string;
|
553 | }
|
554 | /**
|
555 | * Interface representing an FCM legacy API data message payload. Data
|
556 | * messages let developers send up to 4KB of custom key-value pairs. The
|
557 | * keys and values must both be strings. Keys can be any custom string,
|
558 | * except for the following reserved strings:
|
559 | *
|
560 | * <ul>
|
561 | * <li><code>from</code></li>
|
562 | * <li>Anything starting with <code>google.</code></li>
|
563 | * </ul>
|
564 | *
|
565 | * See {@link https://firebase.google.com/docs/cloud-messaging/send-message | Build send requests}
|
566 | * for code samples and detailed documentation.
|
567 | */
|
568 | export interface DataMessagePayload {
|
569 | [key: string]: string;
|
570 | }
|
571 | /**
|
572 | * Interface representing an FCM legacy API notification message payload.
|
573 | * Notification messages let developers send up to 4KB of predefined
|
574 | * key-value pairs. Accepted keys are outlined below.
|
575 | *
|
576 | * See {@link https://firebase.google.com/docs/cloud-messaging/send-message | Build send requests}
|
577 | * for code samples and detailed documentation.
|
578 | */
|
579 | export interface NotificationMessagePayload {
|
580 | /**
|
581 | * Identifier used to replace existing notifications in the notification drawer.
|
582 | *
|
583 | * If not specified, each request creates a new notification.
|
584 | *
|
585 | * If specified and a notification with the same tag is already being shown,
|
586 | * the new notification replaces the existing one in the notification drawer.
|
587 | *
|
588 | * **Platforms:** Android
|
589 | */
|
590 | tag?: string;
|
591 | /**
|
592 | * The notification's body text.
|
593 | *
|
594 | * **Platforms:** iOS, Android, Web
|
595 | */
|
596 | body?: string;
|
597 | /**
|
598 | * The notification's icon.
|
599 | *
|
600 | * **Android:** Sets the notification icon to `myicon` for drawable resource
|
601 | * `myicon`. If you don't send this key in the request, FCM displays the
|
602 | * launcher icon specified in your app manifest.
|
603 | *
|
604 | * **Web:** The URL to use for the notification's icon.
|
605 | *
|
606 | * **Platforms:** Android, Web
|
607 | */
|
608 | icon?: string;
|
609 | /**
|
610 | * The value of the badge on the home screen app icon.
|
611 | *
|
612 | * If not specified, the badge is not changed.
|
613 | *
|
614 | * If set to `0`, the badge is removed.
|
615 | *
|
616 | * **Platforms:** iOS
|
617 | */
|
618 | badge?: string;
|
619 | /**
|
620 | * The notification icon's color, expressed in `#rrggbb` format.
|
621 | *
|
622 | * **Platforms:** Android
|
623 | */
|
624 | color?: string;
|
625 | /**
|
626 | * The sound to be played when the device receives a notification. Supports
|
627 | * "default" for the default notification sound of the device or the filename of a
|
628 | * sound resource bundled in the app.
|
629 | * Sound files must reside in `/res/raw/`.
|
630 | *
|
631 | * **Platforms:** Android
|
632 | */
|
633 | sound?: string;
|
634 | /**
|
635 | * The notification's title.
|
636 | *
|
637 | * **Platforms:** iOS, Android, Web
|
638 | */
|
639 | title?: string;
|
640 | /**
|
641 | * The key to the body string in the app's string resources to use to localize
|
642 | * the body text to the user's current localization.
|
643 | *
|
644 | * **iOS:** Corresponds to `loc-key` in the APNs payload. See
|
645 | * {@link https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html |
|
646 | * Payload Key Reference} and
|
647 | * {@link https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW9 |
|
648 | * Localizing the Content of Your Remote Notifications} for more information.
|
649 | *
|
650 | * **Android:** See
|
651 | * {@link http://developer.android.com/guide/topics/resources/string-resource.html | String Resources}
|
652 | * for more information.
|
653 | *
|
654 | * **Platforms:** iOS, Android
|
655 | */
|
656 | bodyLocKey?: string;
|
657 | /**
|
658 | * Variable string values to be used in place of the format specifiers in
|
659 | * `body_loc_key` to use to localize the body text to the user's current
|
660 | * localization.
|
661 | *
|
662 | * The value should be a stringified JSON array.
|
663 | *
|
664 | * **iOS:** Corresponds to `loc-args` in the APNs payload. See
|
665 | * {@link https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html |
|
666 | * Payload Key Reference} and
|
667 | * {@link https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW9 |
|
668 | * Localizing the Content of Your Remote Notifications} for more information.
|
669 | *
|
670 | * **Android:** See
|
671 | * {@link http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling |
|
672 | * Formatting and Styling} for more information.
|
673 | *
|
674 | * **Platforms:** iOS, Android
|
675 | */
|
676 | bodyLocArgs?: string;
|
677 | /**
|
678 | * Action associated with a user click on the notification. If specified, an
|
679 | * activity with a matching Intent Filter is launched when a user clicks on the
|
680 | * notification.
|
681 | *
|
682 | * * **Platforms:** Android
|
683 | */
|
684 | clickAction?: string;
|
685 | /**
|
686 | * The key to the title string in the app's string resources to use to localize
|
687 | * the title text to the user's current localization.
|
688 | *
|
689 | * **iOS:** Corresponds to `title-loc-key` in the APNs payload. See
|
690 | * {@link https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html |
|
691 | * Payload Key Reference} and
|
692 | * {@link https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW9 |
|
693 | * Localizing the Content of Your Remote Notifications} for more information.
|
694 | *
|
695 | * **Android:** See
|
696 | * {@link http://developer.android.com/guide/topics/resources/string-resource.html | String Resources}
|
697 | * for more information.
|
698 | *
|
699 | * **Platforms:** iOS, Android
|
700 | */
|
701 | titleLocKey?: string;
|
702 | /**
|
703 | * Variable string values to be used in place of the format specifiers in
|
704 | * `title_loc_key` to use to localize the title text to the user's current
|
705 | * localization.
|
706 | *
|
707 | * The value should be a stringified JSON array.
|
708 | *
|
709 | * **iOS:** Corresponds to `title-loc-args` in the APNs payload. See
|
710 | * {@link https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html |
|
711 | * Payload Key Reference} and
|
712 | * {@link https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW9 |
|
713 | * Localizing the Content of Your Remote Notifications} for more information.
|
714 | *
|
715 | * **Android:** See
|
716 | * {@link http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling |
|
717 | * Formatting and Styling} for more information.
|
718 | *
|
719 | * **Platforms:** iOS, Android
|
720 | */
|
721 | titleLocArgs?: string;
|
722 | [key: string]: string | undefined;
|
723 | }
|
724 | /**
|
725 | * Interface representing a Firebase Cloud Messaging message payload. One or
|
726 | * both of the `data` and `notification` keys are required.
|
727 | *
|
728 | * See {@link https://firebase.google.com/docs/cloud-messaging/send-message | Build send requests}
|
729 | * for code samples and detailed documentation.
|
730 | */
|
731 | export interface MessagingPayload {
|
732 | /**
|
733 | * The data message payload.
|
734 | */
|
735 | data?: DataMessagePayload;
|
736 | /**
|
737 | * The notification message payload.
|
738 | */
|
739 | notification?: NotificationMessagePayload;
|
740 | }
|
741 | /**
|
742 | * Interface representing the options that can be provided when sending a
|
743 | * message via the FCM legacy APIs.
|
744 | *
|
745 | * See {@link https://firebase.google.com/docs/cloud-messaging/send-message | Build send requests}
|
746 | * for code samples and detailed documentation.
|
747 | */
|
748 | export interface MessagingOptions {
|
749 | /**
|
750 | * Whether or not the message should actually be sent. When set to `true`,
|
751 | * allows developers to test a request without actually sending a message. When
|
752 | * set to `false`, the message will be sent.
|
753 | *
|
754 | * **Default value:** `false`
|
755 | */
|
756 | dryRun?: boolean;
|
757 | /**
|
758 | * The priority of the message. Valid values are `"normal"` and `"high".` On
|
759 | * iOS, these correspond to APNs priorities `5` and `10`.
|
760 | *
|
761 | * By default, notification messages are sent with high priority, and data
|
762 | * messages are sent with normal priority. Normal priority optimizes the client
|
763 | * app's battery consumption and should be used unless immediate delivery is
|
764 | * required. For messages with normal priority, the app may receive the message
|
765 | * with unspecified delay.
|
766 | *
|
767 | * When a message is sent with high priority, it is sent immediately, and the
|
768 | * app can wake a sleeping device and open a network connection to your server.
|
769 | *
|
770 | * For more information, see
|
771 | * {@link https://firebase.google.com/docs/cloud-messaging/concept-options#setting-the-priority-of-a-message |
|
772 | * Setting the priority of a message}.
|
773 | *
|
774 | * **Default value:** `"high"` for notification messages, `"normal"` for data
|
775 | * messages
|
776 | */
|
777 | priority?: string;
|
778 | /**
|
779 | * How long (in seconds) the message should be kept in FCM storage if the device
|
780 | * is offline. The maximum time to live supported is four weeks, and the default
|
781 | * value is also four weeks. For more information, see
|
782 | * {@link https://firebase.google.com/docs/cloud-messaging/concept-options#ttl | Setting the lifespan of a message}.
|
783 | *
|
784 | * **Default value:** `2419200` (representing four weeks, in seconds)
|
785 | */
|
786 | timeToLive?: number;
|
787 | /**
|
788 | * String identifying a group of messages (for example, "Updates Available")
|
789 | * that can be collapsed, so that only the last message gets sent when delivery
|
790 | * can be resumed. This is used to avoid sending too many of the same messages
|
791 | * when the device comes back online or becomes active.
|
792 | *
|
793 | * There is no guarantee of the order in which messages get sent.
|
794 | *
|
795 | * A maximum of four different collapse keys is allowed at any given time. This
|
796 | * means FCM server can simultaneously store four different
|
797 | * send-to-sync messages per client app. If you exceed this number, there is no
|
798 | * guarantee which four collapse keys the FCM server will keep.
|
799 | *
|
800 | * **Default value:** None
|
801 | */
|
802 | collapseKey?: string;
|
803 | /**
|
804 | * On iOS, use this field to represent `mutable-content` in the APNs payload.
|
805 | * When a notification is sent and this is set to `true`, the content of the
|
806 | * notification can be modified before it is displayed, using a
|
807 | * {@link https://developer.apple.com/reference/usernotifications/unnotificationserviceextension |
|
808 | * Notification Service app extension}.
|
809 | *
|
810 | * On Android and Web, this parameter will be ignored.
|
811 | *
|
812 | * **Default value:** `false`
|
813 | */
|
814 | mutableContent?: boolean;
|
815 | /**
|
816 | * On iOS, use this field to represent `content-available` in the APNs payload.
|
817 | * When a notification or data message is sent and this is set to `true`, an
|
818 | * inactive client app is awoken. On Android, data messages wake the app by
|
819 | * default. On Chrome, this flag is currently not supported.
|
820 | *
|
821 | * **Default value:** `false`
|
822 | */
|
823 | contentAvailable?: boolean;
|
824 | /**
|
825 | * The package name of the application which the registration tokens must match
|
826 | * in order to receive the message.
|
827 | *
|
828 | * **Default value:** None
|
829 | */
|
830 | restrictedPackageName?: string;
|
831 | [key: string]: any | undefined;
|
832 | }
|
833 | /**
|
834 | * Individual status response payload from single devices
|
835 | *
|
836 | * @deprecated Returned by {@link Messaging#sendToDevice}, which is also deprecated.
|
837 | */
|
838 | export interface MessagingDeviceResult {
|
839 | /**
|
840 | * The error that occurred when processing the message for the recipient.
|
841 | */
|
842 | error?: FirebaseError;
|
843 | /**
|
844 | * A unique ID for the successfully processed message.
|
845 | */
|
846 | messageId?: string;
|
847 | /**
|
848 | * The canonical registration token for the client app that the message was
|
849 | * processed and sent to. You should use this value as the registration token
|
850 | * for future requests. Otherwise, future messages might be rejected.
|
851 | */
|
852 | canonicalRegistrationToken?: string;
|
853 | }
|
854 | /**
|
855 | * Interface representing the status of a message sent to an individual device
|
856 | * via the FCM legacy APIs.
|
857 | *
|
858 | * See
|
859 | * {@link https://firebase.google.com/docs/cloud-messaging/admin/send-messages#send_to_individual_devices |
|
860 | * Send to individual devices} for code samples and detailed documentation.
|
861 | *
|
862 | * @deprecated Returned by {@link Messaging.sendToDevice}, which is also deprecated.
|
863 | */
|
864 | export interface MessagingDevicesResponse {
|
865 | canonicalRegistrationTokenCount: number;
|
866 | failureCount: number;
|
867 | multicastId: number;
|
868 | results: MessagingDeviceResult[];
|
869 | successCount: number;
|
870 | }
|
871 | /**
|
872 | * Interface representing the server response from the {@link Messaging.sendToDeviceGroup}
|
873 | * method.
|
874 | *
|
875 | * See
|
876 | * {@link https://firebase.google.com/docs/cloud-messaging/send-message?authuser=0#send_messages_to_device_groups |
|
877 | * Send messages to device groups} for code samples and detailed documentation.
|
878 | *
|
879 | * @deprecated Returned by {@link Messaging.sendToDeviceGroup}, which is also deprecated.
|
880 | */
|
881 | export interface MessagingDeviceGroupResponse {
|
882 | /**
|
883 | * The number of messages that could not be processed and resulted in an error.
|
884 | */
|
885 | successCount: number;
|
886 | /**
|
887 | * The number of messages that could not be processed and resulted in an error.
|
888 | */
|
889 | failureCount: number;
|
890 | /**
|
891 | * An array of registration tokens that failed to receive the message.
|
892 | */
|
893 | failedRegistrationTokens: string[];
|
894 | }
|
895 | /**
|
896 | * Interface representing the server response from the legacy {@link Messaging.sendToTopic} method.
|
897 | *
|
898 | * See
|
899 | * {@link https://firebase.google.com/docs/cloud-messaging/admin/send-messages#send_to_a_topic |
|
900 | * Send to a topic} for code samples and detailed documentation.
|
901 | */
|
902 | export interface MessagingTopicResponse {
|
903 | /**
|
904 | * The message ID for a successfully received request which FCM will attempt to
|
905 | * deliver to all subscribed devices.
|
906 | */
|
907 | messageId: number;
|
908 | }
|
909 | /**
|
910 | * Interface representing the server response from the legacy
|
911 | * {@link Messaging.sendToCondition} method.
|
912 | *
|
913 | * See
|
914 | * {@link https://firebase.google.com/docs/cloud-messaging/admin/send-messages#send_to_a_condition |
|
915 | * Send to a condition} for code samples and detailed documentation.
|
916 | */
|
917 | export interface MessagingConditionResponse {
|
918 | /**
|
919 | * The message ID for a successfully received request which FCM will attempt to
|
920 | * deliver to all subscribed devices.
|
921 | */
|
922 | messageId: number;
|
923 | }
|
924 | /**
|
925 | * Interface representing the server response from the
|
926 | * {@link Messaging.subscribeToTopic} and {@link Messaging.unsubscribeFromTopic}
|
927 | * methods.
|
928 | *
|
929 | * See
|
930 | * {@link https://firebase.google.com/docs/cloud-messaging/manage-topics |
|
931 | * Manage topics from the server} for code samples and detailed documentation.
|
932 | */
|
933 | export interface MessagingTopicManagementResponse {
|
934 | /**
|
935 | * The number of registration tokens that could not be subscribed to the topic
|
936 | * and resulted in an error.
|
937 | */
|
938 | failureCount: number;
|
939 | /**
|
940 | * The number of registration tokens that were successfully subscribed to the
|
941 | * topic.
|
942 | */
|
943 | successCount: number;
|
944 | /**
|
945 | * An array of errors corresponding to the provided registration token(s). The
|
946 | * length of this array will be equal to {@link MessagingTopicManagementResponse.failureCount}.
|
947 | */
|
948 | errors: FirebaseArrayIndexError[];
|
949 | }
|
950 | /**
|
951 | * Interface representing the server response from the
|
952 | * {@link Messaging.sendAll} and {@link Messaging.sendMulticast} methods.
|
953 | */
|
954 | export interface BatchResponse {
|
955 | /**
|
956 | * An array of responses, each corresponding to a message.
|
957 | */
|
958 | responses: SendResponse[];
|
959 | /**
|
960 | * The number of messages that were successfully handed off for sending.
|
961 | */
|
962 | successCount: number;
|
963 | /**
|
964 | * The number of messages that resulted in errors when sending.
|
965 | */
|
966 | failureCount: number;
|
967 | }
|
968 | /**
|
969 | * Interface representing the status of an individual message that was sent as
|
970 | * part of a batch request.
|
971 | */
|
972 | export interface SendResponse {
|
973 | /**
|
974 | * A boolean indicating if the message was successfully handed off to FCM or
|
975 | * not. When true, the `messageId` attribute is guaranteed to be set. When
|
976 | * false, the `error` attribute is guaranteed to be set.
|
977 | */
|
978 | success: boolean;
|
979 | /**
|
980 | * A unique message ID string, if the message was handed off to FCM for
|
981 | * delivery.
|
982 | *
|
983 | */
|
984 | messageId?: string;
|
985 | /**
|
986 | * An error, if the message was not handed off to FCM successfully.
|
987 | */
|
988 | error?: FirebaseError;
|
989 | }
|