FirebaseCloudMessagingHttpV1Api

Hex.pm Documentation

Send Firebase Cloud Messaging Push Notifications via the FCM HTTP v1 API.

Use goth to acquire authentication tokens.

example

Example

{:ok, %Goth.Token{token: token}} =
  Goth.Token.for_scope("https://www.googleapis.com/auth/firebase.messaging")

%Google.Firebase.FCM.V1.Message{
  notification: %Google.Firebase.FCM.V1.Notification{
    title: "notification title",
    body: "notification body"
  },
  android: %Google.Firebase.FCM.V1.AndroidConfig{
    priority: "HIGH",
    ttl: "86400s",
    notification: %Google.Firebase.FCM.V1.AndroidNotification{
      channel_id: "my-android-channel"
    }
  },
  topic: "my-topic"
}
|> Google.Firebase.FCM.V1.Message.send("projects/my-firebase-project", token)

installation

Installation

The package can be installed by adding firebase_cloud_messaging_http_v1_api to your list of dependencies in mix.exs:

def deps do
  [
    {:firebase_cloud_messaging_http_v1_api, "~> 0.1.0"}
  ]
end

alternatives

Alternatives

The main alternative is Pigeon, which uses the deprecated Legacy HTTP protocol. I needed the newer protocol so I could use topics and avoid sending individual messages to each device, so I wrote this library.