node-red-contrib-webhookrelay 0.3.0
General purpose webhook tunnel-based receiver. Process 3rd party webhooks without public IP or configuring NAT/firewall
Webhook Relay
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):
Usage
- 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 https://my.webhookrelay.com/v1/webhooks/544a6fe8-83fe-4361-a264-0fd486e1665d
endpoint:
{
"msg": "hello Node-RED!"
}
Example JSON object output from the node:
{
"topic": "nodered",
"payload": {
"type": "webhook",
"meta": {
"id": "xxxxx-xxxx-xxxx-ab1d-89a8b0505693",
"bucked_id": "12302faf-43bd-43c4-ab1d-89a8b0505693",
"bucket_name": "nodered",
"input_id": "544a6fe8-83fe-4361-a264-0fd486e1665d",
"input_name": "Default public endpoint",
"output_name": "",
"output_destination": ""
},
"headers": {
"Content-Type": ["application/json"],
"Accept": ["*/*"],
"Content-Length": ["29"],
"User-Agent": ["insomnia/6.3.1"],
"Cookie": ["__cfduid=dc244a014f0b1e2965544ddb483c3fe1b1525866866"]
},
"query": "",
"body": "{\n\t\"msg\": \"hello Node-RED!\"\n}",
"method": "PUT"
},
"_msgid": "43de3dbf.04f4c4"
}
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:
return {
meta: msg.payload.meta, // 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)" // body
headers: {
someheader: ['somevalue']
}
};
Then, send this payload back to the Webhook Relay node through its input.
Alternative methods
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/.