Telegram Bot with Supabase memory and OpenAI assistant integration n8n Workflow Template

n8n workflow template · 10 nodes · Telegram

Telegram Bot with Supabase memory and OpenAI assistant integration is a free n8n workflow template that starts from the Telegram Trigger node and works with Telegram and Supabase. It has 10 nodes and no AI nodes. The notes inside the workflow say: “Many simple chatbots lack context awareness and user memory.” To run it, you add your own credentials for OpenAI API, Supabase API and Telegram Bot API.

At a glance

Trigger
Telegram Trigger (Get New Message)
Nodes
10
Apps
Telegram and Supabase
AI nodes
None
Credentials
3 types
Category
Chatbots and messaging

Apps and integrations

  • Telegram
  • Supabase

Node types used

  • Telegram Trigger
  • HTTP Request
  • Supabase
  • Merge
  • Telegram
  • If

How it works

The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.

AI Telegram Bot with Supabase memory

Made by Mark Shcherbakov from community 5minAI

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.

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.

Create own Telegram bot in Botfather bot

Create table in Supabase with SQL query

SQL query to create table in Supabase

Create assistant in OpenAI.

Specify own assistant id here

Setup notes

The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.

Set up steps

  1. Create a Telegram Bot using the Botfather and obtain the bot token.
  2. Set up Supabase
  3. Create a new project and generate a SUPABASE_URL and SUPABASE_KEY.
  4. Create a new table named telegram_users with the following SQL query
  1. OpenAI Setup
  2. Create an OpenAI assistant and obtain the OPENAI_API_KEY.
  3. Customize your assistant’s personality or use cases according to your requirements.
  4. Environment Configuration in n8n
  5. Configure the Telegram, Supabase, and OpenAI nodes with the appropriate credentials.
  6. Set up triggers for receiving messages and handling conversation logic.
  7. Set up OpenAI assistant ID in "++OPENAI - Run assistant++" node.

... or watch set up video [5 min]

Nodes in this workflow

The 10 nodes in file order (sticky notes excluded). Branches and connections determine execution order in n8n:

  1. Get New Message (Telegram Trigger)
  2. OPENAI - Create thread (HTTP Request)
  3. Create User (Supabase)
  4. Merge (Merge)
  5. OPENAI - Send message (HTTP Request)
  6. OPENAI - Run assistant (HTTP Request)
  7. OPENAI - Get messages (HTTP Request)
  8. Send Message to User (Telegram)
  9. If User exists (If)
  10. Find User (Supabase)

Credentials you need

  • OpenAI API – used by OPENAI - Create thread, OPENAI - Get messages, OPENAI - Run assistant and OPENAI - Send message
  • Supabase API – used by Create User and Find User
  • Telegram Bot API – used by Get New Message and Send Message to User

Configure your own credentials after importing. Create each credential in n8n, then select it in the node.

How to import into n8n

  1. Download the JSON file with the button above.
  2. In n8n, open a new workflow, select the ... menu and choose Import from File. You can also paste the JSON straight into the editor canvas.
  3. Open each node that shows a warning and select or create its credential.
  4. Read the notes on the canvas, test the workflow with sample data, then activate it.

Do you need somewhere to run it? Read our guide to self-hosted n8n.

Need this customised?

We can adapt this workflow to your apps, data and process, then deploy and support it.

Contact Us