telegram. Implementing Telegram bot run script.
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is failing

This commit is contained in:
Alexey Skobkin 2022-05-02 19:14:12 +03:00
parent d201850956
commit 1807424586
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 **Do not forget** to install the latest dependencies before adding new dependencies and rewriting
the `requirements.txt` file. Otherwise old dependencies could be lost. 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,5 +2,6 @@ certifi==2021.10.8
charset-normalizer==2.0.12 charset-normalizer==2.0.12
idna==3.3 idna==3.3
pyTelegramBotAPI==4.5.0 pyTelegramBotAPI==4.5.0
python-dotenv==0.20.0
requests==2.27.1 requests==2.27.1
urllib3==1.26.9 urllib3==1.26.9

View file

@ -1,13 +1,14 @@
import telebot import telebot
from telebot.types import Message from telebot.types import Message
class CommandProcessor: class CommandProcessor:
"""Processes user input and dispatches the data to other services.""" """Processes user input and dispatches the data to other services."""
bot: telebot.TeleBot bot: telebot.TeleBot
def __init__(self, token: str): 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) self.bot = telebot.TeleBot(token)
def run(self): def run(self):