Pigeon v1.1.1 Pigeon.FCM.Notification View Source
Defines FCM notification struct and convenience constructor functions.
Link to this section Summary
Functions
Creates FCM.Notification
struct with device registration IDs and optional
notification and data payloads
Updates "data"
key in push payload
Updates "notification"
key in push payload
Updates "priority"
key
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
regid_error_response :: :device_essage_rate_exceeded | :invalid_data_key | :invalid_package_name | :invalid_paramteres | :invalid_registration | :invalid_ttl | :message_too_big | :missing_registration | :mismatch_sender_id | :not_registered | :topics_message_rate_exceeded | :unavailable
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
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
t() :: %Pigeon.FCM.Notification{message_id: nil | String.t, payload: %{}, priority: :normal | :high, registration_id: String.t | [String.t], response: [] | [regid_response, ...], status: status | nil}
Link to this section Functions
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
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
}
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}
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"}]