WebSocket Response icon

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 real-time communication scenarios where workflows need to interact dynamically with WebSocket clients, such as chat applications, live notifications, or real-time data updates.

Use Case Examples

  1. Broadcast a notification message to all connected WebSocket clients when a certain event occurs.
  2. Reply to the sender of a WebSocket message with a confirmation or data response.
  3. Send a custom JSON message to a specific WebSocket client identified by connection ID.

Properties

Name Meaning
Message The message content to send to WebSocket client(s). Required for sending operations.
Message Format The format of the message to send, which can be plain text, a JSON object, or a template with variables.
JSON Message Builder Fields to build a JSON message including type, content, status, and whether to include a timestamp. Used only when message format is JSON.
Response Options Options to control behavior on send error and whether to verify connection status before sending.

Output

JSON

  • operation - The operation performed (e.g., broadcastToAll).
  • message - The message that was sent or processed.
  • sentToConnections - Number of connections the message was broadcast to (for broadcast operation).
  • totalConnections - Total number of active WebSocket connections.
  • success - Boolean indicating if the message sending was successful.
  • connectionId - ID of the WebSocket connection involved (for specific send operations).
  • error - Error message if sending failed and continueOnError is enabled.
  • originalInput - The original input JSON data for the item.
  • itemIndex - Index of the processed item in the input array.
  • timestamp - Timestamp when the operation was performed.
  • connections - List of active WebSocket connections with details (for getConnections operation).

Dependencies

  • An active WebSocket connection manager service to handle connections and message sending.

Troubleshooting

  • Error 'No connectionId found in input data' occurs if the node is used without a preceding WebSocket Trigger node that provides connectionId in input data. Ensure the node is placed correctly in the workflow.
    Error 'Connection is not active or does not exist' indicates the specified WebSocket connection ID is invalid or the connection is closed. Verify the connection ID and that the client is connected.
  • If broadcasting messages results in 'No active connections to broadcast message to', it means no clients are currently connected. Check client connections before broadcasting.
  • If sending fails and 'Continue on Send Error' is false, the node will throw an error and stop execution. Enable this option to allow workflow continuation despite send failures.

Links

Discussion