Pigeon v1.2.3 Pigeon.FCM.Notification View Source

Defines FCM notification struct and convenience constructor functions.

Link to this section Summary

Types

FCM push response for individual registration IDs

Status of FCM request

t()

Functions

Creates FCM.Notification struct with device registration IDs and optional notification and data payloads

Updates "collapse_key" key

Updates "data" key in push payload

Sets "dry_run" key to true. Pushes will be processed but not actually delivered to the device

Updates "notification" key in push payload

Updates "priority" key

Updates "restricted_package_name" key

Updates "time_to_live" key. Time-to-live is measured in seconds

Returns a list of registration IDs that should be removed

Returns a list of registration IDs that should be retried

Returns a list of successful registration IDs

Returns a list of registration IDs and their corresponding new ID

Link to this section Types

Link to this type regid_error_response() View Source
regid_error_response() ::
  :device_message_rate_exceeded
  | :internal_server_error
  | :invalid_apns_credential
  | :invalid_data_key
  | :invalid_package_name
  | :invalid_parameters
  | :invalid_registration
  | :invalid_ttl
  | :message_too_big
  | :missing_registration
  | :mismatch_sender_id
  | :not_registered
  | :topics_message_rate_exceeded
  | :unavailable
  | :unknown_error
Link to this type regid_response() View Source
regid_response() ::
  {:success, binary()}
  | {regid_error_response(), binary()}
  | {:update, {binary(), binary()}}

FCM push response for individual registration IDs

  • {:success, "reg_id"} - Push was successfully sent
  • {:update, {"reg_id", "new_reg_id"}} - Push successful but user should use new registration ID for future pushes
  • {regid_error_response, "reg_id"} - Push attempted but server responded with error
Link to this type status() View Source
status() ::
  :success
  | :timeout
  | :unauthorized
  | :malformed_json
  | :internal_server_error
  | :unavailable

Status of FCM request

  • :success - Notification was processed successfully
  • :timeout - Worker did not respond within timeout. This is likely an internal error
  • :unauthorized - Bad FCM key
  • :malformed_json - Push payload was invalid JSON
  • :internal_server_error - FCM server encountered an error while trying to process the request
  • :unavailable - FCM server couldn’t process the request in time
Link to this type t() View Source
t() :: %Pigeon.FCM.Notification{
  collapse_key: nil | String.t(),
  dry_run: boolean(),
  message_id: nil | String.t(),
  payload: map(),
  priority: :normal | :high,
  registration_id: String.t() | [String.t()],
  response: [] | [regid_response(), ...],
  restricted_package_name: nil | String.t(),
  status: status() | nil,
  time_to_live: non_neg_integer()
}

Link to this section Functions

Link to this function new(registration_ids, notification \\ %{}, data \\ %{}) View Source

Creates FCM.Notification struct with device registration IDs and optional notification and data payloads.

Examples

iex> Pigeon.FCM.Notification.new("reg ID")
%Pigeon.FCM.Notification{
  payload: %{},
  registration_id: "reg ID",
  priority: :normal
}

iex> Pigeon.FCM.Notification.new("reg ID", %{"body" => "test message"})
%Pigeon.FCM.Notification{
  payload: %{"notification" => %{"body" => "test message"}},
  registration_id: "reg ID",
  priority: :normal
}

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

iex> regids = Enum.map(0..1_499, fn(_x) -> "reg ID" end)
iex> [n1 | [n2]] = Pigeon.FCM.Notification.new(regids,
...> %{"body" => "test message"}, %{"key" => "value"})
iex> Enum.count(n1.registration_id)
1000
iex> Enum.count(n2.registration_id)
500
Link to this function put_collapse_key(n, key) View Source

Updates "collapse_key" key.

Examples

iex> put_collapse_key(%Pigeon.FCM.Notification{}, "Updates available")
%Pigeon.FCM.Notification{collapse_key: "Updates available"}

Updates "data" key in push payload.

Examples

iex> put_data(%Pigeon.FCM.Notification{}, %{"key" => 1234})
%Pigeon.FCM.Notification{
  payload: %{"data" => %{"key" => 1234}},
  registration_id: nil
}

Sets "dry_run" key to true. Pushes will be processed but not actually delivered to the device.

Examples

iex> put_dry_run(%Pigeon.FCM.Notification{})
%Pigeon.FCM.Notification{dry_run: true}
Link to this function put_notification(n, notification) View Source

Updates "notification" key in push payload.

Examples

iex> put_notification(%Pigeon.FCM.Notification{},
...> %{"body" => "message"})
%Pigeon.FCM.Notification{
  payload: %{"notification" => %{"body" => "message"}},
  registration_id: nil
}

Updates "priority" key.

Examples

iex> put_priority(%Pigeon.FCM.Notification{}, :normal)
%Pigeon.FCM.Notification{priority: :normal}

iex> put_priority(%Pigeon.FCM.Notification{}, :high)
%Pigeon.FCM.Notification{priority: :high}

iex> put_priority(%Pigeon.FCM.Notification{priority: :normal}, :bad)
%Pigeon.FCM.Notification{priority: :normal}
Link to this function put_restricted_package_name(n, name) View Source

Updates "restricted_package_name" key.

Examples

iex> put_restricted_package_name(%Pigeon.FCM.Notification{}, "com.example.app")
%Pigeon.FCM.Notification{restricted_package_name: "com.example.app"}
Link to this function put_time_to_live(n, ttl) View Source

Updates "time_to_live" key. Time-to-live is measured in seconds.

Examples

iex> put_time_to_live(%Pigeon.FCM.Notification{}, 60 * 60 * 24)
%Pigeon.FCM.Notification{time_to_live: 86_400}

Returns a list of registration IDs that should be removed

Examples

iex> n = %Pigeon.FCM.Notification{response: [
...> {:success, "regid1"}, {:invalid_registration, "regid2"},
...> {:success, "regid3"}, {:update, {"regid4", "new_regid4"}},
...> {:not_registered, "regid5"}, {:unavailable, "regid6"}]}
iex> remove?(n)
["regid2", "regid5"]

Returns a list of registration IDs that should be retried

Examples

iex> n = %Pigeon.FCM.Notification{response: [
...> {:success, "regid1"}, {:invalid_registration, "regid2"},
...> {:success, "regid3"}, {:update, {"regid4", "new_regid4"}},
...> {:not_registered, "regid5"}, {:unavailable, "regid6"}]}
iex> retry?(n)
["regid6"]

Returns a list of successful registration IDs

Examples

iex> n = %Pigeon.FCM.Notification{response: [
...> {:success, "regid1"}, {:invalid_registration, "regid2"},
...> {:success, "regid3"}, {:update, {"regid4", "new_regid4"}},
...> {:not_registered, "regid5"}, {:unavailable, "regid6"}]}
iex> success?(n)
["regid1", "regid3"]

Returns a list of registration IDs and their corresponding new ID

Examples

iex> n = %Pigeon.FCM.Notification{response: [
...> {:success, "regid1"}, {:invalid_registration, "regid2"},
...> {:success, "regid3"}, {:update, {"regid4", "new_regid4"}},
...> {:not_registered, "regid5"}, {:unavailable, "regid6"}]}
iex> update?(n)
[{"regid4", "new_regid4"}]