Webhook Relay
Search…
Receive webhooks inside your JavaScript app
Learn how to receive and process webhooks directly inside your application.
​
Webhook Relay’s Socket Server allows users to receive webhooks inside their application without having public IP, domain or even running a web server themselves. Here’s a short example application written in JavaScript that subscribes to a stream of webhooks:
1
// client.js
2
const WebSocket = require('ws');
3
​
4
const ws = new WebSocket('wss://my.webhookrelay.com/v1/socket');
5
​
6
var apiKey = process.env.RELAY_KEY;
7
var apiSecret = process.env.RELAY_SECRET;
8
​
9
ws.on('open', function open() {
10
// on connection, send our authentication request
11
ws.send(JSON.stringify({action: 'auth', key: apiKey, secret: apiSecret}));
12
});
13
​
14
ws.on('close', function close() {
15
console.log('disconnected');
16
});
17
​
18
ws.on('message', function incoming(data) {
19
console.log(data)
20
var msg = JSON.parse(data);
21
if (msg.type === 'status' && msg.status === 'authenticated') {
22
// if we got authentication confirmation, send subscribe event to the server
23
ws.send(JSON.stringify({action: 'subscribe', buckets: ['123']}));
24
}
25
});
Copied!
To run:

1. Install websocket library ws:

1
npm i ws
Copied!

2. Set token key and secret (generate at tokens page):

1
export RELAY_KEY=your-token-key
2
export RELAY_SECRET=your-token-secret
Copied!

3. Start it:

1
node client.js
Copied!
Now, if you send a webhook to your public input endpoint, you should see something similar:
1
$ node client.js
2
{"type":"status","status":"authenticated","message":"connected successfully, subscribe to buckets"}
3
{"type":"status","status":"subscribed","message":"subscribed to buckets: 123"}
4
{"type":"webhook","meta":{"bucked_id":"89e44c32-27ff-4832-8655-8a42d3851b6f","bucket_name":"123","input_id":"ee4ac550-12a4-41a7-837d-dd3356ed1771","input_name":"Default public endpoint"},"headers":{"Content-Length":["15"],"User-Agent":["insomnia/6.0.2"],"Cookie":["__cfduid=dc244a014f0b1e2965544ddb483c3fe1b1525866866"],"Content-Type":["application/json"],"Accept":["*/*"]},"query":"","body":"{\"hi\": \"there\"}","method":"PUT"}
Copied!
Copy link
Contents