Skip to content

Commit

Permalink
Add /bot-command handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Kudinov committed Apr 17, 2024
1 parent 4353a2e commit b8f1599
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/bot/commands/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion app/services/answers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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```"
)

0 comments on commit b8f1599

Please sign in to comment.