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
- Telegram Bot API: Receives user messages.
- Supabase: Stores user data and openAI thread links.
- OpenAI API: Runs AI assistant and holds chat threads.
- n8n Automation Platform: Orchestrates all connections and data flow.
Beginner step-by-step: How to use this workflow inside n8n
Download and import workflow
- Click the Download button on this page to get the workflow file.
- In n8n editor, choose “Import from File” and select the downloaded workflow.
Configure credentials and settings
- Add your Telegram bot API key in n8n Credentials.
- Add your Supabase project URL and anon key as Supabase Credentials.
- Add your OpenAI API key and set your Assistant ID in the HTTP request nodes.
- Update table names, thread ID placeholders, or chat ID fields if you customized them.
Test and activate workflow
- Send a message to your Telegram bot to trigger the workflow.
- Check that the bot replies appropriately and data is saved in Supabase.
- Once testing is okay, activate the workflow to run in production.
- 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.
