This is a simple chatbot for Telegram. It is written in Python and uses the aiogram. Try it out here
- The bot can send a random picture with a cute cat. The
/cat
command is used for this (by TheCatAPI) - Currency conversion is available using the
/convert
command (by Exchange Rates API.io) - Using the
/weather
command, you can find out the weather in any city (by OpenWeatherMap) - The
/poll
command allows you to create a poll - All commands are also available in the Telegram groups
- Throttling is used to save resources and API requests
-
Install Python 3.10
-
Install Poetry and add it to the PATH
curl -sSL https://install.python-poetry.org | python3 -
-
Check that Poetry is installed correctly
poetry --version
-
Clone the repository
git clone https://github.com/LagrangeH/chat-bot-telegram.git
-
Go to the project directory
cd chat-bot-telegram
-
Create a virtual environment
poetry env use python3.10
-
Install dependencies
poetry install
-
Create
.env
file (copy.env.dist
and rename it to.env
)cp .env.dist .env
-
Fill in the
.env
fileDEBUG=False # https://t.me/botfather BOT_TOKEN= # https://thecatapi.com/ (Optional) CAT_API_KEY= # https://openweathermap.org/home/sign_up WEATHER_API_KEY= # https://exchangeratesapi.io/ EXCHANGE_API_KEY=
-
Run the bot
poetry run python bot.py
-
Send a message to the bot in Telegram
-
Use the
/help
command to see all available commands
The pytest framework is used for testing. Some unit-tests require parameters to be passed in.
-
Parameters can be optionally passed in command line mode:
poetry run pytest /tests --cat-api-key="..." --weather-api-key="..." --exchange-api-key="..."
If some parameters were not passed in command line mode, they will be taken from the .env file, otherwise, tests that require these parameters will be skipped.
-
To run tests with parameters passed from .env or without passing parameters, the following command is sufficient:
poetry run pytest /tests