Guide

Webhooks

Tunnels

Ingress Controller

Internet of Things

Using CLI

WebSocket Server

Protocol and Configuration

Socket server allows connecting to Webhook Relay service directly from your application using WebSockets. Communication is done using JSON encoded messages. In order to start streaming, create a new bucket with your desired name:

Once you have a bucket, you can start receiving webhooks to your public endpoint (one public endpoint will be created by default upon bucket creation).

WebSockets will receive events with webhook data when both no outputs are defined or for every internal output specified. If you only have public outputs, neither WebSockets nor relay agent will receive them.

Step 1: Connect

Your API keys allow multiple simultaneous connections. Connect to:

wss://my.webhookrelay.com/v1/socket

Step 2: Authenticate

You must authenticate before you can make any other requests. Generate a new key & secret pair in your tokens page (https://my.webhookrelay.com/tokens). To authenticate, send:

{

"action":"auth",

"key":"YOUR_KEY",

"secret":"YOUR_SECRET"

}

Once authenticated, you will receive the following message:

{

"type": "status",

"status": "authenticated",

"message": "connected successfully, subscribe to buckets"

}

Step 3: Subscribe to webhooks stream

Once authenticated, you can request a stream. Buckets (https://my.webhookrelay.com/buckets) are used for grouping and routing. You can request multiple bucket streams. To subscribe, send:

{

"action":"subscribe",

"buckets": [ "my-1-bucket-name", "my-2-bucket-id" ]

}

Field buckets works as a filter, checking for bucket ID or bucket name. To subscribe to all buckets in your account, send only {"action":"subscribe"} message.

Once subscribed, you will receive the following message, confirming your stream:

{

"type": "status",

"status": "subscribed",

"message": "subscribed to buckets: my-1-bucket-name, my-2-bucket-id"

}

Schema

All incoming webhooks will have event type set to webhook and attached meta field with additional information such as bucket ID, bucket name, input ID, input name:

{

"type": "webhook", // event type

"meta": { // bucket, input and output information

"bucked_id": "1593fe5f-45f9-45cc-ba23-675fdc7c1638",

"bucket_name": "my-1-bucket-name",

"input_id": "b90f2fe9-621d-4290-9e74-edd5b61325dd",

"input_name": "Default public endpoint",

"output_name": "111",

"output_destination": "http://localhost:8080"

},

"headers": { // request headers

"Content-Type": [

"application/json"

]

},

"query": "foo=bar", // query (ie: /some-path?foo=bar)

"body": "{\"hi\": \"there\"}", // request body

"method": "PUT"// request method

}

JavaScript Example

Here’s a short example application written in JavaScript that subscribes to a stream of webhooks:

JavaScript SDK example

Javascript library is available via npm. Library source code is available on GitHub. It’s written in Typescript is a thin wrapper around our WebSocket server client. It can only subscribe to buckets but cannot create/update/delete them.

To install it:

npm i webhookrelay-ws-client

Library usage

var ws = require(`webhookrelay-ws-client`);

// handler function has to accept a JSON string and parse on its own

var handler = function (data) {

console.log(data)

}

// create a client with specified token key and secret from https://my.webhookrelay.com/tokens and any buckets that

// can be created here https://my.webhookrelay.com/buckets. Handler function is called whenever there's a new message

Now, whenever you send webhooks to your public endpoint https://my.webhookrelay.com/v1/webhooks/<your input ID>, they will be received inside your application. You can subscribe to multiple buckets. Each message will have a JSON string that you can parse: