WebSocket Response
Send responses to specific WebSocket connections or broadcast messages to all clients
Overview
This node sends messages to WebSocket clients in various ways: replying to the original sender, sending to a specific connection by ID, broadcasting to all connected clients, or retrieving a list of active connections. It is useful in workflows that interact with WebSocket clients, such as real-time chat applications, live notifications, or interactive dashboards.
Use Case Examples
- Reply to the sender of a WebSocket message with a confirmation response.
- Send a custom message to a specific WebSocket client identified by connection ID.
- Broadcast a notification message to all connected WebSocket clients.
- Retrieve and log the list of all active WebSocket connections for monitoring.
Properties
| Name | Meaning |
|---|---|
| Connection ID Source | Determines where to get the WebSocket connection ID from, either from the input data or manual input. |
| Connection ID | The ID of the WebSocket connection to send the message to. Required if Connection ID Source is manual. |
| Message | The message content to send to the WebSocket client(s). Required for sending operations. |
| Message Format | Format of the message to send: plain text, JSON object, or a template with variables. |
| JSON Message Builder | Fields to build a JSON message when Message Format is JSON, including message type, content, status, and whether to include a timestamp. |
| Response Options | Options controlling error handling and connection verification before sending. |
Output
JSON
operation- The operation performed (replyToSender, sendToConnection, broadcastToAll, getConnections).connectionId- The WebSocket connection ID the message was sent to (if applicable).message- The message content sent to the client(s).success- Boolean indicating if the message was successfully sent.totalConnections- Total number of active WebSocket connections.sentToConnections- Number of connections the message was broadcast to (for broadcast operation).connections- List of active WebSocket connections with details (for getConnections operation).error- Error message if sending failed and continueOnError is enabled.originalInput- The original input data item JSON.itemIndex- Index of the processed input item.timestamp- Timestamp when the operation was performed.
Dependencies
- WebSocketConnectionManager from an internal shared module managing WebSocket connections
Troubleshooting
- Error 'No connectionId found in input data' occurs if the node expects a connectionId from input but none is present. Ensure this node follows a WebSocket Trigger node or manual connectionId is provided.
Error 'Connection is not active or does not exist' occurs if the specified connectionId is not currently active. Verify the connection ID and that the client is connected. - If broadcasting messages results in zero recipients and continueOnError is false, the node throws an error. Ensure there are active WebSocket clients connected before broadcasting.
- Unknown operation error occurs if an unsupported operation is selected. Verify the operation parameter is set correctly.
Links
- WebSocket API Documentation - General information about WebSocket protocol and API.
- n8n WebSocket Response Node Documentation - Official documentation for the WebSocket Response node in n8n.