Who is this for?
This workflow is perfect for developers, chatbot enthusiasts, and businesses interested in building a dynamic Telegram bot with memory capabilities. The bot uses OpenAI's assistant for interactions and integrates with Supabase to store user data, enabling personalized conversations.
What problem does this workflow solve?
Many basic chatbots lack memory and context awareness. This workflow solves that issue by integrating Supabase to track user sessions (using telegram_id
and openai_thread_id
), allowing the bot to remember past interactions, creating a more engaging and human-like experience.
What this workflow does
This Telegram bot template connects with OpenAI to respond to user queries while storing and retrieving user information from Supabase. The memory component allows the bot to reference previous interactions, making it suitable for customer support, virtual assistants, or any application where context retention is valuable.
- Receive New Message: The bot listens for incoming messages from users on Telegram.
- Check User in Database: Checks if the user exists in Supabase using
telegram_id
. - Create New User (if necessary): Adds a new user record in Supabase with
telegram_id
andopenai_thread_id
if the user is new. - Start or Continue Conversation with OpenAI: Initiates a new thread or continues an existing one using the stored
openai_thread_id
. - Merge Data: Combines user-specific data and conversation context.
- Send and Receive Messages: Sends the message to OpenAI and processes the response.
- Reply to User: Sends OpenAI's response back to the user on Telegram.
Setup
- Create a Telegram Bot using Botfather and get the bot token.
- Set up Supabase:
- Create a new project and obtain
SUPABASE_URL
andSUPABASE_KEY
. - 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;
- Create a new project and obtain
- OpenAI Setup:
- Create an OpenAI assistant and obtain the
OPENAI_API_KEY
. - Customize the assistant’s personality or use case as needed.
- Create an OpenAI assistant and obtain the
- Environment Configuration in rantir:
- Configure Telegram, Supabase, and OpenAI nodes with the required credentials.
- Set up triggers to receive messages and handle conversation logic.
- Input the OpenAI assistant ID in the "++OPENAI - Run assistant++" node.
Other Workflows like this one
Your connected stack awaits to automate AI workflows with 24-7 uptime performance and engagement