38 lines
1.7 KiB
Python
38 lines
1.7 KiB
Python
import logging
|
||
|
||
from aiogram.types import BotCommand, InlineKeyboardButton, InlineKeyboardMarkup
|
||
|
||
from shared.telegram_base import TelegramBase
|
||
|
||
log = logging.getLogger(__name__)
|
||
|
||
|
||
class TelegramBot(TelegramBase):
|
||
async def send_message(self, text: str, chat_id: int) -> None:
|
||
await self.bot.send_message(chat_id=chat_id, text=text)
|
||
|
||
async def send_message_with_button(self, text: str, chat_id: int, button_text: str, button_url: str) -> None:
|
||
keyboard = InlineKeyboardMarkup(inline_keyboard=[[InlineKeyboardButton(text=button_text, url=button_url)]])
|
||
await self.bot.send_message(chat_id=chat_id, text=text, reply_markup=keyboard)
|
||
|
||
async def create_chat_invite_link(self, chat_id: int, requires_approval: bool = False) -> str:
|
||
invite_link = await self.bot.create_chat_invite_link(chat_id=chat_id, creates_join_request=requires_approval)
|
||
return invite_link.invite_link
|
||
|
||
async def send_message_with_inline_keyboard(
|
||
self, text: str, chat_id: int, buttons: list[list[InlineKeyboardButton]]
|
||
) -> None:
|
||
keyboard = InlineKeyboardMarkup(inline_keyboard=buttons)
|
||
await self.bot.send_message(chat_id=chat_id, text=text, reply_markup=keyboard)
|
||
|
||
async def edit_message_reply_markup(self, chat_id: int, message_id: int) -> None:
|
||
await self.bot.edit_message_reply_markup(chat_id=chat_id, message_id=message_id, reply_markup=None)
|
||
|
||
async def set_commands(self) -> None:
|
||
commands = [
|
||
BotCommand(command='start', description='Начать работу с ботом'),
|
||
BotCommand(command='new_creative', description='Создать новый креатив'),
|
||
]
|
||
|
||
await self.bot.set_my_commands(commands)
|