Telegram Bot with Supabase Memory and OpenAI Assistant Integration

### 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. [![Youtube thumb 3.png](https://cflobdhpqwnoisuctsoc.supabase.co/storage/v1/object/public/my_storage/Youtube%20thumb%20(3).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 1. **Create a Telegram Bot** using the [Botfather](https://t.me/botfather) and obtain the bot token. 2. **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'), telegram_id bigint null, openai_thread_id text null, constraint telegram_users_pkey primary key (id) ) tablespace pg_default; ``` 3. **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. 4. **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.

n8n
Telegram Bot with Supabase Memory and OpenAI Assistant Integration
$14.99
Last updated September 5, 2026
30-day money-back guarantee
Instant download
Lifetime updates included

New buyers can create an account from the cart to unlock a controlled $10 first-purchase credit on eligible orders of $25+.

Secure checkout powered by Stripe

Support

How to import this workflow into n8n

  1. 1Purchase or download the workflow to get the n8n workflow JSON file.
  2. 2In your n8n instance, open Workflows and choose "Import from File" (or paste the JSON with Ctrl+V on the canvas).
  3. 3Open each node marked with a credential warning and connect your own accounts and API keys.
  4. 4Run the workflow once manually to verify the data flow, then toggle it to Active.

Related AI workflows

More from Mark Shcherbakov

Need this deployed? We'll set it up for you.

Our automation experts deploy this workflow in your stack, connect your accounts, and verify it works — or build a custom solution from scratch.