flynnoct / chatgpt-telegram-bot

Telegram bot implemented by OFFICIAL OpenAI ChatGPT API (gpt-3.5-turbo, released on 2023-03-01)
MIT License
181 stars 43 forks source link
chatgpt openai telegram telegram-bot

ChatGPT Bot for Telegram

💥 Read This Before Updating to v1.4

We adjusted configuration format since v1.4.0, which is NOT compatible with previous versions. Please check the config doc for more details. You should backup your old config file and create a new one after updating to v1.4.0.

🎉 News

🐱 Introduction

ChatGPT Bot for Telegram is implemented with OpenAI ChatGPT API released on March 1, 2023. The Telegram integration framework is based on python-telegram-bot.

ChatGPT Bot can act as your Telegram contact. You can chat with it personally, share with a contact, and collabrate in a group chat. We attach great importance to privacy protection and make sure the Bot can't acquire any unrelated messages in group chats.

The Bot shares knowledge and inspires exciting new ideas. Many interesting features, such as DALL·E and Whisper are integrated together to make our Bot smarter and more usable.

We hope you enjoy it!

🌟 Features

The Telegram Bot features the following functions:

Additonal features:

👷 Deploy Your Own

Preparation

  1. Create a Telegram Bot by @BotFather and get the token.
  2. Create an OpenAI account and get the API key.
  3. A Linux VM or a server with Python 3 is needed to run the Bot.
  4. A practical Internet environment is required.
  5. (Optional) FFmpeg is required for the Bot to handle voice messages with Whisper. If you are not interested in using voice messages, you don't need to install it and must set enable_voice in the config file to False.
  6. (Optional) Azure TTS SDK is required for the Bot to reply with voice messages.

Installation

  1. Git clone from main branch or download the latest release Source code file and install the dependencies.
git clone https://github.com/flynnoct/chatgpt-telegram-bot.git
cd chatgpt-telegram-bot
pip install -r requirements.txt
  1. Create a config file to manage the Bot.

The config file includes sensitive information, such as telegram_token and openai_api_key, and we only release the corresponding template config.json.template. Therefore, you need to create a new config.json file by replacing the relative fields in the template with your own.

cp config.json.template config.json

Recommended: You should keep config.json.template unmodified because the Bot needs to read default configuration values from it. For backward compatibility, it is highly recommended to check the template for newly added parameters when you update to a new version.

For more details, see documentation.

  1. Run the Bot with start_bot.sh and try talk to it. You can also use docker to run the Bot.
# First, make sure you are in the root directory of the project,
# aka <your_download_location>/chatgpt-telegram-bot
bash ./bin/start_bot.sh # start the Bot

# Use docker compose to run the Bot
docker compose up -d

To clear ChatGPT conversation context and restart the Bot, run shell script restart_bot.sh. To shut down the Bot, run stop_bot.sh.

bash ./bin/restart_bot.sh # restart the Bot
bash ./bin/stop_bot.sh # stop the Bot

Up to now, you have successfully deployed the Bot.

Usage

The Bot works in both personal and group chat of Telegram. In a personal chat, simply send a message to the Bot and it will reply to you. In a group chat, use the /chat to invoke the Bot.

In a personal chat with a contact, use @your_bot_name <your messages> to invoke the Bot with Telegram inline mode. Both you and your contact can see the Bot's reply in the chat.

  1. The following commands are supported:

(Optinal) You can set them up as Telegram Bot command, see here.

  1. Inline mode

To enable inline mode, see here.

Type /mybots > Your_Bot_Name > Bot Settings > Inline Feedback, you must set the Inline Feedback to 100%.

TroubleShooting

See documentation.

🧑‍💻 For developers

Documentation is provided under docs for developers who wants to customize the Bot.

📚 Release Notes

The latest released version is here.

The release notes are here.

More interesting new features are coming soon!

🪪 License

MIT

☕️ Buy Me a Coffee (not Java)

If you like this project, you can buy me a coffee ❤️ or give this repository a free star ⭐️.

Click Alipay to open QR code.