General Introduction
GPT-Telegram-Worker is a multi-model AI Telegram robot based on Cloudflare Workers, supporting multiple APIs such as OpenAI, Claude, Azure, etc. The project is developed in TypeScript, with a modularized design for easy expansion to provide a fast and scalable service experience. The robot is equipped with intelligent dialog, image generation, image analysis and other functions, and supports multiple languages to meet diversified needs.
Function List
- Multi-model support: Integrate multiple AI models such as OpenAI, Google Gemini, Anthropic Claude, Groq and Azure OpenAI.
- Intelligent dialog: with contextual memory capability to ensure smooth and natural dialog.
- Image Generation: Supports textual descriptions to generate images, using DALL-E and Cloudflare. Flux Technology.
- Image analysis: support users to upload images and analyze them intelligently, using OpenAI or Google Gemini Model.
- Multi-language support: Built-in i18n function supports 8 languages.
- User rights management: control access rights through the whitelist function to enhance security.
- High-performance deployment: Leverage the edge computing power of Cloudflare Workers for rapid response.
- Efficient data management: Redis is used for data caching and management to ensure efficient processing.
- Flux Cue Optimization: Optimize image-generated cues for Flux models via an external API.
Using Help
Installation process
- preliminary::
- Cloudflare Account
- Telegram Account and Bot Token
- Upstash Redis database (requires Eviction to be enabled)
- API key for at least one AI service
- Getting Started::
- Cloning Project Warehouse:
git clone https://github.com/snakeying/GPT-Telegram-Worker.git
- Configure the necessary environment variables: in the
.env
file to set up information about Cloudflare, Telegram, and Redis. - Deploy to Cloudflare Workers:
npm install -g @cloudflare/wrangler wrangler login wrangler init telegram-bot cp dist/index.js telegram-bot/ wrangler publish
- Set up a Telegram Webhook:
curl -F "url=https://your-worker.your-subdomain.workers.dev" https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook
- Cloning Project Warehouse:
Instructions for use
- Activate the robot.::
- utilization
/start
Command to start the robot. - utilization
/language
Switch language. - utilization
/switchmodel
Toggle the AI model. - utilization
/new
Start a new conversation. - utilization
/history
Get a summary of the conversation history. - utilization
/help
Get help information.
- utilization
- Image Generation::
- utilization
/img
command to generate an image (DALL-E). - utilization
/flux
command to generate an image (Cloudflare Flux).
- utilization
- image analysis::
- After uploading the image, the robot automatically performs an intelligent analysis and returns the results.
- Rights Management::
- Ensure security by controlling user access rights through the whitelisting feature.
- data management::
- Use Redis for data caching and management to ensure efficient processing.
Detailed Operation Procedure
- Configuring Environment Variables::
- In the project root directory, create the
.env
file, add the following:TELEGRAM_BOT_TOKEN= CLOUDFLARE_ACCOUNT_ID= REDIS_URL=
- Make sure that all variables are properly configured.
- In the project root directory, create the
- Deploying to Cloudflare Workers::
- Use the Wrangler CLI to deploy the project:
wrangler publish
- Configure environment variables in the Cloudflare Dashboard.
- Use the Wrangler CLI to deploy the project:
- Setting up the Telegram Webhook::
- Setting up a Webhook using the Telegram Bot API:
curl -F "url=https://your-worker.your-subdomain.workers.dev" https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook
- Setting up a Webhook using the Telegram Bot API:
- Use of robots::
- After starting the robot, you can use various commands to interact with the robot, generate images, analyze pictures, switch languages and models, and so on.