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 associated with a specific key (such as a user ID, group ID, or a combination) using Redis as a backend. It is designed to handle multiple triggers that send messages independently but need to be combined into a single aggregated output intelligently.

This node supports two main strategies for aggregation:

  • Smart Wait: Waits until no new messages arrive within a specified timeout period before outputting the aggregated message.
  • Immediate on Complete: Outputs the aggregated message immediately once it detects that the last message ends with one of the predefined "end words" indicating completion.

Practical Use Cases

  • Combining chat messages from a user or group that arrive in separate events into a single coherent message.
  • Collecting partial inputs or fragmented data over time before processing them together.
  • Implementing intelligent delays in workflows where you want to wait for a complete sentence or thought before proceeding.

Properties

Name Meaning
Key The identifier used to group messages. Can be a user ID, group ID, or a combination like user123_group456.
Message Content The content of the message to aggregate.
Wait Time (Seconds) The amount of time (in seconds) to wait after the last message before considering the aggregation complete (used mainly in Smart Wait strategy).
Strategy The aggregation strategy to use:
- Smart Wait: Waits intelligently until no new messages arrive.
- Immediate on Complete: Outputs immediately when a complete sentence is detected.
End Words A comma-separated list of words that indicate the end of a message when using the Immediate on Complete strategy. When 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:

  • status: Indicates the current state, e.g., "messages_aggregated", "message_stored", "timeout", "no_messages", "superseded".
  • key: The aggregation key used.
  • aggregatedMessage: The combined message string from all collected messages.
  • messageCount: Number of messages aggregated.
  • originalMessages: Array of original message objects with content and timestamp.
  • trigger: What caused the output, e.g., "immediate_complete" or "smart_timeout".
  • aggregatedAt: ISO timestamp when aggregation was completed.
  • Additional fields such as reason, maxWaitTime, or totalWaitTime may appear depending on the context.

If the node cannot find messages or if messages expire, it outputs appropriate status messages explaining the reason.

The node does not output binary data.

Dependencies

  • Requires a Redis server accessible via credentials configured in n8n.
  • Needs an API key credential or connection details for Redis (host, port, password, TLS, etc.).
  • Uses the ioredis library internally to interact with Redis.
  • The node expects Redis to support commands like rpush, lrange, expire, and locking mechanisms.

Troubleshooting

  • Missing Redis Credentials: The node will throw an error if Redis credentials are not found. Ensure credentials are properly set up in n8n.
  • Key or Message Content Missing: Both "Key" and "Message Content" properties are mandatory; missing either will cause an error.
  • Redis Connection Issues: Connection timeouts or authentication failures can occur if Redis is unreachable or credentials are incorrect.
  • Locking Conflicts: The node uses Redis locks to prevent concurrent aggregations. If another process holds the lock, the node waits briefly and retries.
  • Message Expiry: Messages stored in Redis have expiration based on wait time. If messages expire before aggregation completes, the node outputs a "no_messages" status.
  • Strategy Misconfiguration: Using the Immediate strategy without specifying valid end words may cause unexpected behavior.
  • Error Messages: Errors from Redis or JSON parsing issues are caught and rethrown with descriptive messages.

To resolve common errors:

  • Verify Redis connectivity and credentials.
  • Ensure input properties are correctly provided.
  • Adjust wait times and end words according to your message patterns.
  • Monitor Redis logs for connection or command errors.

Links and References

Discussion