Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/snakeying/gpt-telegram-bot

Your own GPT Telegram Bot on Vercel
https://github.com/snakeying/gpt-telegram-bot

azure chatbot chatgpt-bot claude claude-api dall-e gemini gemini-api gpt groq groq-api multilanguage openai openai-api telegram telegram-bot

Last synced: about 1 month ago
JSON representation

Your own GPT Telegram Bot on Vercel

Awesome Lists containing this project

README

        

# GPT-Telegram-Bot: Multifunctional AI Assistant ๐Ÿค–๐Ÿ’ฌ

[English](./README.md) | [็ฎ€ไฝ“ไธญๆ–‡](./docs/README.zh-cn.md) | [็น้ซ”ไธญๆ–‡](./docs/README.zh-hant.md) | [ๆ—ฅๆœฌ่ชž](./docs/README.ja.md) | [Espaรฑol](./docs/README.es.md) | [Franรงais](./docs/README.fr.md) | [ะ ัƒััะบะธะน](./docs/README.ru.md) | [Deutsch](./docs/README.de.md)

GPT-Telegram-Bot is a powerful Telegram bot that integrates various AI models, providing intelligent conversations, image generation and analysis capabilities.

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fsnakeying%2FGPT-Telegram-Bot)

## Main Features ๐ŸŒŸ

1. **Multi-model Support** ๐ŸŽญ: Any model compatible with OpenAI API, Google Gemini, Anthropic Claude, Groq, and Azure OpenAI
2. **Intelligent Conversations** ๐Ÿ’ฌ: Natural language interactions with context memory support
3. **Image Generation** ๐ŸŽจ: Create images based on text descriptions
4. **Image Analysis** ๐Ÿ”: Interpret and describe uploaded images
5. **Multilingual Support** ๐ŸŒ: Localization support for multiple languages
6. **Stream Response** โšก: Real-time generation and display of AI replies
7. **User Whitelist** ๐Ÿ”: Can be set to allow access only to specific users

## Supported AI Models ๐Ÿง 

- 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 ๐Ÿ‘”

## Project Structure ๐Ÿ“

```
GPT-Telegram-Bot/
โ”œโ”€โ”€ api/ # API related configuration
โ”‚ โ”œโ”€โ”€ telegram.js # Handles Telegram bot interactions
โ”œโ”€โ”€ src/ # Source code
โ”‚ โ”œโ”€โ”€ api.js # Handles interactions with OpenAI compatible APIs
โ”‚ โ”œโ”€โ”€ bot.js # Main Telegram bot logic
โ”‚ โ”œโ”€โ”€ config.js # Configuration file
โ”‚ โ”œโ”€โ”€ azureOpenAI.js # Handles interactions with Azure OpenAI
โ”‚ โ”œโ”€โ”€ claude.js # Handles interactions with Claude
โ”‚ โ”œโ”€โ”€ generateImage.js# Handles interactions with DALLยทE
โ”‚ โ”œโ”€โ”€ geminiApi.js # Handles interactions with Gemini
โ”‚ โ”œโ”€โ”€ groqapi.js # Handles interactions with Groq
โ”‚ โ”œโ”€โ”€ uploadhandler.js# Handles image upload and analysis logic
โ”‚ โ”œโ”€โ”€ localization.js # Handles multilingual support
โ”‚ โ”œโ”€โ”€ redis.js # Upstash Redis database functionality
โ”œโ”€โ”€ locales/ # Multilingual support files
โ”‚ โ”œโ”€โ”€ en.json
โ”‚ โ”œโ”€โ”€ zh-cn.json
โ”‚ โ”œโ”€โ”€ zh-hant.json
โ”‚ โ””โ”€โ”€ ja.json
โ”‚ โ””โ”€โ”€ es.json
โ”‚ โ””โ”€โ”€ fr.json
โ”‚ โ””โ”€โ”€ ru.json
โ”‚ โ””โ”€โ”€ de.json
โ”œโ”€โ”€ docs/ # Multilingual README files
โ”‚ โ”œโ”€โ”€ README.zh-cn.md
โ”‚ โ”œโ”€โ”€ README.zh-hant.md
โ”‚ โ”œโ”€โ”€ README.ja.md
โ”‚ โ”œโ”€โ”€ README.es.md
โ”‚ โ”œโ”€โ”€ README.fr.md
โ”‚ โ”œโ”€โ”€ README.ru.md
โ”‚ โ””โ”€โ”€ README.de.md
โ”œโ”€โ”€ public/ # Vercel webpage after deployment
โ”‚ โ””โ”€โ”€ index.html # Webpage entry file
โ”œโ”€โ”€ package.json # Project dependencies
โ”œโ”€โ”€ vercel.json # Vercel configuration file
โ””โ”€โ”€ README.md # Project description file
```

## Quick Start ๐Ÿš€

### Prerequisites

- [Vercel](https://vercel.com/) account
- Telegram account and Bot Token
- [Upstash](https://upstash.com/) Please select the Redis database and enable the [Eviction](https://upstash.com/docs/redis/features/eviction) feature
- API key for at least one AI service

### Deployment Steps

1. Clone the repository:
```bash
git clone https://github.com/snakeying/GPT-Telegram-Bot.git
cd GPT-Telegram-Bot
```

2. Install dependencies:
```bash
npm install
```

3. Configure environment variables:
Create a `.env` file and fill in the necessary configuration information (refer to the environment variable configuration below).

4. 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

5. Set up Telegram Webhook:
After deployment, use the following URL to set up the Webhook:
```
https://api.telegram.org/bot/setWebhook?url=/api/telegram
```

## Environment Variable Configuration ๐Ÿ”ง

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.

## Usage Guide ๐Ÿ“–

- `/start` - Initialize the bot
- `/new` - Start a new conversation
- `/history` - View conversation history summary
- `/help` - Get help information
- `/switchmodel ` - Switch AI model
- `/img [size]` - Generate image
- `/language ` - 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)

## Notes โš ๏ธ

- 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 ๐Ÿ”ง

## Contribution ๐Ÿค

Welcome to submit Pull Requests or open Issues to improve this project! Your contributions will make this AI assistant more powerful and interesting.

## License ๐Ÿ“œ

This project is licensed under the [MIT License](https://choosealicense.com/licenses/mit/).

---

About the "Deploy to Vercel" button:
This button provides a one-click deployment to Vercel, which is very convenient. However, please note:

1. The link in the button points to the original repository (https://github.com/snakeying/GPT-Telegram-Bot).
2. If you've forked this project and want to deploy your own version, you need to update this button link in the README.
3. 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:

```markdown
[![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.