diff --git a/README.md b/README.md index b19ac07..f90e6dc 100644 --- a/README.md +++ b/README.md @@ -29,3 +29,10 @@ pip freeze > requirements.txt **Do not forget** to install the latest dependencies before adding new dependencies and rewriting the `requirements.txt` file. Otherwise old dependencies could be lost. + +## Running the bot + +```shell +export TELEGRAM_TOKEN=xxx +python bot.py +``` diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..b3de037 --- /dev/null +++ b/bot.py @@ -0,0 +1,13 @@ +import logging +import os +from telegram.command_processor import CommandProcessor + +from dotenv import load_dotenv + +load_dotenv() + +token = os.getenv('TELEGRAM_TOKEN') + +bot = CommandProcessor(token) +logging.info("Starting Telegram bot") +bot.run() diff --git a/requirements.txt b/requirements.txt index 8b2e6e8..2bbfd18 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,5 +2,6 @@ certifi==2021.10.8 charset-normalizer==2.0.12 idna==3.3 pyTelegramBotAPI==4.5.0 +python-dotenv==0.20.0 requests==2.27.1 urllib3==1.26.9 diff --git a/telegram/command_processor.py b/telegram/command_processor.py index 6129ded..7856ac6 100644 --- a/telegram/command_processor.py +++ b/telegram/command_processor.py @@ -1,13 +1,14 @@ import telebot from telebot.types import Message - class CommandProcessor: """Processes user input and dispatches the data to other services.""" bot: telebot.TeleBot def __init__(self, token: str): + if token is None or len(token) == 0: + raise ValueError("Token should not be empty") self.bot = telebot.TeleBot(token) def run(self):