n8n

How to Automate Redis OpenAI Chat Consolidation?

Turn busy chat streams into clear, single messages ready for fast replies. Useful for support teams and any chat based queue that needs fewer prompts and lower costs. Great for websites, help desks, and messaging inboxes that receive many short messages in a row.

Incoming chat text is buffered in Redis with a context id. The flow tracks last seen time, counts new messages, and sets a waiting flag so only one batch runs at a time. A smart wait time is calculated from word count, then an inactivity or count check decides when to consolidate. When ready, all buffered messages are pulled, reversed for order, and sent to an information extractor that removes duplicates and returns one clean paragraph using an OpenAI chat model. After reply, the buffer, counter, and waiting flag are cleared.

You need Redis and an OpenAI API key. Map your context id so messages from the same user stay grouped. Expect fewer API calls, faster answers, and better agent focus. Good for live chat triage, WhatsApp style threads, and internal help queues. Adjust the wait rules to fit your volume and message length.

What are the key features?

  • Chat intake buffers messages in Redis lists keyed by context id.
  • Waiting flag prevents overlapping runs so batches do not collide.
  • Dynamic wait time based on word count adjusts to message length.
  • Inactivity and count checks decide when to consolidate or exit.
  • Information extractor merges and de duplicates into one paragraph.
  • OpenAI chat model generates a clean, ready to use summary.
  • Cleanup step clears buffer, counters, and waiting flag after reply.
  • Supports manual testing and runs from other workflows.

What are the benefits?

  • Reduce manual message sorting from hours to minutes
  • Cut duplicate prompts to the model by up to 50 percent
  • Lower token use with one consolidated request per batch
  • Handle higher chat volume without extra agents
  • Keep messages grouped by user for clearer context

How do you set it up?

  1. Import the template into n8n: Create a new workflow in n8n > Click the three dots menu > Select 'Import from File' > Choose the downloaded JSON file.
  2. You will need accounts with OpenAI and Redis. See the Tools Required section above for links to create accounts with these services.
  3. In the n8n credentials manager, create a Redis credential. Enter host, port, and password from your Redis service. Save the credential and select it on all Redis nodes.
  4. In the n8n credentials manager, create an OpenAI API Key credential. Get the key from your OpenAI account API page. Name the credential clearly and select it on the OpenAI Chat Model node.
  5. Open the Chat Trigger node and confirm it captures the message text and a context id field. If your source uses a different field name, map it in the Set or Code node before buffering.
  6. Open the Code node named get wait seconds and adjust the rules for waitSeconds to match your typical message size and speed.
  7. Check the Redis keys used in the Set and Get nodes. They follow buffer_in, buffer_count, last_seen, and waiting_reply with the context id. Keep these consistent.
  8. Run a manual test with the manual trigger and the mock input node to confirm keys are written to Redis and the waiting flag is set.
  9. Send a few chat messages quickly. Wait for the inactivity window. Verify the buffer is read, a single paragraph is produced, and cleanup deletes the keys.
  10. If batches do not fire, increase waitSeconds or lower the threshold in the inactivity and count check. If Redis calls fail, confirm host, port, TLS, and password.
  11. When stable, connect an external chat source to the Chat Trigger endpoint and monitor Redis key TTLs to ensure smooth batching at scale.

Tools Required

$24 / mo or $20 / mo billed annually to use n8n in the cloud. However, the local or self-hosted n8n Community Edition is free.

OpenAI

Sign up

Pay-as-you-go: GPT-5 at $1.25 per 1M input tokens and $10 per 1M output tokens

Redis

Sign up

Free plan: $0 / mo, 30 MB, single DB

Similar Templates

Join Futurise to access 1,200+ automation templates

Get instant access to ready-made automation workflows for n8n, Make.com, AI agents, and more. Download, customise, and deploy in minutes.