Skip to content

Telegram bot implemented by OFFICIAL OpenAI ChatGPT API (gpt-3.5-turbo-0301, released on 2023-03-01)

License

Notifications You must be signed in to change notification settings

vvonchain/chatgpt-telegram-bot

 
 

Repository files navigation

ChatGPT Bot for Telegram

🔥 URGENT

We located a bug in v1.2.0 which may lead to an error when start the bot. Please make sure you update to the v1.2.2 version.

🎉 News

  • DALL·E, the OpenAI Image Generation Model, is now supported! Send a short prompt to the Bot and get your own painting!
  • Whisper, the OpenAI Intelligent Speech Recognizer, is now supported! Now chat with the Bot with audio messages!
  • Telegram Inline Mode (Beta) is now supported! You can ask @BotFather to enable both inline mode & inline feedback to 100% for your Bot and use it in any private chat with a contact and group chat (even without inviting the bot as a member).
  • Important privacy protection strategy is deployed! The Bot is unable (and of course we won't) to collect any message in group chat except user prompts.
  • Better config.json.template is now provided.

🐱 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:

  • An AI consultant, based on OpenAI ChatGPT, interacts in a conversational way.
  • A flexible speech recognizer which supports audio interaction.
  • A AI painter reponses to user's requirement prompt.

Additonal functions are also implemented:

  • (Beta) Telegram inline mode is supported to invoke the Bot in a private chat with a contact and a group without bot as a member.
  • User Whitelist to control who can use the bot. You can also set allow_all_users to true to allow all users to use the Bot.
  • Set the daily limitation of requirements to DALL·E.
  • Grant more resources to Super Users.
  • Docker deployment is supported. (This method is maintained by community. Thanks for @EstrellaXD 's contribution)

👋 How to Use

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. It will not collect any other message except the prompts after the command.

(Beta) 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. This function is Beta because it currently can't record the chat context.

Bot Commands

  • /start: Start the bot.
  • /chat : Invoke the Bot in group chat.
  • /dalle <prompt>: Ask DALL·E for a painting based on your prompt.
  • /clear: Clear the conversation context.
  • /getid: Get your Telegram user ID.

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

Note: You should disable the privacy mode of the bot. Otherwise the bot will not receive the messages from the group chat. You can do this by sending /setprivacy to @BotFather.

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

Follow the documentation to complete your config.json file.

  1. Run the Bot with start_bot.sh and try talk to it. Also, you can invite it to group chats and share with your friends! Or 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

📚 Release Notes

The latest released version is here.

The release notes are here.

More interesting new features are comming 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.

About

Telegram bot implemented by OFFICIAL OpenAI ChatGPT API (gpt-3.5-turbo-0301, released on 2023-03-01)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 95.5%
  • Shell 3.6%
  • Other 0.9%