Make RichText Dictionaryable - #2610
Conversation
Make RichText Dictionaryable Conform the fact that RichText can be str or list also.
There was a problem hiding this comment.
Pull request overview
Adds recursive dictionary serialization for rich text values used in outgoing rich messages.
Changes:
- Makes
RichTextdictionary-serializable. - Serializes strings, lists, and nested rich-text objects.
- Updates input rich blocks to use recursive serialization.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
It needs the same fix for captions too. |
|
I saw RichBlockxxx, but I did not found, where it is used. I'll re-check, thank you. |
|
It's used in the rich block InputMedia types (InputRichBlockAudio, InputRichBlockPhoto, InputRichBlockVideo, etc). The caption is a RichBlockCaption class and both fields are RichText as well. |
Done |
|
|
RichBlockTableCell + |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (2)
telebot/types.py:14797
- The new recursive serialization path has no regression coverage. Please add
tests/test_types.pycases for a plain string, a nested list containing aRichTextsubtype, and a deserializedRichTextobject passed through anInputRichBlock; these are the failure modes described by issue #2609 and would also catch missing subtype fields.
def richtext_to_dict(richtext: Union[str, List[RichText], RichText]):
if isinstance(richtext, str):
return richtext
elif isinstance(richtext, list):
return [RichText.richtext_to_dict(item) for item in richtext]
elif isinstance(richtext, RichText):
return richtext.to_dict()
telebot/types.py:15762
- Optional
textis currently serialized asnullwhen omitted.InputRichMessage.to_json()dumps this dictionary directly, but the field contract says omission makes the cell invisible andnullis not a validRichTextvalue. Build the required fields first and addtextonly when it is notNone.
'text': RichText.richtext_to_dict(self.text),
|
I did a bunch of testing and everything I tried sending as a rich message seems to work. There's a chance I might have missed something but it seems okay now. |
|
When setting horizontal_accuracy to None in InputRichBlockMap.location, it gets passed to the API as None (I'm guessing). I just took the location received and sent it right back out without modifying it, then got an error. Edit: Even when I don't set horizontal_accuracy at all I still get the error. |
|
A big mess from my side, sorry @Badiboy |
|
The location is not None, only the horizontal_accuracy of it. |
|
I must be drunk sorry |
It's not a problem at all. It was a huge update, you made huge work, I made a review. It's normal working process ) |
Fixed optional field in Location. It looks like an long-time bug, thank you! ) |


Make RichText Dictionaryable
Conform the fact that RichText can be str or list also.
Address #2609