English | ็ฎไฝไธญๆ | ็น้ซไธญๆ | ๆฅๆฌ่ช | Espaรฑol | Franรงais | ะ ัััะบะธะน | Deutsch
GPT-Telegram-Bot is a powerful Telegram bot that integrates various AI models, providing intelligent conversations, image generation and analysis capabilities.
- Multi-model Support ๐ญ: Any model compatible with OpenAI API, Google Gemini, Anthropic Claude, Groq, and Azure OpenAI
- Intelligent Conversations ๐ฌ: Natural language interactions with context memory support
- Image Generation ๐จ: Create images based on text descriptions
- Image Analysis ๐: Interpret and describe uploaded images
- Multilingual Support ๐: Localization support for multiple languages
- Stream Response โก: Real-time generation and display of AI replies
- User Whitelist ๐: Can be set to allow access only to specific users
- OpenAI Series: Powerful language models ๐
- Google Gemini: Google's next-generation AI model ๐งโ๐ฌ
- Anthropic Claude: Another powerful language model choice ๐ญ
- Groq: High-speed inference AI model โก
- Azure OpenAI: Microsoft-hosted OpenAI service ๐
GPT-Telegram-Bot/
โโโ api/ # API related configurations
โ โโโ telegram.js # Handle Telegram bot interactions
โโโ src/ # Source code
โ โโโ bot.js # Main Telegram bot logic
โ โโโ api.js # Handle API interactions
โ โโโ config.js # Configuration file
โ โโโ uploadhandler.js # Handle image uploads
โ โโโ redis.js # Upstash Redis database functionality
โโโ locales/ # Multilingual support files
โโโ package.json # Project dependencies
โโโ vercel.json # Vercel configuration file
โโโ .gitignore # Git ignore file
api/telegram.js
: Handles webhook requests from Telegramsrc/bot.js
: Contains main bot logic and command processingsrc/api.js
: Manages API interactions with different AI servicessrc/config.js
: Stores project configurations and environment variablessrc/uploadhandler.js
: Handles image upload and analysis functionalitysrc/redis.js
: Manages interactions with Upstash Redis, used for storing conversation historylocales/
: Contains translation files for different languages, supporting multilingual functionality
- Vercel account
- Telegram account and Bot Token
- Upstash Please select the Redis database and enable the Eviction feature
- API key for at least one AI service
-
Clone the repository:
git clone https://github.com/snakeying/GPT-Telegram-Bot.git cd GPT-Telegram-Bot
-
Install dependencies:
npm install
-
Configure environment variables: Create a
.env
file and fill in the necessary configuration information (refer to the environment variable configuration below). -
Deploy to Vercel:
- Fork this repo
- Modify according to the instructions at the bottom of the readme
- Click the "Deploy with Vercel" button
- Connect your GitHub repository
- Configure environment variables
- Complete deployment
-
Set up Telegram Webhook: After deployment, use the following URL to set up the Webhook:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook?url=<YOUR_VERCEL_DOMAIN>/api/telegram
Before deploying and running GPT-Telegram-Bot, you need to set the following environment variables. Create a .env
file in the project root directory and configure the following variables:
Variable Name | Description | Default Value |
---|---|---|
OPENAI_API_KEY |
OpenAI API key | - |
OPENAI_BASE_URL |
OpenAI API base URL | https://api.openai.com/v1 |
OPENAI_MODELS |
OpenAI models to use (comma-separated) | - |
DEFAULT_MODEL |
Default model to use | First model in OPENAI_MODELS |
AZURE_OPENAI_API_KEY |
Azure OpenAI API key | - |
AZURE_OPENAI_ENDPOINT |
Azure OpenAI endpoint | - |
AZURE_OPENAI_MODELS |
Azure OpenAI models to use (comma-separated) | - |
TELEGRAM_BOT_TOKEN |
Telegram Bot Token | - |
WHITELISTED_USERS |
Allowed user IDs (comma-separated) | - |
DALL_E_MODEL |
DALL-E model to use | dall-e-3 |
UPSTASH_REDIS_REST_URL |
Upstash Redis REST URL | - |
UPSTASH_REST_TOKEN |
Upstash Redis REST Token | - |
SYSTEM_INIT_MESSAGE |
System initialization message | You are a helpful assistant. |
SYSTEM_INIT_MESSAGE_ROLE |
System message role | system |
GEMINI_API_KEY |
Google Gemini API key | - |
GOOGLE_MODELS |
Google models to use (comma-separated) | - |
GEMINI_ENDPOINT |
Gemini API endpoint | https://generativelanguage.googleapis.com/v1beta/models |
GROQ_API_KEY |
Groq API key | - |
GROQ_MODELS |
Groq models to use (comma-separated) | - |
MAX_HISTORY_LENGTH |
Maximum history length | 50 |
CLAUDE_API_KEY |
Anthropic Claude API key | - |
CLAUDE_MODELS |
Claude models to use (comma-separated) | - |
CLAUDE_ENDPOINT |
Claude API endpoint | https://api.anthropic.com/v1/chat/completions |
Make sure to add these environment variables to your project's environment configuration when deploying to Vercel or other platforms.
/start
- Initialize the bot/new
- Start a new conversation/history
- View conversation history/help
- Get help information/switchmodel <model name>
- Switch AI model/img <description> [size]
- Generate image/language <language code>
- Switch interface language- Send an image for analysis
- Send a message directly for conversation
Supported languages (use /language command):
- English (en)
- Simplified Chinese (zh-cn)
- Traditional Chinese (zh-hant)
- Japanese (ja)
- Spanish (es)
- French (fr)
- Russian (ru)
- German (de)
- Use API quotas reasonably, especially when using image features ๐ธ
- Securely store environment variables and API keys ๐
- Different AI models may have different features and limitations ๐
- Regularly check and update dependencies to ensure security and performance ๐ง
Welcome to submit Pull Requests or open Issues to improve this project! Your contributions will make this AI assistant more powerful and interesting.
This project is licensed under the MIT License.
About the "Deploy to Vercel" button: This button provides a one-click deployment to Vercel, which is very convenient. However, please note:
- The link in the button points to the original repository (https://github.com/snakeying/GPT-Telegram-Bot).
- If you've forked this project and want to deploy your own version, you need to update this button link in the README.
- Update method: Replace
snakeying/GPT-Telegram-Bot
in the link with your GitHub username and repository name.
For example, if your GitHub username is "yourname", you should change the button link to:
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fyourname%2FGPT-Telegram-Bot)
This ensures that the "Deploy to Vercel" button will deploy your forked version, not the original repository.