0.0.2 • Published 12 months ago

replicate-webhook-proxy v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

Replicate Webhook Proxy

Receive your Replicate webhook events through a websocket connection, right in your browser or Node.js code!

Installation

npm install replicate-webhook-proxy

Usage

Specify the following URL when creating a Replicate prediction:

https://r3swiuknhh.execute-api.eu-west-1.amazonaws.com/prod/webhook?key=my_key

Change the key query parameter to a unique key / password. Then, in your browser / Node.js code:

// Import module
const rwp = require("replicate-webhook-proxy");

// Create a websocket client with a key / password used in the prediction webhook URL
const client = rwp("my_key");

// Setup event listeners
client.on("open", () => console.log("onopen"));
client.on("close", () => console.log("onclose"));
client.on("message", (event) => console.log("onmessage", event.data));
client.on("error", (event) => console.log("onerror", event.message));

The message event returns an event.data property with the following structure:

{
  query: {
    key: "my_key"
    // Other query string parameters in the webhook URL
  },
  body: {
    // Replicate prediction data
  }
}

Why?

To receive HTTP webhook requests you need a publicly accessible endpoint on the internet. This is easy if you have a web server already exposed to the internet, but not if you're using a local computer. You can use tools such as ngrok, but they require a separately running process that opens a proxy tunnel to your computer.

This NPM package let's you connect to a websocket endpoint and receive webhook event, right in your broweser or Node.js code!

How?

A proxy in the middle will receive HTTP webhooks from a running Replicate model and relay them via Websockets to the client application.

How it works.

0.0.2

12 months ago

0.0.1

12 months ago