Qwen Code Telegram MCP Server
MCP server integrating Telegram bot with Qwen Code for AI chat, supporting persistent sessions, group chat, and advanced features via mention-based triggers.
README
Qwen Code Telegram MCP Server
Version: v2.2.0
MCP Server for Telegram Bot integration with Qwen Code. Chat with Qwen Code directly from Telegram with persistent sessions, group chat support, and advanced features.
๐ Features
Core Features
- ๐ค Telegram Bot Integration - Full Telegram Bot API via long polling
- ๐ MCP Protocol Support - Native integration with Qwen Code
- ๐ฌ Persistent Sessions - File-based conversation history (survives restarts)
- ๐ Pairing System - 6-digit code security for access control
- โจ๏ธ Typing Indicators - Better UX while processing
- ๐ Admin Commands - Session management and monitoring
- ๐งน Auto-Cleanup - Automatic maintenance for old sessions
- ๐ง Dynamic Configuration - Workspace-specific settings
v2.2.0 New Features
- ๐ฅ Group Chat Support - Bot works in groups without crashes!
- ๐ข Mention-Based Trigger - Bot responds only when mentioned (
@bot_name) - ๐ญ Quoted Message Context - Bot reads reply/quote messages
- ๐ Silent Ignore - No spam in groups (ignores non-mentions)
- ๐ฏ Smart Reply - Auto-reply to original message for better UX
- ๐ Metrics Tracking - Request count and token usage monitoring
๐ Quick Start
For Qwen Code Users (Vibe Coding)
๐ฏ EASIEST METHOD: Let your LLM agent handle everything!
After cloning this repository, simply tell your Qwen Code:
@qwen Read and implement VIBE-INSTALL.md for installation,
then VIBE-CONFIG.md for configuration. Ask me for confirmation
before any sensitive data.
Your LLM agent will:
- โ Install all dependencies automatically
- โ Build the TypeScript project
- โ Guide you through Telegram bot creation
- โ Configure Qwen Code MCP settings
- โ Test everything works
๐ Vibe Coding Guides:
- ๐ฆ VIBE-INSTALL.md - Automated installation
- โ๏ธ VIBE-CONFIG.md - Automated configuration
- ๐ ๏ธ VIBE-REPAIR.md - Automated troubleshooting
Special Note from the Human This is the only section touched by human. Everything in this MCP is vibe-coded but safely structured. If something messed up, simply run your agent. It will do the complex thing for you. Wanted new features? Ask your agent.
My agent clears the path. Yours should follow. -JavaIsKey
Manual Installation
Prerequisites
- Node.js >= 18.x
- npm >= 9.x
- Git
Steps
- Clone repository
git clone https://github.com/YOUR_USERNAME/qwen-code-telegram-mcp.git
cd qwen-code-telegram-mcp
- Install dependencies
npm install
- Build TypeScript
npm run build
- Setup environment
cp .env.example .env
# Edit .env with your configuration
- Configure Qwen Code
Add to ~/.qwen/settings.json:
{
"mcpServers": {
"telegram": {
"command": "node",
"args": ["[YOUR_PATH]/dist/index.js"],
"env": {
"TELEGRAM_BOT_TOKEN": "${TELEGRAM_BOT_TOKEN}",
"WORKSPACE_PATH": "[YOUR_WORKSPACE_PATH]"
}
}
}
}
- Start Qwen Code
npx qwen
- Chat with your bot on Telegram!
๐ฑ Telegram Bot Setup
Create New Bot
- Open Telegram โ Search
@BotFather - Send
/newbot - Follow instructions:
- Choose name:
My Assistant - Choose username:
my_assistant_bot
- Choose name:
- Copy the bot token (format:
123456789:ABCdef...)
โ ๏ธ IMPORTANT: Disable Privacy Mode
For group chat support:
- @BotFather โ
/setprivacy - Select your bot
- Choose: "Disable privacy"
Without this, bot won't read group messages!
๐ฎ Usage
Private Chat
Just send message to bot:
User: Hello
Bot: [AI response from Qwen Code]
Group Chat
Must mention bot:
User: @my_bot_name What's the capital of France?
Bot: [AI response]
User: hello everyone
Bot: [Ignored - no mention]
With quoted message:
User 1: [sends message] "This is important"
User 2: [reply] @my_bot_name summarize this
Bot: [Reads quoted message + instruction]
๐ Available Commands
User Commands
/start- Welcome message + pairing instructions/help- Help information/status- Server status/session- Your session info/clear- Clear your session/whoami- Your Telegram info/ask <question>- Ask Qwen Code directly/pair <CODE>- Pair bot with code/approvalmode [mode]- Set approval mode (plan/auto-accept/yolo)
Admin Commands
/sessions- List all active sessions
๐ Pairing System
How It Works
- User messages bot - Bot checks if user is paired
- Admin generates code - Via MCP tool:
generate_telegram_pairing_code - User pairs - User runs:
/pair ABC123 - Access granted - User now has access
Pairing Code Properties
- 6 characters (uppercase alphanumeric)
- Valid for 15 minutes
- One-time use
- Auto-cleanup when expired
๐ Project Structure
qwen-code-telegram-mcp/
โโโ src/
โ โโโ index.ts # Main code (2300+ lines)
โโโ dist/
โ โโโ index.js # Compiled code
โโโ .env # Environment config
โโโ .env.example # Example config
โโโ package.json # Dependencies
โโโ tsconfig.json # TypeScript config
โโโ README.md # This file
โโโ DOCUMENTATION.md # Detailed documentation
โโโ VIBE-INSTALL.md # LLM agent installation guide
โโโ VIBE-CONFIG.md # LLM agent configuration guide
โโโ VIBE-REPAIR.md # LLM agent troubleshooting guide
Workspace/
โโโ temp/
โ โโโ telegram-bot.log # Runtime log
โ โโโ telegram-sessions/
โ โโโ {chatId}.json # User sessions
โ โโโ allowlist.json # Paired users
โ โโโ approval-modes.json # Approval modes
โโโ .qwen/
โโโ commands/
โโโ *.md # Custom commands
โ๏ธ Configuration
Environment Variables
Copy .env.example to .env and configure:
# Telegram Bot Configuration
TELEGRAM_BOT_TOKEN=your_bot_token_here
# Workspace Configuration
WORKSPACE_PATH=/path/to/your/workspace
# MCP Server Configuration
MCP_SERVER_PORT=3000
MCP_TRANSPORT=stdio
Session Settings
| Setting | Default | Description |
|---|---|---|
MAX_CONVERSATION_HISTORY |
50 | Max messages per session |
INACTIVE_CHAT_TIMEOUT_MS |
86400000 | Session expiry (24h) |
๐ ๏ธ Development
# Build TypeScript
npm run build
# Run development mode
npm run dev
# Run production
npm start
๐ Troubleshooting
Bot not responding
Check:
- Bot token valid? โ @BotFather
- Bot running in Qwen Code?
- Privacy mode disabled? โ
/setprivacy
Session not saving
Check:
WORKSPACE_PATHcorrect?- Folder has write permission?
temp/telegram-sessions/exists?
Pairing code not working
Check:
- Code not expired (15 min only)
- Code entered correctly (uppercase)
- User in allowlist?
Need Help?
๐ See VIBE-REPAIR.md for comprehensive troubleshooting guide!
๐ Metrics Tracking
Bot automatically tracks:
totalRequests- Total message counttotalErrors- Error counttokens.total- Estimated token usagetokens.prompt- Input tokenstokens.output- Output tokens
View with: /status command
๐งช Testing Checklist
Basic Functionality
- [ ] DM:
helloโ AI response - [ ] Group:
@bot_name testโ AI response - [ ] Group:
test(no mention) โ Ignored - [ ] Custom command:
/healthโ Executed
Sessions
- [ ] Session file created
- [ ] Session persists after restart
- [ ]
/cleardeletes session - [ ]
/sessionshows correct info
Pairing
- [ ] Unpaired โ Access denied
- [ ] Generate code โ Works
- [ ]
/pair ABC123โ Success - [ ] Invalid code โ Rejected
Files
- [ ] Send document โ Processed
- [ ] Send photo โ Downloaded
- [ ]
send_telegram_fileโ Works
Logging
- [ ] Log file created
- [ ] Messages logged
- [ ] Errors logged
- [ ] No infinite loops
๐ Version History
v2.2.0 (Current)
- โ Full group chat support
- โ Mention-based triggering
- โ Quoted message context
- โ Telegram auto-correct handling
- โ Metrics tracking
v2.1
- Multi-bot support via workspace-specific MCP config
v2.0
- Persistent sessions
- Pairing system
- Typing indicators
- Admin commands
v1.0
- Initial release with basic MCP integration
๐ Documentation
- VIBE-INSTALL.md - LLM agent installation guide
- VIBE-CONFIG.md - LLM agent configuration guide
- VIBE-REPAIR.md - LLM agent troubleshooting guide
- DOCUMENTATION.md - Detailed technical documentation
- CONTRIBUTING.md - Contribution guidelines
- CODE_OF_CONDUCT.md - Code of conduct
๐ค Contributing
Contributions welcome! Please read CONTRIBUTING.md first.
Quick Contributing
- Fork repository
- Create branch:
git checkout -b feature/your-feature - Make changes
- Test thoroughly
- Submit PR
๐ License
ISC License - see LICENSE file.
๐ Support
For Issues:
- Check VIBE-REPAIR.md first
- Review logs:
temp/telegram-bot.log - Create GitHub issue with:
- Error message
- What you were doing
- Your environment (Node.js, OS)
For Questions:
- Create GitHub Discussion
- Check DOCUMENTATION.md
๐ฏ Why Vibe Coding?
This project is designed for Qwen Code vibe coding:
- โ LLM-Friendly Setup - VIBE-* guides for automated installation
- โ Zero Configuration - LLM agent handles everything
- โ Smart Troubleshooting - VIBE-REPAIR for automated fixes
- โ User Confirmation - Sensitive data requires user approval
- โ Well Documented - Every step clearly explained
Just clone and let your LLM agent do the work! ๐
Built with โค๏ธ for Qwen Code
Last updated: 2026-03-26
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.