node-red-contrib-webhookrelay package provides an easy way to receive webhooks without exposing whole Node-RED instance to the internet. Webhooks are received through public cloud endpoint and then are streamed over secure connections to your Node-RED.
What problem does it solve?
Node-RED is great at receiving and processing various kinds of events but is not considered safe to be exposed to the internet (more info here). Also, to expose Node-RED to the internet, you will need to either deploy it on a public cloud instance or configure your router NAT/firewall.
Example use case
Here's an example of how to receive and process webhooks on your private Node-RED server (than can be running on your laptop) from a remote device such as a smartphone. Other services such as IFTTT, Zapier or Google Home are great examples of useful integrations. You can get all the webhook details from the node:
How it works
Webhook Relay acts as a gateway to accept all webhooks and then route them to connected clients based on routing configuration. Connected clients can either be lightweight executables, Docker containers or WebSocket clients (this library is based on our ws client):
- Create a bucket
nodered(or any other name) on the buckets page
- Get your authentication token key and secret
- Install our node:
npm install node-red-contrib-webhookrelay
- Open node your node to add bucket name, authentication key and secret.
- Connect any other node to your output.
Example JSON input to the
Example JSON object output from the node:
Sending responses back to the caller
First, ensure that your bucket's input is configured to return responses (by default for security reasons it will always return 200 status code and an empty body):
- Go to your buckets page https://my.webhookrelay.com/buckets
- Go to the bucket details
- Click on input's settings
- From the dropdown select "Any output"
Now, to send back responses from the Node-RED back to Webhook Relay so it can respond to the caller, form a payload:
returnmeta: msgpayloadmeta // this is original meta field from the payload (it's important to include it so we have the message ID)status: 200 // status code to return (200, 201, 400, etc)body: "any payload here (if you want to send JSON, just stringify it first)" // bodyheaders:someheader: 'somevalue';
Then, send this payload back to the Webhook Relay node through its input.
You can also use Webhook Relay CLI. One way forwarding webhooks
relay forward --bucket nodered http://127.0.0.1:1880/your/http/endpoint
Or exposing whole Node-RED to the internet:
relay connect http://127.0.0.1:1880
Pricing - Free + paid options
Webhook Relay has a free tier that can be enough for a lot of integration (CI/CD) but consider subscribing to a paid plan to support the project. Pricing can be found here: https://webhookrelay.com/pricing/.