Giter VIP home page Giter VIP logo

chatgpt-telegram-bot's Introduction

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

  • Microsoft Azure TTS is now supported! The Bot can now reply with voice messages!
  • ChatGPT temperature is now supported! You can set the temperature in configuration to customize the creativity of ChatGPT reply.
  • A better logging system is provided for debugging purposes.
  • A better-organized config structure is provided. You should go through the config doc and modify the config file. We have temporarily removed the config.py configuration script.
  • Model selection ability is added. You can now choose the model you want to use in the config file. The Bot can be powered by GPT-4 if you have access.

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

  • ChatGPT, the AI consultant. You can customize the Bot's character according to preference.
  • DALL·E, the Image Generation AI Model. Send a short prompt to the Bot and get your own painting.
  • Whisper, the Intelligent Speech Recognizer. The Bot can read your voice messages.
  • Azure TTS, the Speech service feature that converts text to lifelike speech. The Bot can reply with voice messages.
  • Comprehensive Privacy Protection. The Bot is unable (and of course we won't) to collect any message in group chat except user prompts.

Additonal features:

  • ChatGPT role and temperature Customization.
  • The Telegram inline mode allows you to query the Bot privately in a chat with a contact or group, even if the Bot is not a member.
  • User White-list to control who can use the Bot. You can also set allow_all_users to true to allow any 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)

👷 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:
  • /start: Start the Bot.
  • /role <prompt>: Set role for conversation.
  • /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.

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

chatgpt-telegram-bot's People

Contributors

dswutang avatar estrellaxd avatar flynnoct avatar hareq avatar peterdavehello avatar raycxggg avatar xubai2001 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

chatgpt-telegram-bot's Issues

Implementing an prompt

Would be very useful to have a prompt system that allows you to set the tone of the assistant.

Something that allows us to kick conversations off with some of the settings we prefer. For example I would have:

'prompt': 'You are a helpful assistant. You always convert imperial to metric measurements and localise spelling to the United Kingdom'

Suggestion: Multi-User Support

One of my use cases is basically running another instance for my friends to use as a telegram bot. It would be helpful to have a way to ‘whitelist’ all telegram IDs so as long as they know the link to message it, they can talk to the bot.

Related to this too, not sure how feasible it is, would be separate conversational context for each person that messages the bot, but I’m also not sure if this is even possible with the API.

Bot Unresponsive

I have installed and configured the config.json with my api key and bot key. I run the bot on terminal and it says the bot has started, but when I try to interact with the bot in telegram it does nothing.

Would you consider synchronizing to HubDocker?

There are many users there, and it can be loved by more people.

For example, on Synology devices, it only supports the use of HubDocker for installation.

If you can synchronize to HubDocker, it's really great.

Bot does not respond.

After running the command 'bash ./bin/start_bot.sh', my terminal displays the message 'Bot has been started successfully', but when I try to chat with the bot on Telegram, it doesn't respond. How can I fix this issue?
ảnh

bot not responding

I tried main and dev and they both have the same problem.

When using start_bot.sh, although it says bot started successfully, it cannot get a response after sending a message through Telegram Bot.

When starting telegram_message_parser.py with the python command, the following error is encountered.

Traceback (most recent call last): File "/home/src/telegram_message_parser.py", line 15, in <module> from telegram.ext import ApplicationBuilder, CommandHandler, MessageHandler, InlineQueryHandler, ChosenInlineResultHandler, ContextTypes, filters ModuleNotFoundError: No module named 'telegram'

Amazing!

First of all, fantastic work. This thing is by far the best I've used. Not sure how you were able to push specific tasks to the background and still communicate with it, but I love it!

I did want to ask about the models. I noticed you were using gpt-3.5-turbo-0301. I'm not familiar with it. Can you explain why that one and not the normal 3.5 turbo?

Also, I tried swapping to text-davinci-003 and 002, but I got a URL error. I assume it just means the wrong syntax is being used to call the API. Is there any way to set it up to utilize older models? I've found that 002 works much better with coding than the newer ones.

Add TTS feature to reply voice messages with Amazon Polly

Any possible to add text-to-speech feature to the bot? For example, with Amazon Polly, we could get 5 million characters free per month for 12 months with the AWS Free Tier. https://aws.amazon.com/polly/

This feature could allow the bot to reply voice messages to users. This could make the bot more powerful, for example for language learning, etc.

