This is the telegram bot that can summarize n last messages in a chat using the power of AI LLM. The telegram bots are not allowed to read the chat history, so we need to store the messages in the database. Right now the bot is using the Firestore database. For summarizing the messages, the bot is using the OpenAI API.
💰 The OpenAI API is not free, so you need to have an account and generate the API key. 💰
- Rename .example.env to .env.
- Setup the Firestore database. Instruction
- Go to IAM & admin > Service accounts in the Google Cloud console. Generate a new private key and save the JSON file. Then use the file to initialize the SDK. Save this file as
serviceAccountKey.json
in the root directory. - Create a new bot using the BotFather and get the token. Save the token in the
.env
file. - In
.env
file set theTELEGRAM_BOT_NAME
variable to the bot name without @.
TELEGRAM_BOT_NAME=your_bot_name
- Change the bot privacy settings to disable the "Group Privacy" option.
- Go to BotFather in Telegram send
/setprivacy
. - Select the username of the bot.
- Select Disable.
- Go to BotFather in Telegram send
- Generate the OpenAI API key and save it in the
.env
file. - You can change other variables in the
.env
file if you want.
DEFAULT_LANGUAGE=ENGLISH
DEFAULT_HISTORY_LENGTH=100
DEFAULT_TONE=NEUTRAL
- Bot can transform voice-to-text, video-note-to-text and video-to=text. To enable this feature you need additional library
ffmpeg
on app environment.
sudo apt-get install ffmpeg
9.1. You can send the transcript of the voice message, video message and video-note message to the chat if you set env variable IS_ECHO_VOICE_MESSAGES
to true
.
IS_ECHO_VOICE_MESSAGES=true
If you want to include the links to the starting theme message in the summary, for private group your group have to be a SUPERGROUP. To make you group a SUPERGROUP, you should make it public and change back to the private.
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
If you want to run it with pm2 run the following command after activating venv:
pm2 start main.py --name summarizer_bot
- Add the bot to the chat.
- Send the
/start
command to the bot. - Send the
/chatid
command to the bot to get the chat id. - Create in the Firestore database a collection with the name of the chat id.
/start
- Start the bot./chatid
- Get the chat ID./summarize n
or/s n
- Summarize the last n messages in the chat. If n is not provided, the bot will summarize the lastDEFAULT_HISTORY_LENGTH
messages.
Retell the messages - the more wide summary of the messages in the chat.
You can call retell
function by mention the bot in the chat @bot_name
and send in the message optionally:
- number of messages to retell
n
- the bot will retell the last n messages. - tone of the summary - the bot will retell the messages with the specified tone.
- language of the summary - the bot will retell the messages in the retell language.
All retell
parameters are processed by LLM and you can use them in any order and combination.