ericlathrop

ericlathrop

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

I needed to send push notifications to a mobile app from my elixir server. I wanted to use Firebase Cloud Messaging’s “topics” so I didn’t have to keep track of every individiual device’s token, which requires using the newer FCM HTTP v1 API. All the other libraries I found on hex (like Pigeon) used the deprecated Legacy HTTP protocol. Versions of this code have been in production since April 2019.

From the README:

FirebaseCloudMessagingHttpV1Api

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

Use goth to acquire authentication tokens.

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)

Where Next?

Popular in Announcing Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36654 110
New
jakub-zawislak
Hi everyone, I’m coming from the Symfony (PHP) framework. I like Phoenix, but it has a one thing that was build much better in the Symfo...
New
Crowdhailer
Raxx is an alternative to Plug and is inspired by projects such as Rack(Ruby) and Ring(Clojure). 1.0-rc.1 is now available. To use it re...
New
anshuman23
Hello all, I have been working on my proposed project called Tensorflex as part of Google Summer of Code 2018.. Tensorflex can be used f...
New
mindok
What is ContEx? A pure Elixir server-side data plotting/charting library outputting SVG. It has nice barcharts in particular and works g...
New
mplatts
With HEEX released we decided to start a components library using Tailwind CSS - check it out here: Petal Components. We also have a boi...
New
wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement