mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-09 17:33:44 +00:00
Bot getter in TelegramObject.
This commit is contained in:
parent
14d250bfbd
commit
d98566bf7f
1 changed files with 8 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ import typing
|
|||
import ujson
|
||||
from typing import TypeVar
|
||||
|
||||
from ..utils.context import get_value
|
||||
from .fields import BaseField
|
||||
|
||||
PROPS_ATTR_NAME = '_props'
|
||||
|
|
@ -126,6 +127,13 @@ class TelegramObject(metaclass=MetaTelegramObject):
|
|||
"""
|
||||
return cls(**data)
|
||||
|
||||
@property
|
||||
def bot(self):
|
||||
bot = get_value('bot')
|
||||
if bot is None:
|
||||
raise RuntimeError('Can not found bot instance in current context!')
|
||||
return bot
|
||||
|
||||
def to_python(self) -> typing.Dict:
|
||||
"""
|
||||
Get object as JSON serializable
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue