Pigeon v1.1.0-rc.0 Pigeon.FCM View Source
Firebase Cloud Messaging (FCM)
Link to this section Summary
Functions
Sends a push over FCM
Starts FCM worker connection with given config or name
Stops existing FCM worker connection
Link to this section Types
Link to this type
on_response()
View Source
on_response() :: (Pigeon.FCM.Notification.t -> no_return)
Async callback for push notification response.
Examples
handler = fn(n) ->
case n.status do
:success ->
bad_regids = FCM.Notification.remove?(n)
to_retry = FCM.Notification.retry?(n)
# Handle updated regids, remove bad ones, etc
:unauthorized ->
# Bad FCM key
error ->
# Some other error
end
end
n = Pigeon.FCM.Notification.new(“device token”, %{}, %{“message” => “test”}) Pigeon.FCM.push(n, on_response: handler)
Link to this type
push_opts()
View Source
push_opts() :: [to: atom | pid | nil, timeout: pos_integer | nil, on_response: on_response | nil]
Options for sending push notifications.
:to
- Defines worker to process push. Defaults to:fcm_default
:on_response
- Optional async callback triggered on receipt of push. Seeon_response/0
:timeout
- Specifies timeout for push responses. Useful if sending large batches synchronously.
Link to this section Functions
Link to this function
push(notification, opts \\ [])
View Source
push(Pigeon.FCM.Notification.t, Keyword.t) :: Pigeon.FCM.Notification.t
push([Pigeon.FCM.Notification.t, ...], Keyword.t) :: [Pigeon.FCM.Notification.t, ...]
Sends a push over FCM.
Examples
iex> n = Pigeon.FCM.Notification.new("regId", %{}, %{"message" => "123"})
iex> Pigeon.FCM.push(n)
%Pigeon.FCM.Notification{message_id: nil,
payload: %{"data" => %{"message" => "123"}}, priority: :normal,
registration_id: "regId", status: :success, response:
[invalid_registration: "regId"]}
iex> n = Pigeon.FCM.Notification.new("regId", %{}, %{"message" => "123"})
iex> Pigeon.FCM.push(n, on_response: nil)
:ok
iex> n = Pigeon.FCM.Notification.new(["regId", "regId"], %{},
...> %{"message" => "123"})
iex> Pigeon.FCM.push(n)
%Pigeon.FCM.Notification{message_id: nil,
payload: %{"data" => %{"message" => "123"}}, priority: :normal,
registration_id: ["regId", "regId"], status: :success,
response: [invalid_registration: "regId",
invalid_registration: "regId"]}
iex> n = Pigeon.FCM.Notification.new(["regId", "regId"], %{},
...> %{"message" => "test"})
iex> notifs = Pigeon.FCM.push([n, n])
iex> Enum.map(notifs, & &1.response)
[[invalid_registration: "regId", invalid_registration: "regId"],
[invalid_registration: "regId", invalid_registration: "regId"]]
Starts FCM worker connection with given config or name.
Examples
iex> config = Pigeon.FCM.Config.new(:fcm_default)
iex> {:ok, pid} = Pigeon.FCM.start_connection(%{config | name: nil})
iex> Process.alive?(pid)
true