Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wiseplat
GitHub Repository: wiseplat/python-code
Path: blob/master/ invest-robot-contest_invest-bot-main/tg_api/telegram_service.py
5925 views
1
import logging
2
3
from aiogram import Bot
4
5
__all__ = ("TelegramService")
6
7
logger = logging.getLogger(__name__)
8
9
10
class TelegramService:
11
"""
12
The class encapsulate logic with TG api via aiogram package
13
"""
14
def __init__(self, token: str, chat_id: str) -> None:
15
self.__bot = Bot(token=token)
16
self.__chat_id = chat_id
17
18
async def send_text_message(self, text: str) -> None:
19
"""
20
Sends text message to telegram chat
21
"""
22
logger.debug(f"TG API send text message: '{text}'")
23
24
await self.__bot.send_message(chat_id=self.__chat_id, text=text)
25
26
logger.debug(f"TG message has been sent.")
27
28