Send a push notification (Erlang)

Send a push notification via thinwrap_notifications:send_push/2 in Erlang — one call shape for FCM, APNs, Expo and every other push provider.

1. Install

{deps, [{thinwrap_notifications, "~> 1.2"}]}.

2. Send the call

Config = #{provider => fcm,
           project_id => list_to_binary(os:getenv("FCM_PROJECT_ID")),
           client_email => list_to_binary(os:getenv("FCM_CLIENT_EMAIL")),
           private_key => list_to_binary(os:getenv("FCM_PRIVATE_KEY"))},

case thinwrap_notifications:send_push(Config, #{
    to => DeviceToken,
    title => <<"Hello">>,
    body => <<"Hello from Thinwrap">>,
    data => #{<<"deepLink">> => <<"/orders/42">>}
}) of
    {ok, #{status := Status, provider_message_id := Id}} ->
        io:format("~s ~s~n", [Status, Id]);
    {error, #{code := Code, message := Msg}} ->
        io:format("~s: ~ts~n", [Code, Msg])
end.

Same code works for all supported providers — just change the provider ID.