Add the ability to change the role please

I can't write code, but I would like to add the function of changing the role by the command directly in the code, because if you specify the role in the chat, he does not really want to match it

Single Message Mode

  • Implemented a single message mode with no context provided to save tokens in some scenarios.

Refactor code: privacy, better hierarchy & logging

It's Flynn here, I'm glad to show you what I plan to do now.

  1. Previously, we ask for @your_bot_name <your messages> in a group chat to make the bot reply. And the Privacy Mode needs to be disabled to make the bot have ability to get ALL messages from a group. We reviewed that requirement and we think it could be a privacy concern for some users (but I promise we didn't, and won't save your chat history for any other use). Therefore, in next version, the way to chat with the bot in a group chat is to use a specific command /chat. Privacy is basic rights, we hope you like this changes.
  2. This bot is started with a small set of features. However there are so many features we like (more on the way!) come to life. It's necessary for us to refactor hierarchy for this project and make everyone's life easier. XD
  3. The We apologize for not having good Ioggings at the beginning and causes someone's confusion. We are going to add loggings into our code and diagnosis could be much easier later.

Good night. See you soon.

Got no response from my bot

wget command didn't work for me, so I used git clone to pull the source code, and I got all dependencies installed, sure, replaced the api key and bot token and got it running on my Azure WM, but I still got no response from my bot.

v1.2.2 to v1.3.0. Backward compatibility

After updating from version 1.2.2 to 1.3.0, the bot stopped responding. I discovered that new parameters were added to the config.json file. The bot did not work until I added the following new parameters:

  • "openai_timeout"
  • "enable_custom_system_role"
  • "system_role"

Perhaps default values for these parameters should be used if they do not exist.

Suddenly No Response from Bot?

It’s been working fine for the past few days but suddenly I’m not getting any responses from the bot, even after restart_bot.sh and a server reboot. Are there any further steps I can take for troubleshooting?

Thank you.

help

