Can I do what I want with websockets in a worker?

I havent used websockets in workers before and have some trouble understanding how it works. I just want to confirm if what I want to do is possible or not: a long-running websocket server that sends messages based on receiving other external events.

My actual end goal is something like this: a client (a browser) connects to my worker acting as a websocket server, and they are fed messages over that WS periodically. They are triggered by certain external events, which is the part I'm having trouble thinking about. For example, say I have a discord bot (running somewhere else) that wants to trigger an event on this worker websocket, how would I do that? Sending a simple webhook to my worker with the event data sure, but how do I feed that through to that websocket connection? Is that the part durable objects helps with?

Thank you
Was this page helpful?