ChatBot Enhanced icon

ChatBot Enhanced

Enhanced chatbot node with Redis/Valkey integration for rate limiting, session management, and advanced features

Overview

The ChatBot Enhanced node provides advanced chatbot functionalities with integrated Redis support, focusing on rate limiting, session management, message buffering/routing, and analytics. Specifically, the Rate Limiting - Check Rate Limit operation verifies if a user or session is within allowed request limits per minute, helping to prevent abuse or overload by enforcing usage quotas.

This node is beneficial in scenarios where you want to:

  • Protect chatbot services from excessive requests by individual users.
  • Implement fair usage policies for API calls or chatbot interactions.
  • Monitor and control traffic bursts with burst protection and penalty mechanisms.

Example use case:
A chatbot deployed on a website uses this node to ensure each visitor can only send up to 10 messages per minute. If a user exceeds this limit, further messages are blocked or delayed, preventing spam and server overload.


Properties

Name Meaning
Session Key Unique identifier for the user or session; can be set dynamically using expressions.
Message Content The content of the message to process; supports expressions to extract from input data.
Rate Limit (Requests per Minute) Maximum number of allowed requests per minute (1 to 1000).
Enable Debug Mode Enables detailed logging and debug information during execution.
Redis Key Prefix Prefix string used for Redis keys to avoid collisions with other applications or nodes.

Output

The node outputs two main streams:

  1. Main output: Contains success or processed results with details such as:

    • Whether the request was allowed or blocked.
    • Current request count, remaining quota, reset time, and retry-after duration.
    • Original message content and session ID.
    • Operation type identifier (smartRateLimit).
  2. Status output: Provides error information or metrics including:

    • Error details if processing fails.
    • Metrics about rate limiting performance, e.g., total requests, remaining requests, window utilization percentage.
    • Redis connection health status.

The json output structure includes fields like:

{
  "type": "success",
  "data": {
    "message": "<original message>",
    "sessionId": "<session key>",
    "operationType": "smartRateLimit",
    "allowed": true,
    "rateLimitData": {
      "requestCount": 5,
      "remainingRequests": 5,
      "resetTime": 1680000000000,
      "retryAfter": 0
    }
  },
  "timestamp": 1680000000000
}

No binary data is produced by this operation.


Dependencies

  • Redis Server: The node requires a Redis instance for storing rate limiting counters and session data.
  • API Key Credential: A valid API key credential for connecting to Redis must be configured in n8n.
  • RedisManager: Internal Redis client manager handles connection pooling and commands.
  • RateLimiter: Implements sliding window algorithm with burst protection and penalties.

Ensure that the Redis credentials are correctly set up and the Redis server is accessible with appropriate permissions.


Troubleshooting

Common Issues

  • Redis Connection Failures:
    Errors like "Redis connection failed" indicate network issues, incorrect credentials, or Redis server downtime. Verify Redis endpoint, credentials, and connectivity.

  • Rate Limit Always Denied:
    If all requests are blocked, check if the Session Key is unique per user/session and not shared inadvertently, causing combined counts.

  • Unexpected High Latency:
    Slow Redis responses or network delays can increase processing time. Enabling debug mode may help identify bottlenecks.

Error Messages

  • "Redis connection failed: <error message>"
    Means the node could not connect to Redis. Resolve by checking credentials and Redis availability.

  • "Unknown operation type: <operation>"
    Indicates an unsupported operation was requested. Confirm the selected operation matches the node's capabilities.

  • "ITEM_PROCESSING_ERROR"
    An error occurred while processing a specific item. Inspect the error message for details and verify input data correctness.


Links and References


If you need summaries for other resources or operations, feel free to ask!

Discussion