A self-hosted Telegram AI bot with Google Gemini & OpenAI-compatible APIs.
Deploy in 60 seconds with one click — no coding required.
| Feature | Details |
|---|---|
| 🧠 Multi-model AI | Google Gemini 2.0 Flash, 1.5 Pro, 1.5 Flash + any OpenAI-compatible provider |
| 🔄 Model switching | /model — swap between AI models instantly via inline keyboard |
| 🎭 System prompts | /prompt — Default, Professional, Creative presets or write your own |
| 🖼️ Image understanding | Send photos — the bot analyzes and describes them |
| 💬 Conversation history | Remembers context within each session |
| 👥 Group chat support | Works in groups and supergroups; shared or per-user history |
| 🔒 Access control | Restrict to specific users or groups to protect your API keys |
| 🌐 Any OpenAI-compatible API | OpenRouter, Groq, Together AI, Mistral, self-hosted LLMs |
| ⚡ One-click deploy | Vercel, Railway, or Render — no server required |
3 steps — under 60 seconds:
- Click Deploy with Vercel above → fill in your API keys when prompted
- Visit your deployment URL → click Set Webhook on the setup page
- Open your bot in Telegram → send
/start
⚠️ SetALLOWED_USERSto your Telegram ID during deploy to protect your API keys from abuse. Send/get_my_infoto the bot to find your ID.
| Command | Description |
|---|---|
/start |
Welcome message and quick help |
/new |
Start a fresh conversation |
/model |
Switch AI model via inline keyboard |
/prompt |
Change system prompt (presets + custom) |
/get_my_info |
Get your Telegram user ID |
/get_group_info |
Get the group chat ID (groups only) |
/help |
Show full help message |
Admin-only (requires ADMIN_ID + IS_DEBUG_MODE=1):
| Command | Description |
|---|---|
/get_allowed_users |
List authorized users |
/get_allowed_groups |
List authorized groups |
/get_api_keys |
Show API key status |
/list_models |
List configured models |
| Preset | Description |
|---|---|
| 🤖 Default | Friendly, concise AI assistant |
| 💼 Professional | Expert consultant with structured answers |
| ✨ Creative | Imaginative partner with vivid storytelling |
| ✏️ Custom | Type your own system prompt |
| Provider | Type | Base URL |
|---|---|---|
| Google Gemini | Gemini API | (built-in) |
| OpenAI | OpenAI-compatible | https://api.openai.com/v1 |
| OpenRouter | OpenAI-compatible | https://openrouter.ai/api/v1 |
| Groq | OpenAI-compatible | https://api.groq.com/openai/v1 |
| Together AI | OpenAI-compatible | https://api.together.xyz/v1 |
| Mistral | OpenAI-compatible | https://api.mistral.ai/v1 |
| Self-hosted (Ollama, LM Studio, etc.) | OpenAI-compatible | Your server URL |
| Variable | Description |
|---|---|
BOT_TOKEN |
Your Telegram bot token from @BotFather |
GOOGLE_API_KEY |
Google Gemini API key from Google AI Studio |
| Variable | Description |
|---|---|
ALLOWED_USERS |
Comma-separated Telegram user IDs or @usernames. Set this to prevent strangers from draining your API quota. |
AUCH_ENABLE |
1 = only allowed users can chat (default), 0 = open to everyone |
| Variable | Description | Default |
|---|---|---|
OPENAI_API_KEY |
API key for any OpenAI-compatible provider | — |
OPENAI_BASE_URL |
Provider base URL | https://api.openai.com/v1 |
| Variable | Description | Default |
|---|---|---|
DEFAULT_MODEL |
Model used for new conversations | gemini-2.0-flash |
GEMINI_MODELS |
Comma-separated Gemini models | gemini-2.0-flash,gemini-1.5-pro,gemini-1.5-flash |
OPENAI_MODELS |
Comma-separated OpenAI-compat models | gpt-4o,gpt-4o-mini |
| Variable | Description | Default |
|---|---|---|
ADMIN_ID |
Your Telegram user ID — enables admin commands | — |
IS_DEBUG_MODE |
1 = send debug logs to admin |
0 |
GROUP_MODE |
1 = shared group history, 2 = per-user history in groups |
1 |
Method 1 — Use this bot:
Send /get_my_info to your bot after deploying — it replies with your user ID.
Method 2 — Use @userinfobot: Open it on Telegram and send any message — it replies instantly with your ID.
For group chat IDs:
Add your bot to the group and send /get_group_info — the bot replies with the group ID (a negative number like -1001234567890). Add it to ALLOWED_GROUPS.
- Fork this repository
- Create a new Railway project → Deploy from GitHub repo
- Add environment variables in the Railway dashboard
- Set start command:
flask --app api.index run --host 0.0.0.0 --port $PORT - Set your webhook URL to the Railway domain
- Fork this repository
- Create a new Web Service on Render
- Set Build Command:
pip install -r requirements.txt - Set Start Command:
flask --app api.index run --host 0.0.0.0 --port $PORT - Add environment variables and set your webhook to the Render domain
Telegram ──webhook──► Flask on Vercel / Railway / Render
│
┌──────────┴──────────┐
▼ ▼
handle_message handle_callback
│ │
┌─────────┴──────┐ user_settings
▼ ▼ (model + prompt)
text/photo commands
│
ChatManager
(per-session history)
│
┌─────┴──────┐
▼ ▼
Gemini API OpenAI-compatible API
Chat history is in-memory and resets on cold start (expected on serverless). Use
/newto clear history manually.
Send this to @BotFather using /setcommands:
start - Start the bot
new - Start a fresh conversation
model - Switch AI model
prompt - Change system prompt
get_my_info - Get your Telegram ID
get_group_info - Get group ID
help - Show help
If this project helped you, please star the repo — it helps others find it!
MIT — free to use, modify, and deploy.