tusker_push/lib/tusker_push/forwarder.ex

35 lines
784 B
Elixir
Raw Normal View History

2024-04-06 03:50:28 +00:00
defmodule TuskerPush.Forwarder do
alias TuskerPush.Apns
alias TuskerPush.Registration
require Logger
2024-04-09 02:20:03 +00:00
@spec forward(Registration.t(), binary(), String.t(), String.t(), String.t() | nil) ::
:ok | {:error, term()}
def forward(%Registration{push_version: 1} = registration, body, salt, key, context) do
2024-04-06 03:50:28 +00:00
payload = %{
"aps" => %{
"alert" => %{
"loc-key" => "apns_enc"
},
"mutable-content" => 1
},
"data" => Base.encode64(body),
"salt" => salt,
2024-04-06 19:26:44 +00:00
"pk" => key,
"v" => 1
2024-04-06 03:50:28 +00:00
}
2024-04-09 02:20:03 +00:00
payload =
unless is_nil(context) do
Map.put(payload, "ctx", context)
else
payload
end
Logger.debug("Sending #{inspect(payload)}")
2024-04-06 03:50:28 +00:00
Apns.send(registration, payload)
end
end