Skip to main content

setRequestHandler

codebolt.chat.setRequestHandler(handler: RequestHandler): void
Sets a global request handler for all incoming messages.

Parameters

NameTypeDescription
handlerRequestHandlerThe async handler function that processes incoming messages.

Example

// Set up a handler for all incoming WebSocket messages
codebolt.chat.setRequestHandler(async (request, response) => {
// Process the incoming request
console.log("Received request:", request);

// Send a response back
response({ success: true, data: "Request processed" });
});

Explanation

This function sets up a global handler for processing all incoming WebSocket messages. The handler receives the parsed request object and a response callback function that can be used to send data back to the server.