Pigeon.FCM.Notification (Pigeon v2.1.0)

View Source

Defines FCM notification struct and convenience constructor functions.

Summary

Types

FCM error response

FCM push response

t()

FCM notification target. Must be one of the following

Functions

Creates FCM.Notification struct with given target and optional notification and data payloads.

Types

error_response()

@type error_response() ::
  :internal
  | :invalid_argument
  | :permission_denied
  | :quota_exceeded
  | :sender_id_mismatch
  | :third_party_auth_error
  | :unauthenticated
  | :unavailable
  | :unknown_error
  | :unregistered
  | :unspecified_error

FCM error response

Most map to the errorCode in the FCM v1 error details. :permission_denied and :unauthenticated come from the gRPC status when FCM rejects the service account itself. :unknown_error covers anything unrecognized.

response()

@type response() ::
  error_response() | nil | :not_connected | :not_started | :success | :timeout

FCM push response

  • error_response/0 - Push attempted but server responded with error. See :error for details.
  • nil - Push has not been sent yet.
  • :not_connected - Dispatcher had no live connection to FCM. Push was not sent.
  • :not_started - Dispatcher is not running. Push was not sent.
  • :success - Push was successfully sent.
  • :timeout - Push was sent but the connection dropped before FCM responded. Delivery is unknown.

t()

@type t() :: %Pigeon.FCM.Notification{
  __meta__: Pigeon.Metadata.t(),
  android: map() | nil,
  apns: map() | nil,
  data: map() | nil,
  error: map() | nil,
  fcm_options: map() | nil,
  name: binary() | nil,
  notification: map() | nil,
  response: response(),
  target: target(),
  validate_only: boolean() | nil,
  webpush: map() | nil
}

target()

@type target() ::
  {:token, binary()}
  | {:fid, binary()}
  | {:topic, binary()}
  | {:condition, binary()}

FCM notification target. Must be one of the following:

  • {:token, "string"} - Registration token to send a message to. Being deprecated by Firebase in favour of fid.
  • {:fid, "string"} - Firebase Installation ID to send a message to.
  • {:topic, "string"} - Topic name to send a message to, e.g. "weather". Note: "/topics/" prefix should not be provided.
  • {:condition, "string"} - Condition to send a message to, e.g. "'foo' in topics && 'bar' in topics".

Functions

new(target, notification \\ nil, data \\ nil)

Creates FCM.Notification struct with given target and optional notification and data payloads.

Examples

iex> Pigeon.FCM.Notification.new({:token, "reg ID"})
%Pigeon.FCM.Notification{
  data: nil,
  notification: nil,
  target: {:token, "reg ID"}
}

iex> Pigeon.FCM.Notification.new({:topic, "example"})
%Pigeon.FCM.Notification{
  data: nil,
  notification: nil,
  target: {:topic, "example"}
}

iex> Pigeon.FCM.Notification.new({:token, "reg ID"}, %{"body" => "test message"})
%Pigeon.FCM.Notification{
  data: nil,
  notification: %{"body" => "test message"},
  target: {:token, "reg ID"}
}

iex> Pigeon.FCM.Notification.new({:token, "reg ID"}, %{"body" => "test message"},
...> %{"key" => "value"})
%Pigeon.FCM.Notification{
  data: %{"key" => "value"},
  notification: %{"body" => "test message"},
  target: {:token, "reg ID"}
}