punnP
Convex Community2y ago
8 replies
punn

Websocket endpoint

Hi all, is it possible to expose a websocket endpoint in Convex?

Code snippet from express we're trying to emulate
import { RawData, WebSocket } from "ws";
import { Request } from "express";

var express = require('express');
var app = express();
var expressWs = require('express-ws')(app);
const port = 3000

// Your other API endpoints
app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.ws("/llm-websocket/:call_id",
  async (ws: WebSocket, req: Request) => {
    // callId is a unique identifier of a call, containing all information about it
    const callId = req.params.call_id;

    ws.on("error", (err) => {
      console.error("Error received in LLM websocket client: ", err);
    });
    ws.on("message", async (data: RawData, isBinary: boolean) => {
      // Retell server will send transcript from caller along with other information
      // You will be adding code to process and respond here
    });
  },
);

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
});
Was this page helpful?