AI Telegram Bot with Supabase Memory (AI Telegram Bot with Contextual Memory)
This workflow implements an intelligent Telegram chatbot that can engage in natural conversations through the OpenAI assistant and utilizes a Supabase database to store the contextual memory of user sessions. The bot can receive user messages, automatically generate replies, and track historical conversations, making interactions smoother. It is suitable for scenarios such as customer service auto-replies and virtual assistants, enhancing user experience and addressing the issue of traditional chatbots lacking contextual understanding.

Workflow Name
AI Telegram Bot with Supabase Memory (AI Telegram Bot with Contextual Memory)
Key Features and Highlights
This workflow implements an intelligent Telegram chatbot integrated with the OpenAI assistant and utilizes Supabase as a database to maintain contextual memory of user conversations. The bot receives user messages, calls the OpenAI assistant to generate responses, and saves and queries the user’s conversation thread ID to enable multi-turn dialogue context association, making interactions more natural and coherent.
Core Problems Addressed
Traditional simple chatbots lack context understanding and user memory, resulting in fragmented and discontinuous conversation experiences. This workflow solves session state management and historical context referencing by storing Telegram user IDs along with corresponding OpenAI conversation thread IDs in Supabase, thereby enhancing the chatbot’s intelligence and human-like interaction quality.
Application Scenarios
- Automated customer service bots capable of continuously tracking customer conversation context
- Virtual assistants providing personalized and continuous services and consultations
- Any Telegram chat application requiring intelligent responses based on historical conversation content
Main Process Steps
- Listen for Telegram Messages: Capture new user messages via the Telegram Trigger node.
- Query User Data: Use the Supabase node to check if the Telegram user already has an existing conversation thread.
- Conditional Logic: If the user exists, merge relevant data; if not, create a new OpenAI conversation thread and add a user record in Supabase.
- Send User Message to OpenAI: Forward the Telegram message text to the OpenAI thread.
- Execute OpenAI Assistant Task: Invoke the OpenAI assistant to generate an intelligent reply.
- Retrieve OpenAI Response: Fetch the generated reply content.
- Send Reply to Telegram: Deliver the OpenAI response back to the user’s Telegram chat window.
Involved Systems and Services
- Telegram: Chat platform for receiving and sending messages.
- OpenAI: Provides intelligent conversational capabilities, including thread creation, message sending, assistant execution, and response retrieval.
- Supabase: Hosts user data, storing Telegram user IDs alongside corresponding OpenAI conversation thread IDs to enable contextual memory.
- n8n Automation Platform: Orchestrates service nodes to automate the entire workflow.
Target Users and Value
- Developers and automation enthusiasts seeking to quickly build intelligent chatbots with contextual memory.
- Enterprise customer service teams aiming to implement smart customer communication and management via Telegram.
- Industries such as education, training, and consulting that require personalized and continuous chatbot dialogue experiences.
- Product managers and technical personnel looking to leverage OpenAI’s powerful language models to create humanized interactive products.
This workflow is developed and provided by Mark Shcherbakov based on the community project 5minAI. It includes accompanying video tutorials and detailed configuration guides to help users rapidly build intelligent Telegram conversational bots.