Please help me to integrate to telegram, bot started, but telegram bot doesnt working:(

Access manager has been derived from Telegram APIs

Access manager has been derived from Telegram APIs in new branch accessmanager-dev. Please help me test it. Thx. @flynnoct

In case of granting users different authority between text, voice and file, the <chat_type> field is currently reserved for future use.

telegram bot reply nothing

I followed the prompts in the instructions for installation, and at the end it showed that the bot has started successfully. However, I'm not receiving any replies from the bot when I send messages to it. I don't know why.

Why do we need to copy a config.json file?

Hello author, I have a question to ask. Why do we need to copy a config.json file through command during installation? Why not directly provide it in the program code? If it is provided directly, the user would have one less step during installation. I am not a programmer, just curious.Thank you for providing such an interesting project.😄

No perceptual clear the conversation context

This model's maximum context length is 4096 tokens. However, your messages resulted in 4119 tokens. Please reduce the length of the messages. Sorry, I am not feeling well. Please try again.

After exceeding the limit of tokens, we can only execute /clear to clear conversation context to restore function.

This seems to be the only option, so is it possible that sending the message again after reaching the limit will automatically execute the /clear command?

It doesn't work for me in Docker Desktop (Windows 10)

2023-03-16 01:11:04 Bot has been started successfully 2023-03-16 01:11:06 Bot has been started successfully 2023-03-16 01:11:07 Bot has been started successfully

Always restart...

image
image
image
image
image

`C:\Users\Asus\Python\chatgpt-telegram-bot>docker compose up -d
[+] Running 0/1

  • chatgpt-bot Warning 2.0s
    [+] Building 25.1s (10/10) FINISHED
    => [internal] load build definition from Dockerfile 0.1s
    => => transferring dockerfile: 288B 0.0s
    => [internal] load .dockerignore 0.0s
    => => transferring context: 34B 0.0s
    => [internal] load metadata for docker.io/library/python:3.11-alpine 1.3s
    => [1/5] FROM docker.io/library/python:3.11-alpine@sha256:741e650697a506f0991ef88490320dee59f9e68de61734e034aee11d2f3baedf 3.1s
    => => resolve docker.io/library/python:3.11-alpine@sha256:741e650697a506f0991ef88490320dee59f9e68de61734e034aee11d2f3baedf 0.1s
    => => sha256:21c32060d5e22e4292410288a34314f9ab518a5df218e906f3387e7f5690eb2c 230B / 230B 0.8s
    => => sha256:8ced40fb1e4201d32de2f1b782b4becf1a5ec8a75406514af9e9898d6f551b68 3.06MB / 3.06MB 1.7s
    => => sha256:741e650697a506f0991ef88490320dee59f9e68de61734e034aee11d2f3baedf 1.65kB / 1.65kB 0.0s
    => => sha256:4b7bbe66de3c3ff042f0a81fd3c20f993acccf08e3eb722f992a585e00594ca9 1.37kB / 1.37kB 0.0s
    => => sha256:7bc17fb245bdf26df10196ea0ab7cb4c1dbbe6d7915f2ac301cdc52e2d91b067 7.34kB / 7.34kB 0.0s
    => => sha256:0b05af06b5194af09bda2ee287f02f887ab50cb3d3434a7d20f67f1af345bfed 12.46MB / 12.46MB 1.6s
    => => extracting sha256:0b05af06b5194af09bda2ee287f02f887ab50cb3d3434a7d20f67f1af345bfed 0.6s
    => => extracting sha256:21c32060d5e22e4292410288a34314f9ab518a5df218e906f3387e7f5690eb2c 0.0s
    => => extracting sha256:8ced40fb1e4201d32de2f1b782b4becf1a5ec8a75406514af9e9898d6f551b68 0.4s
    => [internal] load build context 0.1s
    => => transferring context: 3.44kB 0.0s
    => [2/5] WORKDIR /app 0.5s
    => [3/5] COPY requirements.txt requirements.txt 0.1s
    => [4/5] RUN pip install -r requirements.txt 18.4s
    => [5/5] COPY . . 0.3s
    => exporting to image 1.0s
    => => exporting layers 1.0s
    => => writing image sha256:e3aa5110d002c34767cdefd3c60874e6e4fd762267f44f0adf67041b107f85e4 0.0s
    => => naming to docker.io/chatgpt/bot 0.0s
    [+] Running 2/2
  • Network chatgpt-telegram-bot_default Created 0.8s
  • Container chatgpt-bot Started 1.5s

C:\Users\Asus\Python\chatgpt-telegram-bot>`

I use the latest version 1.2.2

What I did wrong?
How can I fix it?

PS: Thank you for your work!

Audio interaction does not work

I have used command pip install ffmpeg-python to get ffmpeg installed, and have set enable_voice to true, after I restarted the bot, the audio interaction still does not work, anything wrong I did?

Settings

"Would like to see output settings, for example, to display code in monospace font so that it can be easily copied by click. Also, it would be useful to have a feature to output text as an image."

Example:

/settings

  • Settings Menu
    *Picture mode- Off
    *Monospace font - On

How can I change the model and temperature?

I modified line 31 and 41 in openai_parser.py, replaced gpt-3.5-turbo-0301 with gpt-3.5-turbo, and restart the bot, I found it on OpenAI daily usage breakdown page the bot still using model gpt-3.5-turbo-0301. How can I change the model? Thanks.

Azure TTS, Enhanced Logging and Better Structured Config

This branch is a mess😫.

I implemented several features in one branch and this branch will include:

  1. Azure TTS support when chat with voice.
  2. I don't like Python's logging lib, do it on my own!
  3. The current config key has not been carefully considered, and we have implemented a better structured config.

[suggestion]change the key value of ChatGPT through command line

It would be great if we could change the key value of ChatGPT through command line, such as typing (or selecting) [change key value] in the terminal, and then inputting the new key to update the key value in the configuration file, which would be more convenient than editing the config file manually.😄

how to get working

ok its not my first time working with ai bots, iv followed all the instructions and ran it and nothing happens it wont responed or anything.

Error in TG lib when starting

I followed your procedures on an ARM based Oracle VPS but received the following error.

$ python3 telegram_message_parser.py
Traceback (most recent call last):
File "telegram_message_parser.py", line 15, in
from telegram import Update
ImportError: cannot import name 'Update' from 'telegram' (/home/ubuntu/.local/lib/python3.8/site-packages/telegram/init.py)

I am using 3.8.10 python

$ py --version
Python 3.8.10

I fixed it by force removing ~/.local/lib/python3.8/site-packages/telegram and force reinstalling
$ pip install python-telegram-bot --force-reinstall and it fixed the issue

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.