Create a Multi-Model AI Chatbot with Telegram, AIMLAPI, and Google Sheets

Go to Workflow
0 views
Built by AI/ML API | D1m7asis AI/ML API | D1m7asis
Created on June 07, 2026

Description

๐Ÿ“ฒ 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

1. ๐Ÿ“ฒ Create a Telegram Bot

Go to @BotFather
Use /newbot โ†’ Set name & username.
Copy the generated API token.

2. ๐Ÿ” Add Telegram Credentials to n8n

Go to n8n > Credentials > Telegram API.
Create a new credential with the BotFather token.

3. ๐Ÿ“— 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).

4. ๐Ÿ”Œ Connect AIMLAPI

Get your API key from AIMLAPI.
In n8n > Credentials, add AI/ML API:
API Key: your_key_here.

5. โš™๏ธ 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.

Nodes Used (4)

Code
n8n-nodes-base.code
Google Sheets
n8n-nodes-base.googleSheets
HTTP Request
n8n-nodes-base.httpRequest
Telegram
n8n-nodes-base.telegram