WebSocket Response
Send responses to specific WebSocket connections or broadcast messages to all clients
Overview
This node, named WebSocket Response, is designed to manage WebSocket communications within an n8n workflow. It supports operations such as replying to the original sender, sending messages to specific WebSocket connections, broadcasting messages to all active connections, and retrieving a list of all active WebSocket connections. This node is useful in scenarios where real-time communication with WebSocket clients is required, such as live chat applications, real-time notifications, or interactive dashboards.
Use Case Examples
- Replying to a user who triggered a WebSocket event by sending a confirmation message back to their connection.
- Sending targeted messages to specific WebSocket clients identified by their connection IDs, for example, sending personalized notifications.
- Broadcasting system-wide alerts or updates to all connected WebSocket clients simultaneously.
- Retrieving and monitoring the list of all active WebSocket connections to manage or audit client connections.
Properties
| Name | Meaning |
|---|---|
| Response Options | Options to control the behavior of the response, including whether to continue on send error and whether to verify the connection before sending. |
Output
JSON
operation- The operation performed (e.g., replyToSender, sendToConnection, broadcastToAll, getConnections).connectionId- The ID of the WebSocket connection involved in the operation (if applicable).message- The message sent or processed by the node (if applicable).success- Indicates whether the message sending operation was successful.totalConnections- The total number of active WebSocket connections at the time of the operation.sentToConnections- Number of connections the message was broadcast to (for broadcast operation).connections- List of active WebSocket connections with details such as connectionId, remoteAddress, userAgent, origin, connectedSince, lastActivity, and isOpen (for getConnections operation).error- Error message if the operation failed (present only if continueOnError is enabled and an error occurred).originalInput- The original input data item that triggered the operation.itemIndex- Index of the input item processed.timestamp- Timestamp when the operation was performed.
Dependencies
- Requires an active WebSocket connection manager to handle WebSocket connections and message sending.
Troubleshooting
- If the node throws an error stating 'No connectionId found in input data,' ensure that the node is placed after a WebSocket Trigger node that provides connectionId in the input data.
If the error 'Connection is not active or does not exist' occurs, verify that the specified connectionId corresponds to an active WebSocket connection and that the 'Verify Connection Before Send' option is enabled. - If broadcasting messages results in 'No active connections to broadcast message to' error, check that there are active WebSocket clients connected to the server.
- If message sending fails and 'Continue on Send Error' is disabled, the node will stop execution; enabling this option allows the workflow to continue despite send failures.