Build an AI Telegram Bot with n8n, Supabase & OpenAI

This workflow automates Telegram bot conversations using OpenAI and Supabase to remember user sessions, enabling context-aware interactions. It solves the common problem of chatbots lacking memory for seamless user experience.
telegramTrigger
supabase
httpRequest
+3
Workflow Identifier: 1211
NODES in Use: Telegram Trigger, Supabase, If, Merge, HTTP Request, Telegram
Automate Telegram bot conversations with n8n and OpenAI

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

What this workflow does

This workflow connects Telegram, OpenAI assistant API, and Supabase to make a smart bot that remembers users and conversations.

It stops the bot asking the same questions over and over.

Users get quicker, more helpful answers because the bot keeps track of past chats.

The bot talks to many users at once without mixing up their conversations.


Who should use this workflow

People running Telegram channels with lots of users who want better support.

Anyone needing their bot to remember chat history across sessions.

Those wanting an easy way to add AI chat that feels personal.


Tools and services used


Beginner step-by-step: How to use this workflow inside n8n

Download and import workflow

  1. Click the Download button on this page to get the workflow file.
  2. In n8n editor, choose “Import from File” and select the downloaded workflow.

Configure credentials and settings

  1. Add your Telegram bot API key in n8n Credentials.
  2. Add your Supabase project URL and anon key as Supabase Credentials.
  3. Add your OpenAI API key and set your Assistant ID in the HTTP request nodes.
  4. Update table names, thread ID placeholders, or chat ID fields if you customized them.

Test and activate workflow

  1. Send a message to your Telegram bot to trigger the workflow.
  2. Check that the bot replies appropriately and data is saved in Supabase.
  3. Once testing is okay, activate the workflow to run in production.
  4. Consider consulting self-host n8n options for reliable workflow hosting.

Workflow Inputs, Processing, and Outputs

Inputs

  • New Telegram messages received via the Telegram trigger node.
  • User’s Telegram chat ID to identify each user.
  • Stored user data and openAI thread IDs from Supabase.

Processing Steps

  • Check Supabase if a user record for the Telegram ID exists.
  • If missing, create a new OpenAI chat thread and save it with user data in Supabase.
  • Send the latest user message to OpenAI under the correct thread.
  • Run the OpenAI assistant to process messages and generate a reply.
  • Fetch the assistant’s reply from OpenAI’s messages endpoint.

Outputs

  • Send the assistant’s reply back to the same Telegram chat.
  • Maintain updated chat context for each user in Supabase for future messages.

Edge cases and handling failures

  • If Supabase query finds no or multiple users, check your query condition and database uniqueness.
  • OpenAI API key issues cause authentication failures. Update API keys in n8n credentials if needed.
  • Telegram messages not sending often mean wrong chat IDs or inactive bots. Verify chat ID matches sender ID and bot is live.

Customization ideas

  • Change assistant personality by editing it on OpenAI and updating the assistant ID in the HTTP node.
  • Add filters to process only particular keywords or commands before sending to OpenAI.
  • Save extra user info like Telegram usernames or preferences by adding columns in Supabase.
  • Add error logging with Slack or email nodes to track workflow issues.

Summary of results

✓ Users get replies that remember past conversations.

✓ Bot saves time by not asking repeated questions.

✓ Multiple users handled without losing chat context.

✓ Saves time and improves user satisfaction in chat support.


Automate Telegram bot conversations with n8n and OpenAI

Visit through Desktop to Interact with the Workflow.

Frequently Asked Questions

Yes, each user’s chat is stored separately in Supabase, so the workflow keeps conversations distinct.
It stores an OpenAI thread ID for each Telegram user in Supabase and uses this to send messages contextually.
The workflow fails to authenticate with OpenAI, causing assistant responses to stop. The API key must be checked and updated.
Yes, but node configurations and queries must be adjusted since this workflow is built for Supabase.

Promoted by BULDRR AI

Related Workflows

Automate Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.