Redis Message Aggregator icon

Redis Message Aggregator

Gom tin nhắn từ nhiều trigger riêng biệt với Redis + intelligent delay

Overview

The Redis Message Aggregator node collects and aggregates messages from multiple independent triggers using Redis as a backend. It is designed to intelligently delay output until certain conditions are met, such as no new messages arriving within a specified wait time or detecting a complete sentence based on defined end words.

This node is useful in scenarios where messages arrive asynchronously and need to be combined before further processing. For example:

  • Collecting chat messages from a user or group over a short period and then processing them as a single aggregated message.
  • Waiting for a user to finish typing a complete sentence before triggering downstream actions.
  • Grouping fragmented inputs into one coherent message to reduce noise in workflows.

Properties

Name Meaning
Key The key used to group messages. This can be a user ID, group ID, or a combination (e.g., "user123", "group456", or "user123_group456").
Message Content The content of the message to aggregate.
Wait Time (Seconds) The time in seconds to wait after the last message before outputting the aggregated result.
Strategy The aggregation strategy to use:
- Smart Wait: Waits intelligently and outputs only when sure no new messages will arrive.
- Immediate on Complete: Outputs immediately once a complete sentence is detected.
End Words (Shown only if "Immediate on Complete" strategy is selected) A comma-separated list of words that indicate the end of a message. If the message ends with any of these words, aggregation outputs immediately.

Output

The node outputs JSON objects representing the aggregation status and results. The structure varies depending on the strategy and state:

  • When messages are aggregated successfully:

    {
      "status": "messages_aggregated",
      "key": "<aggregation key>",
      "aggregatedMessage": "<concatenated message content>",
      "messageCount": <number of messages aggregated>,
      "originalMessages": [
        {"content": "<message1>", "timestamp": <timestamp>},
        ...
      ],
      "trigger": "<trigger type: immediate_complete or smart_timeout>",
      "aggregatedAt": "<ISO timestamp>",
      "totalWaitTime": <optional, seconds waited in smart strategy>
    }
    
  • When a message is stored but waiting for completion:

    {
      "status": "message_stored",
      "key": "<aggregation key>",
      "messageContent": "<current message>",
      "messageCount": <current count>,
      "reason": "waiting_for_complete_sentence"
    }
    
  • Other statuses include:

    • "no_messages": No messages found for the key.
    • "timeout": Maximum wait time exceeded without aggregation.
    • "superseded": Another execution is already aggregating messages.

The node does not output binary data.

Dependencies

  • Requires a Redis server connection configured via credentials providing host, port, password, database, TLS options, or a connection string.
  • Uses the ioredis library internally to interact with Redis.
  • Requires an API key credential for Redis access configured in n8n.

Troubleshooting

  • Missing Redis Credentials: The node throws an error if Redis credentials are not found. Ensure you have configured valid Redis credentials in n8n.
  • Key or Message Content Missing: Both "Key" and "Message Content" properties are mandatory. Omitting either causes an error.
  • Redis Connection Issues: Connection timeouts or authentication failures may occur if Redis server details or credentials are incorrect.
  • Lock Contention: The node uses Redis locks to prevent concurrent aggregation. If many executions run simultaneously for the same key, some may be superseded.
  • Message Expiry: Messages expire after a timeout (3x wait time). If messages expire before aggregation, the node outputs a "no_messages" status.
  • Strategy Misconfiguration: Using "Immediate on Complete" without specifying appropriate end words may cause unexpected behavior.

Links and References

Discussion