Using a Webhook to get server sent events from a 3rd party

I’m trying to write a small library to subscribe to Server Sent Events sent by Firebase, via REST. I’ve setup a webhook using the following json:

{
  "event" : "firebase_sse",
  "url" : "https://particle-test.firebaseio.com/test.json",
  "requestType" : "GET",
  "mydevices" : true,
  "headers" : {
    "Accept" : "text/event-stream"
  }
}

The equivalent curl statement to get the event stream working would be:

curl -L -H "Accept: text/event-stream" 'https://particle-test.firebaseio.com/test.json'

As specified by Firebase, it requires the Accept header to be an event stream. It also requires that the client (in this case, the webhook) obey redirects. I tested a webhook GET to a simple redirect using https://jigsaw.w3.org/HTTP/300/307.html and it seemed to work ok. The hook-sent event triggers when I publish, but there’s never a hook-response event. My questions are:

  • Do webhooks require GET requests to terminate completely before returning data?
  • Can webhooks process event streams?
  • … has anyone gotten Firebase event subscriptions to work?
1 Like

Hi @jychuah !

I am trying to do the same, to connect the firebade Rest API through webhooks just as you desbribed. I am wondering if you found an answer or another option to constantly stream from the Firebase database. It would be great if you can share it with me!

When I run the webhook attached to my database from my device, I show error events in the console stating that the response from the server timed out. This is because the Firebase Rest Api sends a response every 30 seconds when there is no data changed, and the Webhook has a timeout of 5 seconds I believe.

Anyways, I would really appreciate if you could share what you have found!

Cheers,
Jose

Hi, Jose. I ended up writing a Node js proxy to get the job done. You can deploy it to Heroku where your web hook sends a subscription request and the proxy forwards notifications from Firebase as events. It’s a little clunky and I never ended up deploying it in a project, but it works OK. Due to the transmission and use of non-existing particle tokens, I can’t guarantee security however.

Thank you for the reply, I will definitely give a try! Did you tried directly setting up the AT commands for http request for the Ublox Sara module? I have been trying on doing that and successfully got a response from the Firebase API, however, for streaming I don’t know how to get from the module that it has received a response due to the particle.command and callback functions.

I haven’t cracked open my Electron, to be honest. However, I would probably rely on the cloud features built into Particle.io to manage the messages and let web hooks manage my authentication. While it would definitely allow me to retain an HTTP stream, I wouldn’t be comfortable with the data consumption (keep alive messages, etc.)