Telegram Chat with Buffering

For Telegram, this workflow efficiently manages multiple incoming messages by buffering them for 10 seconds, allowing users to send a series of messages in quick succession. It consolidates these messages into a single coherent conversation, processes them with an AI agent, and responds with one unified reply, enhancing user interaction and streamlining communication.

7/8/2025
22 nodes
Complex
manualcomplexsticky notetelegramtelegramtriggerwaitsupabasenoopaggregatelangchainadvancedcommunicationbotlogicconditionaldatabasedata
Categories:
Communication & MessagingComplex WorkflowManual Triggered
Integrations:
Sticky NoteTelegramTelegramTriggerWaitSupabaseNoOpAggregateLangChain

Target Audience

This workflow is ideal for:
- Developers looking to integrate AI responses into Telegram bots.
- Businesses wanting to enhance customer support through automated responses.
- Chatbot Creators aiming to manage multiple user messages efficiently.
- Product Managers seeking to streamline communication processes within their applications.

Problem Solved

This workflow addresses the challenge of handling multiple rapid messages from users in applications like Telegram. Instead of responding to each message individually, it buffers incoming messages and processes them as a single coherent conversation. This enhances user experience by providing a unified response rather than fragmented replies.

Workflow Steps

  • Receive Message: The workflow begins when a message is received through the Telegram bot.
    2. Add to Queued Messages: The message is stored in a Supabase PostgreSQL table called message_queue along with the user's ID and message ID.
    3. Wait for Additional Messages: The system waits for 10 seconds to see if any new messages arrive from the same user.
    4. Get Queued Messages: After the wait period, all messages from the user are retrieved from the database.
    5. Sort by Message ID: The messages are sorted to ensure they are processed in the order they were received.
    6. Check Most Recent Message: The workflow checks if the last received message is the most recent one to prevent duplicates.
    7. Aggregate Messages: If the most recent message is confirmed, all queued messages are combined into a single conversation.
    8. AI Processing: The aggregated messages are sent to an AI model for generating a unified response.
    9. Send Reply: The AI's response is sent back to the user on Telegram.
    10. Delete Queued Messages: Finally, the processed messages are deleted from the queue to maintain a clean state.
  • Customization Guide

    Users can customize this workflow by:
    - Modifying the Wait Time: Change the value of the wait period to adjust how long the system waits for additional messages.
    - Using Different AI Models: Replace the current AI model with another one to suit different conversational needs.
    - Adding System Messages: Incorporate system messages to tailor the AI's behavior and responses according to specific use cases.
    - Changing Database Structure: Adapt the Supabase database structure or fields to capture additional data as required.