Skip to content

Commit

Permalink
Merge pull request #32 from flynnoct/dev
Browse files Browse the repository at this point in the history
v1.2.0
  • Loading branch information
flynnoct authored Mar 6, 2023
2 parents 9b3c898 + a5c5d80 commit 3a520d9
Show file tree
Hide file tree
Showing 19 changed files with 735 additions and 450 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/docs
config.json.template
LICENSE.md
README.md
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3.9-alpine

# Install dependencies
WORKDIR /app

COPY requirements.txt requirements.txt

RUN pip install -r requirements.txt

# Copy the rest of the code
COPY . .

CMD ["sh", "bin/start_bot.sh"]

45 changes: 33 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@

- **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!
- **Important privacy protection stategy** is deployed! The Bot is unable to collect any message in group chat except user prompts.

## Introduction

ChatGPT Bot for Telegram is implemented with [OpenAI ChatGPT API](https://platform.openai.com/docs/guides/chat) released on March 1, 2023. The Telegram integration framework is based on [python-telegram-bot](https://python-telegram-bot.org).

ChatGPT Bot can act as your Telegram contact. You can chat with it either personally or in a group chat. Just like the popular AI on the OpenAI official site, 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.
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!

Expand All @@ -25,21 +28,27 @@ The Telegram Bot features the following functions:

Additonal functions are also implemented:

- (Beta) _Telegram inline mode_ is supported to invoke the Bot in a private chat with a contact.
- Set the daily limitation of requirements to **DALL·E**.
- Grant more resources to _Super Users_.

## Commands

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

## Sample 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, you need to tag the message with `@<bot_name>` to invoke the Bot.

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.

### Preparation

Expand All @@ -53,36 +62,48 @@ In a group chat, you need to tag the message with `@<bot_name>` to invoke the Bo
### Deployment

Download the latest release version and install the dependencies.
1. Git clone from main branch or download the latest release [Source code](https://github.com/flynnoct/chatgpt-telegram-bot/releases/latest) file and install the dependencies.

```bash
wget https://github.com/flynnoct/chatgpt-telegram-bot/releases/latest
git clone https://github.com/flynnoct/chatgpt-telegram-bot.git
cd chatgpt-telegram-bot
pip install -r requirements.txt
```

Then, you need to 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 and replace the relative fields with your own.
2. 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.

```bash
cp config.json.template config.json
```

Follow below procedures to fill you `config.json`:
Follow the [documentation](docs/config_file.md) to complete your `config.json` file.

1. Replace the `telegram_token` and `openai_api_key` with your own.
2. Add allowed users to the `allowed_users` list. You can get your user id by sending `/start` to [@userinfobot](https://t.me/userinfobot) or send `/getid` to the Bot (after you start it).
3. 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.

> Note: the user ID is a series of numbers, you should add it to the `allowed_users` list as a string (add quotation marks around it).
```bash
# 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

Now, you can 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!
# 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
bash ./bin/restart_bot.sh # restart the bot
bash ./bin/stop_bot.sh # stop the bot
```

## Release version and notes

The latest released version can be found [here](https://github.com/flynnoct/chatgpt-telegram-bot/releases/latest). More interesting new features are comming soon!
The latest released version is [here](https://github.com/flynnoct/chatgpt-telegram-bot/releases/latest).

The release notes are [here](/docs/release_notes.md).

More interesting new features are comming soon!

## License

[MIT](LICENSE.md)
Expand All @@ -91,4 +112,4 @@ The release notes are [here](/docs/release_notes.md).

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

Click [Alipay](donate_code/alipay.jpg) to open QR code.
Click [Alipay](docs/donate_code/alipay.jpg) to open QR code.
2 changes: 1 addition & 1 deletion restart_bot.sh → bin/restart_bot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ else
fi

echo "Starting bot..."
nohup python3 telegram_message_parser.py >/dev/null 2>&1 &
nohup python3 src/telegram_message_parser.py >/dev/null 2>&1 &
echo "Bot has been restarted successfully"
2 changes: 1 addition & 1 deletion start_bot.sh → bin/start_bot.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# This script start a Python program named telegram_message_parser.py and run it in the background

nohup python3 telegram_message_parser.py >/dev/null 2>&1 &
nohup python3 src/telegram_message_parser.py >/dev/null 2>&1 &
echo "Bot has been started successfully"
File renamed without changes.
15 changes: 9 additions & 6 deletions config.json.template
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
{
"openai_api_key": "<YOUR_OPENAI_API_KEY_HERE>",
"telegram_bot_token": "<YOUR_TELEGRAM_BOT_TOKEN_HERE>",
"enable_voice": true, // When enabled, Bot will accept audio messages with Whisper and reply.
"allow_all_users": false,
"allowed_users": [
"<USER_ID_1>",
"<USER_ID_2>",
"<USER_ID_2>"
],
"wait_time": 600, // The time limit in seconds that the Bot will clear the conversation context.
"enable_dalle": true, // When enabled, Bot will involve DALL·E to handle requests for painting.
"enable_voice": true,
"wait_time": 600,
"enable_dalle": true,
"super_users": [
"<SUPER_USER_ID_1>", // Super users are granted unlimited usage on DALL·E per day.
"<SUPER_USER_ID_1>",
"<SUPER_USER_ID_2>"
],
"image_generation_limit_per_day": 5 // The upper limit that a normal user is allowed to invoke DALL·E per day.
"image_generation_limit_per_day": 5,
// Beta! When enabled, Bot will be able to work in inline mode, contact @BotFather to enable inline mode for your Bot
"enable_inline": false
}
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3"

services:
chatgpt-bot:
image: chatgpt/bot
container_name: chatgpt-bot
restart: always
build:
context: .
dockerfile: Dockerfile
53 changes: 53 additions & 0 deletions docs/config_file.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Documentation for config.json

This documentation is for users who are unfamilar with JSON file and have trouble in using the `config.json` file.

## Usage

Follow below procedures to modify your `config.json`:

1. Replace the `telegram_token` and `openai_api_key` with your own.
2. Add allowed users to the `allowed_users` list. You can get your user id by sending `/start` to [@userinfobot](https://t.me/userinfobot) or send `/getid` to the Bot (after you start it).

> Note: the user ID is a series of numbers, you should add it to the `allowed_users` list as a string (add quotation marks around it).
```
{
"openai_api_key": "<YOUR_OPENAI_API_KEY_HERE>",
"telegram_bot_token": "<YOUR_TELEGRAM_BOT_TOKEN_HERE>",
// Allow all users to use the bot, if enabled, "allowed_users" list won't have any effect.
"allow_all_users": false,
"allowed_users": [
"<USER_ID_1>",
"<USER_ID_2>"
],
// When enabled, Bot will accept audio messages with Whisper and reply.
"enable_voice": true,
// The time limit in seconds that the Bot will clear the conversation context.
"wait_time": 600,
// When enabled, Bot will involve DALL·E to handle requests for painting.
"enable_dalle": true,
// Super users are granted unlimited usage on DALL·E per day.
"super_users": [
"<SUPER_USER_ID_1>",
"<SUPER_USER_ID_2>"
],
// The upper limit that a normal user is allowed to invoke DALL·E per day.
"image_generation_limit_per_day": 5,
// Beta! When enabled, Bot will be able to work in inline mode, contact @BotFather to enable inline mode for your Bot
"enable_inline": False
}
```

## Troubleshooting

- Comments are not allowed in JSON specification. Make sure there are no commented code and words left in the file.
- There should be **no comma** after the last element in `allowed_users` and `super_users` lists.
File renamed without changes
21 changes: 21 additions & 0 deletions docs/release_notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Version history

## v1.2.0

- Privacy protection improvement. The Bot now is unable to acquire messages in the group chat except user prompts.
- Beta version for Telegram inline mode. The Bot now can be invoked in a chat with a contact.
- Code hierarchy adjustment and bugs fixed.
- Documentation for config.json file is published.

## v1.1.0

- DALL·E API integration. The Bot now supports image generation based on user prompts.
- Whisper API integration. The Bot now supports interaction with voice messages.
- Usage limitation. Now support set daily limitation of requirements to DALL·E.
- Super user. Now support granting unlimited resources to Super Users.

## v1.0.0

- ChatGPT API integration.
- Telegram API integration.
- Private and group chat function.
134 changes: 0 additions & 134 deletions message_manager.py

This file was deleted.

Loading

0 comments on commit 3a520d9

Please sign in to comment.