Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pwntus/replicate-webhook-proxy
Receive your Replicate webhook events through a websocket connection, right in your browser or Node.js code!
https://github.com/pwntus/replicate-webhook-proxy
replicate
Last synced: 5 days ago
JSON representation
Receive your Replicate webhook events through a websocket connection, right in your browser or Node.js code!
- Host: GitHub
- URL: https://github.com/pwntus/replicate-webhook-proxy
- Owner: Pwntus
- Created: 2023-05-18T22:23:27.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-05-19T12:19:02.000Z (over 1 year ago)
- Last Synced: 2024-12-15T19:05:37.807Z (7 days ago)
- Topics: replicate
- Language: JavaScript
- Homepage:
- Size: 40 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Replicate Webhook Proxy
Receive your [Replicate webhook](https://replicate.com/docs/webhooks) events through a websocket connection, right in your browser or Node.js code!
## Installation
```sh
npm install replicate-webhook-proxy
```## Usage
Specify the following URL when [creating a Replicate prediction](https://replicate.com/docs/reference/http#predictions.create):
```sh
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:
```js
// 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:
```js
{
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](https://ngrok.com/), 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.](./demo.jpg)