WebSocket Response
Send responses to specific WebSocket connections or broadcast messages to all clients
Overview
This node, named WebSocket Response, is designed to send 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 scenarios where workflows need to interact with WebSocket clients dynamically, such as sending real-time updates, responses, or notifications based on workflow events.
Use Case Examples
- Replying to a client that triggered a WebSocket event with a confirmation message.
- Sending a targeted message to a specific WebSocket connection identified by its connection ID.
- Broadcasting a notification to all connected WebSocket clients, such as a system-wide alert.
- Retrieving and listing all active WebSocket connections for monitoring or management purposes.
Properties
| Name | Meaning |
|---|---|
| Connection ID Source | Determines where to obtain the WebSocket connection ID from, either from the input data (usually from a WebSocket Trigger node) or manual input. |
| Connection ID | The ID of the WebSocket connection to send the message to. Required if Connection ID Source is set to Manual Input. |
| Message | The message content to send to the WebSocket client(s). Required for sending operations. |
| Message Format | Specifies the format of the message to send: plain text, JSON object, or a template with variables. |
| JSON Message Builder | When message format is JSON, allows building a structured JSON message with fields: type, content, status, and whether to include a timestamp. |
| Response Options | Options controlling behavior on send errors and connection verification before sending. |
Output
JSON
operation- The operation performed (e.g., replyToSender, sendToConnection, broadcastToAll, getConnections).connectionId- The WebSocket connection ID the message was sent to (if applicable).message- The message content sent to the WebSocket client(s).success- Boolean indicating if the message was successfully sent.totalConnections- Total number of active WebSocket connections at the time of operation.sentToConnections- Number of connections the message was broadcast to (for broadcast operation).connections- List of active WebSocket connections with details (for getConnections operation).originalInput- The original input data item JSON.itemIndex- Index of the input item processed.timestamp- Timestamp when the operation was performed.error- Error message if sending failed and continueOnError is enabled.
Dependencies
- WebSocketConnectionManager from an internal shared module managing WebSocket connections
Troubleshooting
- If the node throws 'No connectionId found in input data', ensure the node is placed after a WebSocket Trigger node that provides connectionId in the input data.
- If 'Connection is not active or does not exist' error occurs, verify that the connection ID is correct and the connection is still open. You can disable connection verification in response options if needed.
- If broadcasting fails with 'No active connections to broadcast message to', ensure there are active WebSocket clients connected.
- If sending fails and continueOnError is false, the node will throw an error stopping the workflow. Enable continueOnError to allow workflow continuation despite send failures.