Skip to main content

Telegram bot with Supabase memory and OpenAI assistant integration

Workflow preview

Workflow preview
100%
Telegram bot with Supabase memory and OpenAI assistant integration preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

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://cflobdhpqwn...

Best for

  • Support Chatbot automation workflows
  • AI Chatbot automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.telegramtrigger, n8n-nodes-base.httprequest, n8n-nodes-base.supabase, n8n-nodes-base.merge, n8n-nodes-base.telegram, n8n-nodes-base.if, n8n-nodes-base.stickynote

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Mark Shcherbakov.

Original n8n.io source

1.1 Workflow description

Title
Telegram bot with Supabase memory and OpenAI assistant integration
Workflow name
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.

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 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'::text),
    telegram_id bigint null,
    openai_thread_id text null,
    constraint telegram_users_pkey primary key (id)
  ) tablespace pg_default;
  1. 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.
  2. 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.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Get New Message

Type / Role
n8n-nodes-base.telegramTrigger - telegramTrigger
Config choices
Version 1.1

Block 2 - OPENAI - Create thread

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 3 - Create User

Type / Role
n8n-nodes-base.supabase - supabase
Config choices
Version 1

Block 4 - Merge

Type / Role
n8n-nodes-base.merge - merge
Config choices
Version 3

Block 5 - OPENAI - Send message

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 6 - OPENAI - Run assistant

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 7 - OPENAI - Get messages

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 8 - Send Message to User

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 9 - If User exists

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.1

Block 10 - Find User

Type / Role
n8n-nodes-base.supabase - supabase
Config choices
Version 1

Block 11 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 12 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 13 - Sticky Note3

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 14 - Sticky Note4

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 15 - Sticky Note5

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 16 - Sticky Note6

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 17 - Sticky Note7

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

3. Summary Table

Workflow Telegram bot with Supabase memory and OpenAI assistant integration
Complexity advanced
Nodes 17
Categories Support Chatbot, AI Chatbot
Author Mark Shcherbakov
Published 06 Oct 2024

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/2453/2453.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Telegram bot with Supabase memory and OpenAI assistant integration do?

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://cflobdhpqwn...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Support Chatbot, AI Chatbot use case.