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:
// client.jsconstWebSocket=require('ws');constws=newWebSocket('wss://my.webhookrelay.com/v1/socket');var apiKey =process.env.RELAY_KEY;var apiSecret =process.env.RELAY_SECRET;ws.on('open',functionopen() {// on connection, send our authentication requestws.send(JSON.stringify({action:'auth', key: apiKey, secret: apiSecret})); });ws.on('close',functionclose() {console.log('disconnected');});ws.on('message',functionincoming(data) {console.log(data)var msg =JSON.parse(data);if (msg.type ==='status'&&msg.status ==='authenticated') {// if we got authentication confirmation, send subscribe event to the serverws.send(JSON.stringify({action:'subscribe', buckets: ['123']})); }});
To run:
1. Install websocket library ws:
npm i ws
2. Set token key and secret (generate at tokens page):