How can i do xmpp push notifications to Firebase?

Hi, is there any tutorials or guide for implements push notifications to Firebase using XMPP?

Thanks!

1 Like

Try to use Romeo.

1 Like

Hi, I have the same question, just more concrete. How would I go about constructing xml for the fcm message in Romeo. Say for instance something like this:

<message id="">
  <gcm xmlns="google:mobile:data">
  {
      "to":"REGISTRATION_ID",  // "to" replaces "registration_ids"
      "message_id":"m-1366082849205" // new required field
      "data":
      {
          "hello":"world",
      }
      "time_to_live":"600",
      "delay_while_idle": true/false,
      "delivery_receipt_requested": true/false
  }
  </gcm>
</message>

The documentation from firebase specifies that all you have to do, is to send the <gcm>...</gcm> part in a classic message stanza.

So you’ll need Romeo.Stanza.message/1:

:ok = Conn.send(pid, Stanza.message(gcm_xml))

Oh, ok, so I can just pass xml as a string/binary to this method? Missed it, i was trying all the time with https://hexdocs.pm/romeo/Romeo.Stanza.html#message/3.

Thanks

As a side note Discord did a great blog post about how they use firebase for push notifications. It’s got good examples of using GenStage.

Thanks, I’m pretty new to elixir and still don’t completely understand stuff about GenServer, but that blog post is how I got the idea for using xmpp for sending push notifcations, since http is too slow for my needs, and there is no sign yet of http2 for firebase…

Finally got to trying out the https://hexdocs.pm/romeo/Romeo.Stanza.html#message/1 method, but don’t think just passing xml works. The Stanza.message/1 method checks if message passed is a map and sends it to Stanza.message/3:

def message(msg) when is_map(msg) do
  message(msg["to"], msg["type"], msg["body"])
end
def message(to, type, message) do
  xmlel(name: "message",
    attrs: [
      {"to", to},
      {"type", type},
      {"id", id},
      {"xml:lang", "en"}
    ],
    children: generate_body(message))
end

And if i try to pass in raw xml into as message, it gets wrapped in body element and i receive InvalidJson : MissingPayload from fcm. Is there a way to send a message without it being parsed?

@callmeahab,

Author of Romeo here. All you need to do is write a function that generates the appropriate XML data structure using the records from the Romeo.XML module.

Something like this (to match the message you mentioned above):

use Romeo.XML

def gcm(json_string) do
  xmlel(name: "message",
    attrs: [{"id", ""}],
    children: [
      xmlel(name: "gcm",
        attrs: [{"xmlns", "google:mobile:data"}],
        children: [
          xmlcdata(content: json_string)
        ]
    ])
end

Then send it like so:

json = Poison.encode!(%{...})
:ok = Romeo.Connection.send(pid, gcm(json))

Hope this helps…

Thanks a lot.

I used ZetPush https://zetpush.com/ and worked just fine for me.