Beast
CDCloudflare Developers
•Created by Magnaboy on 12/18/2024 in #workers-help
Can I do what I want with websockets in a worker?
I think instead of adding web socket support in a Worker itself you would want to keep it in a Durable Object where it can be a longer running process. When you deploy a durable object you're also deploying a worker alongside it, and in that worker you can setup that webhook route that receives data from your Discord bot and then have it send that data into your durable object which would then process it in the web socket with
server.send("Your message")
See the CF example below:
https://developers.cloudflare.com/durable-objects/examples/websocket-server/
But you will likely want to use the web socket Hibernation API to avoid any charges when you're not actively using any web sockets.2 replies