Create a Multi-Model AI Chatbot with Telegram, AIMLAPI, and Google Sheets
π² AI Multi-Model Telegram Chatbot (n8n + AIMLAPI)
This n8n workflow enables Telegram users to interact with multiple AI models dynamically using #model_id commands. It also supports a /models command to list all available models. Each user has a daily usage limit, tracked via Google Sheets.
π Key Features
Dynamic Model Selection:** Users choose models on-the-fly via #model_id (e.g., #openai/gpt-4o). /models Command:** Lists all available models grouped by provider. Daily Limit Per User:** Enforced using Google Sheets. Prompt Parsing:** Extracts model and message from user input. Logging:** Logs every request & result into Google Sheets for usage tracking. Seamless Telegram Delivery:** Responses are sent directly back to the chat.
π Setup Guide
- π² Create a Telegram Bot
Go to @BotFather Use /newbot β Set name & username. Copy the generated API token.
- π Add Telegram Credentials to n8n
Go to n8n > Credentials > Telegram API. Create a new credential with the BotFather token.
- π Google Sheets Setup
Create a Google Sheet named Sheet1. Add columns: user_id | date | query | result Share the sheet with your Service Account or OAuth Email (depending on auth method).
- π Connect AIMLAPI
Get your API key from AIMLAPI. In n8n > Credentials, add AI/ML API: API Key: your_key_here.
- βοΈ Customize Limits & Enhancements
Adjust daily limits in the Set Daily Limit node. Optional: Add NSFW content filtering. Implement alias commands. Extend with /help, /usage, /history. Add inline button UX (advanced).
π‘ How It Works
β‘οΈ Command Examples:
Start a chat with a specific model: #openai/gpt-4o Write a motivational quote. Request available models list: /models β‘οΈ Workflow Logic:
Receives a Telegram message.
Switch node checks if the message is /models or a prompt.
For /models, it fetches and sends a grouped list of models.
For prompts: Checks usage limits. Parses #model_id and prompt text. Dynamically routes the request to the chosen model. Sends the AI's response back to the user. Logs the query & result to Google Sheets.
If daily limit exceeded β sends a limit exceeded message.
π§ͺ Testing & Debugging Tips
Test via a separate Telegram chat. Use Console/Set nodes to debug payloads. Always test commands by messaging the bot (not via "Execute Node"). Validate cases: Missing #model_id. Invalid model_id. Limit exceeded handling.
Related Templates
Use OpenRouter in n8n versions <1.78
What it is: In version 1.78, n8n introduced a dedicated node to use the OpenRouter service, which lets you to use a lot...
Task Deadline Reminders with Google Sheets, ChatGPT, and Gmail
Intro This template is for project managers, team leads, or anyone who wants to automatically remind teammates of tasks ...
π€ Build Resilient AI Workflows with Automatic GPT and Gemini Failover Chain
This workflow contains community nodes that are only compatible with the self-hosted version of n8n. How it works This...
π Please log in to import templates to n8n and favorite templates
Workflow Visualization
Loading...
Preparing workflow renderer
Comments (0)
Login to post comments