This is a simple Telegram bot that uses the OpenAI API to generate responses to user messages. It is designed to respond only to messages from a specific authorized user.
-
Clone the repository:
git clone https://github.com/ueco-jb/telegram-openapi-bot.git cd telegram-openapi-bot
-
Create a virtual environment and install the dependencies:
python3 -m venv env source env/bin/activate pip install -r requirements.txt
You need to set up two API keys: one for Telegram, and one for OpenAI.
-
Telegram Bot Token: Follow the instructions on BotFather to create a new Telegram bot and get your bot token.
-
OpenAI API Key: Sign up on OpenAI to get your API key.
-
Telegram user ID: In order to restrict bot to only one user, enter telegram user ID. To obtain your Telegram ID, you can start a chat with the
@get_id_bot
on Telegram, click on the START button at the bottom, and the bot will then send you a message containing your user ID.
Once you have your API keys, enter the values in config.yaml
file.
With your virtual environment activated and the config.yaml
file filled with your API keys, you can run the bot with:
python3 main.py
The bot will now listen for new messages from the authorized user and respond to them using the OpenAI API.