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 15, 2024
1 parent 4353a2e commit 5af3b4d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 9 additions & 0 deletions app/bot/commands/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
)

from app.resources import strings
from app.services.answers import build_incoming_bot_command_text

collector = HandlerCollector()

Expand Down Expand Up @@ -53,3 +54,11 @@ async def help_handler(message: IncomingMessage, bot: Bot) -> None:
async def git_commit_sha(message: IncomingMessage, bot: Bot) -> None:
"""Show git commit SHA."""
await bot.answer_message(environ.get("GIT_COMMIT_SHA", "<undefined>"), message)


@collector.command("/bot-command", description="Message with body & command")
async def bot_command_handler(message: IncomingMessage, bot: Bot) -> None:
"""Show bot command data."""
await bot.answer_message(
build_incoming_bot_command_text(message)
)
9 changes: 8 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, IncomingMessage, Image, UserFromSearch
from pybotx_smartapp_rpc import SmartApp

from app.services.beautify import beautify_dict
Expand Down Expand Up @@ -64,3 +64,10 @@ async def build_static_image_url(image_file: Image, smartapp: SmartApp) -> str:
)

return link


def build_incoming_bot_command_text(message: IncomingMessage) -> str:
return (
f"Incoming body:\n```{message.body}```\n\n"
f"Incoming data:\n```{beautify_dict(message.data)}```\n"
)

0 comments on commit 5af3b4d

Please sign in to comment.