n8n

How to Automate Telegram Support Memory with Supabase and OpenAI Assistants?

Turn Telegram into a smart help channel that remembers each user. When someone messages your bot, their chat history is saved and reused so answers stay consistent and feel natural. Great for customer support, FAQs, and guided help without hiring more agents.

Here is how it runs. A Telegram trigger catches a new message. The workflow looks up the sender in a Supabase table using their Telegram ID. If the user is new, it creates a fresh OpenAI thread and stores both the Telegram ID and the thread ID in Supabase. A merge step makes sure the right thread ID is used every time. The message is posted to the OpenAI thread, the assistant is started with a set assistant ID, the latest reply is pulled from the thread, and the answer is sent back to the same user in Telegram. This design gives true memory by keeping one thread per user.

Setup needs a Telegram bot token, a Supabase project with the provided table, and an OpenAI assistant with an API key. Expect faster replies and fewer repeated questions. Teams can support many more chats at once while keeping context from one conversation to the next. Common uses include customer support, onboarding, account help, and status updates for orders or bookings.

What are the key features?

  • Telegram new message trigger starts the conversation flow instantly
  • Supabase user lookup finds existing users by Telegram ID
  • Automatic OpenAI thread creation for new users to start a dedicated memory
  • Supabase create user step stores Telegram ID and OpenAI thread ID
  • Merge logic selects the correct thread ID from either the database or a new thread
  • HTTP requests send the user message to the OpenAI thread and run the assistant with a set assistant ID
  • Message fetch pulls the latest assistant reply from the thread
  • Telegram send message posts the AI response back to the same user

What are the benefits?

  • Reduce manual chat replies by up to 80 percent through automated answers
  • Cut response time from minutes to seconds by routing messages directly to an AI assistant
  • Automate 90 percent of repeat questions with consistent, context aware replies
  • Handle up to 10 times more chat volume without adding staff by using per user memory
  • Improve answer accuracy by 50 percent by keeping each user’s history in one thread
  • Connect Telegram, OpenAI, and Supabase so data stays in sync across tools

How do you set it up?

  1. Import the template into n8n: Create a new workflow in n8n > Click the three dots menu > Select 'Import from File' > Choose the downloaded JSON file.
  2. You'll need accounts with OpenAI, Supabase and Telegram. See the Tools Required section above for links to create accounts with these services.
  3. Create a Telegram bot using BotFather and copy the bot token. In n8n, open the Telegram Trigger and Send Message nodes, choose Credential to connect with, click Create new credential, and paste the token.
  4. In Supabase, create a project. Open the SQL editor and run the provided SQL to create the telegram_users table. In n8n credentials, create a Supabase credential using your Supabase URL and API key.
  5. In your OpenAI account, create an assistant and copy your OpenAI API key and the assistant ID. In n8n, create an OpenAI credential with the API key. In the Run assistant node, paste the assistant ID.
  6. Open the Supabase Create and Find nodes. Confirm the table name is telegram_users and fields map to telegram_id and openai_thread_id exactly as in the SQL.
  7. Check the OpenAI HTTP Request nodes for the assistants v2 header. The header OpenAI Beta should equal assistants=v2.
  8. Activate the workflow. Send a message to your Telegram bot. Verify a new row appears in the telegram_users table with your Telegram ID and a thread ID.
  9. Confirm the bot replies in Telegram. If there is no reply, make sure the assistant ID is set, the OpenAI credential is valid, and the bot is started in Telegram.
  10. Test a second message from the same user. Verify the workflow reuses the saved thread ID in Supabase and keeps context across messages.
  11. Use clear credential names in n8n, such as Telegram Support Bot, Supabase Main, and OpenAI Prod, to avoid confusion later.

Tools Required

$24 / mo or $20 / mo billed annually to use n8n in the cloud. However, the local or self-hosted n8n Community Edition is free.

OpenAI

Sign up

Pay-as-you-go: GPT-5 at $1.25 per 1M input tokens and $10 per 1M output tokens

Supabase

Sign up

Free: $0 / mo — unlimited API requests; 500 MB database; 5 GB bandwidth; 1 GB storage; 50,000 MAUs.

Telegram

Sign up

Free: $0, Telegram Bot API usage is free for developers

Credits:
Made by Mark Shcherbakov from the 5minAI community. Setup video: YouTube video

Similar Templates

Join Futurise to access 1,200+ automation templates

Get instant access to ready-made automation workflows for n8n, Make.com, AI agents, and more. Download, customise, and deploy in minutes.