Join the Telegram Group chat to share your user experience or report Bugs.
English | Simplified Chinese | Traditional Chinese
β Supports ChatGPT and GPT4 API
β Supports online search using duckduckgo and Googleπ. DuckDuckGo search is provided by default, and the official API for Google search needs to be applied by the user. It can provide real-time information that GPT could not answer before, such as Weibo hot search today, weather in a certain place today, and the progress of a certain person or news.
β Supports document QA based on the embedded vector database. In the search, for the searched PDF, automatic vector semantic search of PDF documents is performed, and pdf-related content is extracted based on the vector database. Supports using the "qa" command to vectorize the entire website with the "sitemap.xml" file, and answer questions based on the vector database, which is especially suitable for document websites and wiki websites of some projects.
β Supports switching between GPT3.5, GPT4 and other models through the "info" command in the chat window
β Asynchronously processes messages, multi-threadedly answers questions, supports isolated dialogues, and different users have different dialogues
β Supports accurate Markdown rendering of messages, using another project of mine
β Supports streaming output, achieving typewriter effect
β Supports whitelisting to prevent abuse and information leakage
β Cross-platform, breaking knowledge barriers anytime and anywhere with Telegram
β Supports one-click Zeabur, Replit deployment, true zero cost, idiotic deployment, and supports kuma anti-sleep. Also supports Docker, fly.io deployment
Variable Name | Comment |
---|---|
BOT_TOKEN (required) | Telegram bot token. Create a bot on BotFather to get the BOT_TOKEN. |
WEB_HOOK (required) | Whenever the telegram bot receives a user message, the message will be passed to WEB_HOOK, where the bot will listen to it and process the received messages in a timely manner. |
API (required) | OpenAI or third-party API key. |
API_URL(optional) | If you are using the OpenAI official API, you don't need to set this. If you using a third-party API, you need to fill in the third-party proxy website. The default is: https://api.openai.com/v1/chat/completions |
GPT_ENGINE (optional) | Set the default QA model; the default is:gpt-3.5-turbo . This item can be freely switched using the bot's "info" command, and it doesn't need to be set in principle. |
NICK (optional) | The default is empty, and NICK is the name of the bot. The bot will only respond when the message starts with NICK that the user inputs, otherwise the bot will respond to any message. Especially in group chats, if there is no NICK, the bot will reply to all messages. |
PASS_HISTORY (optional) | The default is true. The bot remembers the conversation history and considers the context when replying next time. If set to false, the bot will forget the conversation history and only consider the current conversation. |
GOOGLE_API_KEY (optional) | If you need to use Google search, you need to set it. If you do not set this environment variable, the bot will default to provide duckduckgo search. Create credentials in Google Cloud's APIs & Services and the API Key will be GOOGLE_API_KEY on the credentials page. Google search can be queried 100 times a day, which is completely sufficient for light use. When the usage limit has been reached, the bot will automatically turn off Google search. |
GOOGLE_CSE_ID (optional) | If you need to use Google search, you need to set it together with GOOGLE_API_KEY. Create a search engine in Programmable Search Engine, where the search engine ID is the value of GOOGLE_CSE_ID. |
whitelist (optional) | Set which users can access the bot, and connect the user IDs authorized to use the bot with ','. The default value is None , which means that the bot is open to everyone. |
One-click deployment:
If you need follow-up function updates, the following deployment method is recommended:
Fork this repository first, then register for Zeabur. The free quota is sufficient for light use. Import from your own Github repository, set the domain name (which must be consistent with WEB_HOOK) and environment variables, and redeploy. If you need function updates in the follow-up, just synchronize this repository in your own repository and redeploy in Zeabur to get the latest functions.
After importing the Github repository, set the running command
pip install -r requirements.txt > /dev/null && python3 main.py
Select Secrets in the Tools sidebar, add the environment variables required by the bot, where:
- WEB_HOOK: Replit will automatically assign a domain name to you, fill in
https://appname.username.repl.co
- Remember to open "Always On"
Click the run button on the top of the screen to run the bot.
Official documentation: https://fly.io/docs/
Use Docker image to deploy fly.io application
flyctl launch --image yym68686/chatgpt:1.0
Enter the name of the application when prompted, and select No for initializing Postgresql or Redis.
Follow the prompts to deploy. A secondary domain name will be provided in the official control panel, which can be used to access the service.
Set environment variables
flyctl secrets set WEB_HOOK=https://flyio-app-name.fly.dev/
flyctl secrets set BOT_TOKEN=bottoken
flyctl secrets set API=
# optional
flyctl secrets set NICK=javis
View all environment variables
flyctl secrets list
Remove environment variables
flyctl secrets unset MY_SECRET DATABASE_URL
ssh to fly.io container
flyctl ssh issue --agent
# ssh connection
flyctl ssh establish
Check whether the webhook URL is correct
https://api.telegram.org/bot<token>/getWebhookInfo
Start the container
docker run -p 80:8080 -dit \
-e BOT_TOKEN="telegram bot token" \
-e WEB_HOOK="https://your_host.com/" \
-e API="" \
-e API_URL= \
yym68686/chatgpt:1.0
Or if you want to use Docker Compose, here is a docker-compose.yml example:
version: "3.5"
services:
chatgptbot:
container_name: chatgptbot
image: yym68686/chatgpt:1.0
environment:
- BOT_TOKEN=
- WEB_HOOK=
- API=
- API_URL=
ports:
- 80:8080
Run Docker Compose container in the background
docker-compose up -d
Package the Docker image in the repository and upload it to Docker Hub
docker build --no-cache -t chatgpt:1.0 -f Dockerfile.build --platform linux/amd64 .
docker tag chatgpt:1.0 yym68686/chatgpt:1.0
docker push yym68686/chatgpt:1.0
Reference Projects:
https://core.telegram.org/bots/api
https://github.com/acheong08/ChatGPT
https://github.com/franalgaba/chatgpt-telegram-bot-serverless
The markdown rendering of the message used is another project of mine.