This workflow implements a message-batching buffer using Redis for temporary storage and GPT-4 for consolidated response generation. Incoming user messages are collected in a Redis list; once a configurable “inactivity” window elapses or a batch size threshold is reached, all buffered messages are sent to GPT-4 in a single prompt. The system then clears the buffer and returns the consolidated reply.
Map Input
context_id
and message
from webhook or manual triggerCompute Wait Time
Rename node to “Determine Inactivity Timeout”
JS Code:
const wordCount = $json.message.split(' ').filter(w=>w).length;
return [{ json: {
context_id: $json.context_id,
message: $json.message,
waitSeconds: wordCount < 5 ? 45 : 30
}}];
Buffer Message in Redis
buffer_in:{{$json.context_id}}
buffer_count:{{$json.context_id}}
with TTL {{$json.waitSeconds + 60}}
Mark Waiting State
waiting_reply:{{$json.context_id}}
→ if null, SET it to true
with TTL {{$json.waitSeconds}}
Wait for Inactivity
{{$json.waitSeconds}}
secondsCheck Batch Trigger
GET keys:
last_seen:{{$json.context_id}}
buffer_count:{{$json.context_id}}
IF both:
buffer_count >= 1
(now – last_seen) >= waitSeconds * 1000
Rename node to “Trigger Batch on Inactivity or Count”
Fetch & Consolidate
GET entire list buffer_in:{{$json.context_id}}
Information Extractor → rename to “Consolidate Messages”
GPT-4 Chat
Cleanup & Respond
Delete Redis keys:
buffer_in:{{$json.context_id}}
waiting_reply:{{$json.context_id}}
buffer_count:{{$json.context_id}}
Return the consolidated reply to the user
buffer_count
reaches your desired batch size.🔗 Encuentra todos nuestros enlaces en Linktree: innovatexiot.carrd.co
🔗 Conecta conmigo en LinkedIn: Edison Andrés García Herrera