Skip to content

Commit 6763a71

Browse files
committed
Fix InputRichMessage/RichMessage to match Bot API spec
InputRichMessage takes html/markdown/is_rtl/skip_entity_detection strings, not page_blocks. RichMessage uses 'blocks' (not 'page_blocks') and adds is_rtl.
1 parent 917068b commit 6763a71

1 file changed

Lines changed: 36 additions & 12 deletions

File tree

telebot/types.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15628,41 +15628,65 @@ class RichMessage(JsonDeserializable):
1562815628

1562915629
Telegram documentation: https://core.telegram.org/bots/api#richmessage
1563015630

15631-
:param page_blocks: List of block elements composing the message
15632-
:type page_blocks: :obj:`list` of :class:`RichBlock`
15631+
:param blocks: Content of the message
15632+
:type blocks: :obj:`list` of :class:`RichBlock`
15633+
15634+
:param is_rtl: Optional. True, if the rich message must be shown right-to-left
15635+
:type is_rtl: :obj:`bool`
1563315636

1563415637
:return: Instance of the class
1563515638
:rtype: :class:`RichMessage`
1563615639
"""
15637-
def __init__(self, page_blocks: Optional[List[RichBlock]] = None, **kwargs):
15638-
self.page_blocks: Optional[List[RichBlock]] = page_blocks
15640+
def __init__(self, blocks: Optional[List[RichBlock]] = None, is_rtl: Optional[bool] = None, **kwargs):
15641+
self.blocks: Optional[List[RichBlock]] = blocks
15642+
self.is_rtl: Optional[bool] = is_rtl
1563915643

1564015644
@classmethod
1564115645
def de_json(cls, json_string):
1564215646
if json_string is None: return None
1564315647
obj = cls.check_json(json_string)
15644-
if 'page_blocks' in obj:
15645-
obj['page_blocks'] = [RichBlock.de_json(b) for b in obj['page_blocks']]
15648+
if 'blocks' in obj:
15649+
obj['blocks'] = [RichBlock.de_json(b) for b in obj['blocks']]
1564615650
return cls(**obj)
1564715651

1564815652

1564915653
class InputRichMessage(Dictionaryable, JsonSerializable):
1565015654
"""
15651-
Describes a rich message to transmit via sendRichMessage.
15655+
Describes a rich message to be sent. Exactly one of the fields html or markdown must be used.
1565215656

1565315657
Telegram documentation: https://core.telegram.org/bots/api#inputrichmessage
1565415658

15655-
:param page_blocks: List of block elements composing the message
15656-
:type page_blocks: :obj:`list` of :class:`RichBlock`
15659+
:param html: Optional. Content of the rich message to send described using HTML formatting
15660+
:type html: :obj:`str`
15661+
15662+
:param markdown: Optional. Content of the rich message to send described using Markdown formatting
15663+
:type markdown: :obj:`str`
15664+
15665+
:param is_rtl: Optional. Pass True if the rich message must be shown right-to-left
15666+
:type is_rtl: :obj:`bool`
15667+
15668+
:param skip_entity_detection: Optional. Pass True to skip automatic detection of entities
15669+
(e.g., URLs, email addresses, username mentions, hashtags, cashtags, bot commands,
15670+
or phone numbers) in the text
15671+
:type skip_entity_detection: :obj:`bool`
1565715672

1565815673
:return: Instance of the class
1565915674
:rtype: :class:`InputRichMessage`
1566015675
"""
15661-
def __init__(self, page_blocks: List[RichBlock]):
15662-
self.page_blocks: List[RichBlock] = page_blocks
15676+
def __init__(self, html: Optional[str] = None, markdown: Optional[str] = None,
15677+
is_rtl: Optional[bool] = None, skip_entity_detection: Optional[bool] = None):
15678+
self.html: Optional[str] = html
15679+
self.markdown: Optional[str] = markdown
15680+
self.is_rtl: Optional[bool] = is_rtl
15681+
self.skip_entity_detection: Optional[bool] = skip_entity_detection
1566315682

1566415683
def to_dict(self):
15665-
return {'page_blocks': [b.to_dict() for b in self.page_blocks]}
15684+
d = {}
15685+
if self.html is not None: d['html'] = self.html
15686+
if self.markdown is not None: d['markdown'] = self.markdown
15687+
if self.is_rtl is not None: d['is_rtl'] = self.is_rtl
15688+
if self.skip_entity_detection is not None: d['skip_entity_detection'] = self.skip_entity_detection
15689+
return d
1566615690

1566715691
def to_json(self):
1566815692
return json.dumps(self.to_dict())

0 commit comments

Comments
 (0)