From b8f15998689389556f457acbdb0208f318774298 Mon Sep 17 00:00:00 2001 From: Ivan Kudinov Date: Mon, 15 Apr 2024 14:58:31 +0300 Subject: [PATCH] Add /bot-command handling --- app/bot/commands/common.py | 8 ++++++++ app/services/answers.py | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/bot/commands/common.py b/app/bot/commands/common.py index 709963a..cb5728f 100644 --- a/app/bot/commands/common.py +++ b/app/bot/commands/common.py @@ -13,10 +13,18 @@ ) from app.resources import strings +from app.services.answers import build_incoming_command_text collector = HandlerCollector() +@collector.default_message_handler +async def default_handler(message: IncomingMessage, bot: Bot) -> None: + """Show bot command data.""" + if message.data.get("command") is not None: + await bot.answer_message(build_incoming_command_text(message)) + + @collector.smartapp_event async def handle_smartapp_event(event: SmartAppEvent, bot: Bot) -> None: await bot.state.smartapp_rpc.handle_smartapp_event(event, bot) diff --git a/app/services/answers.py b/app/services/answers.py index 2fbf437..0cc21ca 100644 --- a/app/services/answers.py +++ b/app/services/answers.py @@ -2,7 +2,7 @@ from typing import Any, Dict from aiofiles.tempfile import SpooledTemporaryFile -from pybotx import File, Image, UserFromSearch +from pybotx import File, Image, IncomingMessage, UserFromSearch from pybotx_smartapp_rpc import SmartApp from app.services.beautify import beautify_dict @@ -64,3 +64,11 @@ async def build_static_image_url(image_file: Image, smartapp: SmartApp) -> str: ) return link + + +def build_incoming_command_text(message: IncomingMessage) -> str: + return ( + f"Incoming command:\n\n" + f"body:\n```\n{message.body}\n```\n\n" + f"data:\n```\n{beautify_dict(message.data)}\n```" + )