diff --git a/src/handlers/__init__.py b/src/handlers/__init__.py index de78f74..c1c0298 100644 --- a/src/handlers/__init__.py +++ b/src/handlers/__init__.py @@ -4,6 +4,7 @@ import simplematrixbotlib as botlib from src.handlers.help import help_handler from src.handlers.city import city_list_handler, select_city_handler from src.handlers.company import company_list_handler, select_company_handler +from src.handlers.category import category_list_handler from src.handlers.user import register_handler from src.fmt.city_formatter import CityFormatter @@ -46,3 +47,6 @@ def setup(bot: botlib.Bot, prefix: str): company_name = formatter.get_name_from_parts(match.args()) await select_company_handler(bot=bot, room_id=room.room_id, sender=message.sender, admin_id=bot.config.admin_id, company_name=company_name) + if match.command('category-list'): + await category_list_handler(bot=bot, room_id=room.room_id, sender=message.sender, admin_id=bot.config.admin_id) + diff --git a/src/handlers/category.py b/src/handlers/category.py new file mode 100644 index 0000000..587c010 --- /dev/null +++ b/src/handlers/category.py @@ -0,0 +1,23 @@ +import simplematrixbotlib as botlib +import aiohttp +import asyncio +import ujson +from src.config.dots_bot_api_config import DotsBotApiConfig + +from src.api.v2.category_api import CategoryAPI +from src.fetcher.v2.api_fetcher import ApiFetcher +from src.fmt.category_formatter import CategoryFormatter + +dots_bot_api_config = DotsBotApiConfig() + +async def category_list_handler(room_id: str, bot: botlib.Bot, sender: str, admin_id: str): + + session = aiohttp.ClientSession(json_serialize=ujson.dumps) + apiFetcher = ApiFetcher(dots_bot_api_config.get_base_url(), session) + formatter = CategoryFormatter() + categoryAPI = CategoryAPI(apiFetcher, formatter) + + msg: str = await categoryAPI.get_objects_message(sender) + + await bot.api.send_markdown_message(room_id=room_id, message=msg) +