function validateAndroidNotification()

in src/messaging/messaging-internal.ts [412:503]


function validateAndroidNotification(notification: AndroidNotification | undefined): void {
  if (typeof notification === 'undefined') {
    return;
  } else if (!validator.isNonNullObject(notification)) {
    throw new FirebaseMessagingError(
      MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification must be a non-null object');
  }

  if (typeof notification.color !== 'undefined' && !/^#[0-9a-fA-F]{6}$/.test(notification.color)) {
    throw new FirebaseMessagingError(
      MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification.color must be in the form #RRGGBB');
  }
  if (validator.isNonEmptyArray(notification.bodyLocArgs) &&
    !validator.isNonEmptyString(notification.bodyLocKey)) {
    throw new FirebaseMessagingError(
      MessagingClientErrorCode.INVALID_PAYLOAD,
      'android.notification.bodyLocKey is required when specifying bodyLocArgs');
  }
  if (validator.isNonEmptyArray(notification.titleLocArgs) &&
    !validator.isNonEmptyString(notification.titleLocKey)) {
    throw new FirebaseMessagingError(
      MessagingClientErrorCode.INVALID_PAYLOAD,
      'android.notification.titleLocKey is required when specifying titleLocArgs');
  }
  if (typeof notification.imageUrl !== 'undefined' &&
    !validator.isURL(notification.imageUrl)) {
    throw new FirebaseMessagingError(
      MessagingClientErrorCode.INVALID_PAYLOAD,
      'android.notification.imageUrl must be a valid URL string');
  }

  if (typeof notification.eventTimestamp !== 'undefined') {
    if (!(notification.eventTimestamp instanceof Date)) {
      throw new FirebaseMessagingError(
        MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification.eventTimestamp must be a valid `Date` object');
    }
    // Convert timestamp to RFC3339 UTC "Zulu" format, example "2014-10-02T15:01:23.045123456Z"
    const zuluTimestamp = notification.eventTimestamp.toISOString();
    (notification as any).eventTimestamp = zuluTimestamp;
  }

  if (typeof notification.vibrateTimingsMillis !== 'undefined') {
    if (!validator.isNonEmptyArray(notification.vibrateTimingsMillis)) {
      throw new FirebaseMessagingError(
        MessagingClientErrorCode.INVALID_PAYLOAD,
        'android.notification.vibrateTimingsMillis must be a non-empty array of numbers');
    }
    const vibrateTimings: string[] = [];
    notification.vibrateTimingsMillis.forEach((value) => {
      if (!validator.isNumber(value) || value < 0) {
        throw new FirebaseMessagingError(
          MessagingClientErrorCode.INVALID_PAYLOAD,
          'android.notification.vibrateTimingsMillis must be non-negative durations in milliseconds');
      }
      const duration = transformMillisecondsToSecondsString(value);
      vibrateTimings.push(duration);
    });
    (notification as any).vibrateTimingsMillis = vibrateTimings;
  }

  if (typeof notification.priority !== 'undefined') {
    const priority = 'PRIORITY_' + notification.priority.toUpperCase();
    (notification as any).priority = priority;
  }

  if (typeof notification.visibility !== 'undefined') {
    const visibility = notification.visibility.toUpperCase();
    (notification as any).visibility = visibility;
  }

  validateLightSettings(notification.lightSettings);

  const propertyMappings = {
    clickAction: 'click_action',
    bodyLocKey: 'body_loc_key',
    bodyLocArgs: 'body_loc_args',
    titleLocKey: 'title_loc_key',
    titleLocArgs: 'title_loc_args',
    channelId: 'channel_id',
    imageUrl: 'image',
    eventTimestamp: 'event_time',
    localOnly: 'local_only',
    priority: 'notification_priority',
    vibrateTimingsMillis: 'vibrate_timings',
    defaultVibrateTimings: 'default_vibrate_timings',
    defaultSound: 'default_sound',
    lightSettings: 'light_settings',
    defaultLightSettings: 'default_light_settings',
    notificationCount: 'notification_count',
  };
  renameProperties(notification, propertyMappings);
}