from aiogram import asyncio, types, executor
from lib.bot.struct import Message_struct
from lib.bot.converters import str_to_dict
from lib.server import send_to_server
# Ensure to import config for tg
from lib.bot.messengers_configs.tg_config import dp
@dp.callback_query_handler()
async def inline_kb_answer_callback_handler(
query: types.CallbackQuery,
) -> None:
message_struct = Message_struct(
user_id=query.from_user.id,
messenger="tg",
payload=str_to_dict(string=query.data),
)
await send_to_server(message=message_struct)
@dp.message_handler()
async def echo_handler(message: types.Message) -> None:
message_struct = Message_struct(
user_id=message.from_id, messenger="tg", text=message.text
)
await send_to_server(message=message_struct)
def start_tg_client() -> None:
print(f"TG listening started")
executor.start_polling(dp, skip_updates=True)
if __name__ == "__main__":
start_tg_client()
from aiogram import asyncio, types, executor
from lib.bot.struct import Message_struct
from lib.bot.converters import str_to_dict
from lib.server import send_to_server
class Tg_client:
def __init__(self, dp) -> None:
self._dp = dp
@self._dp.callback_query_handler()
async def inline_kb_answer_callback_handler(
query: types.CallbackQuery,
) -> None:
message_struct = Message_struct(
user_id=query.from_user.id,
messenger="tg",
payload=str_to_dict(string=query.data),
)
await send_to_server(message=message_struct)
@self._dp.message_handler()
async def echo_handler(message: types.Message) -> None:
message_struct = Message_struct(
user_id=message.from_id, messenger="tg", text=message.text
)
await send_to_server(message=message_struct)
def start_tg_client() -> None:
print(f"TG listening started")
executor.start_polling(self._dp, skip_updates=True)
if __name__ == "__main__":
from lib.bot.messengers_configs.tg_config import dp
tg_client = Tg_client(dp=dp)
tg_client.start_tg_client()
from aiogram import types, executor
from lib.bot.struct import Message_struct
from lib.bot.converters import str_to_dict
from lib.server import send_to_server
class Tg_client:
def __init__(self, dp) -> None:
self._dp = dp
self._dp.callback_query_handler()(
self.inline_kb_answer_callback_handler
)
self._dp.message_handler()(self.echo_handler)
async def inline_kb_answer_callback_handler(
self,
query: types.CallbackQuery,
) -> None:
message_struct = Message_struct(
user_id=query.from_user.id,
messenger="tg",
payload=str_to_dict(string=query.data),
)
await send_to_server(message=message_struct)
async def echo_handler(self, message: types.Message) -> None:
message_struct = Message_struct(
user_id=message.from_id, messenger="tg", text=message.text
)
await send_to_server(message=message_struct)
def start_tg_client(self) -> None:
print(f"TG listening started")
executor.start_polling(self._dp, skip_updates=True)
if __name__ == "__main__":
from lib.bot.messengers_configs.tg_config import dp
tg_client = Tg_client(dp=dp)
tg_client.start_tg_client()
getattr(self, method_name)
) и вызываю оригинальный декоратор на нём с сохранёнными параметрами. Ведь декоратор - это функция, его можно вызывать как функцию.