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

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

Learn how to Build this Workflow with AI:

Visit through Desktop for Best experience

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.


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 Viral UGC Video Creation Using n8n + Degaus (Beginner-Friendly Guide)

Learn how to automate viral UGC video creation using n8n, AI prompts, and Degaus. This beginner-friendly guide shows how to import, configure, and run the workflow without technical complexity.
Form Trigger
Google Sheets
Gmail
+37
Free

AI SEO Blog Writer Automation Workflows in n8n

A complete beginner guide to building an AI SEO blog writer automation using n8n.
AI Agent
Google Sheets
httpRequest
+5
Free

Automate CrowdStrike Alerts with VirusTotal, Jira & Slack

This workflow automates processing of CrowdStrike detections by enriching threat data via VirusTotal, creating Jira tickets for incident tracking, and notifying teams on Slack for quick response. Save hours daily by transforming complex threat data into actionable alerts effortlessly.
scheduleTrigger
httpRequest
jira
+5
Free

Automate Telegram Invoices to Notion with AI Summaries & Reports

Save hours on financial tracking by automating invoice extraction from Telegram photos to Notion using Google Gemini AI. This workflow extracts data, records transactions, and generates detailed spending reports with charts sent on schedule via Telegram.
lmChatGoogleGemini
telegramTrigger
notion
+9
Free

Automate Email Replies with n8n and AI-Powered Summarization

Save hours managing your inbox with this n8n workflow that uses IMAP email triggers, AI summarization, and vector search to draft concise replies requiring minimal review. Automate business email processing efficiently with AI guidance and Gmail integration.
emailReadImap
vectorStoreQdrant
emailSend
+12
Free

Automate Email Campaigns Using n8n with Gmail & Google Sheets

This n8n workflow automates personalized email outreach campaigns by integrating Gmail and Google Sheets, saving hours of manual follow-up work and reducing errors in email sequences. It ensures timely follow-ups based on previous email interactions, optimizing communication efficiency.
googleSheets
gmail
code
+5
Free