Telegram bot with Supabase memory and OpenAI assistant integrati
Video Guide I prepared a detailed guide that showed the whole process of building an AI bot, from the simplest version to the most complex in a template. .png)](https://www.youtube.com/watch?v=QrZxuWgFqBI)
Who is this for?
This workflow is ideal for developers, chatbot enthusiasts, and businesses looking to build a dynamic Telegram bot with memory capabilities. The bot leverages OpenAI's assistant to interact with users and stores user data in Supabase for personalized conversations.
What problem does this workflow solve?
Many simple chatbots lack context awareness and user memory. This workflow solves that by integrating Supabase to keep track of user sessions (via ```telegram_id``` and ```openai_thread_id```), allowing the bot to maintain continuity and context in conversations, leading to a more human-like and engaging experience.
What this workflow does
This Telegram bot template connects with OpenAI to answer user queries while storing and retrieving user information from a Supabase database. The memory component ensures that the bot can reference past interactions, making it suitable for use cases such as customer support, virtual assistants, or any application where context retention is crucial.
1.**Receive New Message:** The bot listens for incoming messages from users in Telegram. 2. **Check User in Database:** The workflow checks if the user is already in the Supabase database using the ```telegram_id```. 3. **Create New User (if necessary):** If the user does not exist, a new record is created in Supabase with the telegram_id and a unique ```openai_thread_id```. 4. **Start or Continue Conversation with OpenAI:** Based on the user’s context, the bot either creates a new thread or continues an existing one using the stored ```openai_thread_id```. 5. **Merge Data:** User-specific data and conversation context are merged. 6. **Send and Receive Messages:** The message is sent to OpenAI, and the response is received and processed. 7. **Reply to User:** The bot sends OpenAI’s response back to the user in Telegram.
Setup
- **Create a Telegram Bot** using the [Botfather](https://t.me/botfather) and obtain the bot token.
- **Set up Supabase:**
- 1. Create a new project and generate a ```SUPABASE_URL``` and ```SUPABASE_KEY```.
- 2. Create a new table named ```telegram_users``` with the following SQL query:
- ```
- create table
- public.telegram_users (
- id uuid not null default gen_random_uuid (),
- date_created timestamp with time zone not null default (now() at time zone 'utc'::text),
- telegram_id bigint null,
- openai_thread_id text null,
- constraint telegram_users_pkey primary key (id)
- ) tablespace pg_default;
- ```
- **OpenAI Setup:**
- 1. Create an OpenAI assistant and obtain the ```OPENAI_API_KEY```.
- 2. Customize your assistant’s personality or use cases according to your requirements.
- **Environment Configuration in n8n:**
- 1. Configure the Telegram, Supabase, and OpenAI nodes with the appropriate credentials.
- 2. Set up triggers for receiving messages and handling conversation logic.
- 3. Set up OpenAI assistant ID in "++OPENAI - Run assistant++" node.
⚡ How to import this workflow into n8n:
- Click the Direct Download JSON button above to save
Telegram_bot_with_Supabase_memory_and_OpenAI_assistant_integrati.json. - Log in to your n8n Cloud or self-hosted n8n instance.
- In your workflow canvas, click the menu in top-right and select Import from File (or paste the JSON directly).
- Configure your credentials (e.g. API keys, database URLs) in the corresponding node settings.
- Click Execute Workflow to test and switch to Active!
Related AI Agents Workflows
View All in AI Agents →5 ways to process images PDFs with Gemini AI in n8n
How it works Many users have asked in the support forum about different methods to analyze images and PDF documents with Google Gemini AI in n8n. This workfl...
7 AI Sales Assistant
Production-ready n8n automation template for 7 AI Sales Assistant built by AhiXLight. Seamlessly connects Airtop Tool, Slack, Airtop with 24 configured nodes.
AAVE portfolio professional AI agent Telegram Email GPT 4o
A next-generation AI-powered DeFi health monitor that tracks wallet positions across Aave V3 using GPT-4o and LangChain. It delivers human-readable reports v...
Access control for AI agents RBAC using Airtable and Telegram
Purpose This workflow allows granular control over the access to tools connected to AI Agents (including Multi-Agent setups) using Role Based Access Control....