#7 Implementing Telegram bot run script.

This commit is contained in:
Alexey Skobkin 2022-05-02 19:14:12 +03:00
parent 8f359847bf
commit 5509053bb0
4 changed files with 23 additions and 1 deletions

View File

@ -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
```

13
bot.py Normal file
View File

@ -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()

View File

@ -2,6 +2,7 @@ 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
feedparser==6.0.2

View File

@ -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):