Context¶
For each command invoked, the first argument is always a Context
instance, which holds a lot of
metadata, and a few utility functions to help you write commands.
A lot of the time, these are the three main attributes you'll be using:
Context.room
(nio.MatrixRoom
) - the room the command was invoked in.Context.message
(nio.RoomMessageText
) - the message that invoked this command.Context.respond
- a utility class to help you respond to the command.
Command Context¶
Event-based context for a command callback
original_response
property
¶
original_response: Optional[RoomSendResponse]
The result of Context.reply(), if it exists.
respond
async
¶
respond(
content: Optional[str] = None,
file: Optional[BaseAttachment] = None,
reply_to: Optional[Union[RoomMessageText, str]] = None,
message_type: Optional[str] = None,
*,
content_type: Literal[
"plain", "markdown", "html", "html.raw"
] = "markdown",
override: Optional[dict] = None,
mentions: Union["Mentions", Literal[False], None] = None
) -> ContextualResponse
Responds to the current event.
See niobot.NioBot.send_message for more information.
Contextual Response¶
Context class for managing replies.
Usage of this function is not required, however it is a useful utility.
original_event
async
¶
original_event() -> Optional[RoomMessage]
Fetches the current event for this response
reply
async
¶
reply(
content: Optional[str] = None,
file: Optional[BaseAttachment] = None,
message_type: Optional[str] = None,
*,
content_type: Literal[
"plain", "markdown", "html", "html.raw"
] = "markdown",
override: Optional[dict] = None
) -> "ContextualResponse"
Replies to the current response.
This does NOT reply to the original invoking message.
See niobot.NioBot.send_message for more information.