InputRichBlock serialization assumes that every RichText value implements .to_dict(), but RichText fields can contain plain strings as well as RichText* objects (RichTextBold, etc). send_rich_message() fails during serialization for both cases. This is on the latest TeleBot version.
With a plain string:
rich_message = InputRichMessage(
blocks = [
InputRichBlockPreformatted(
text = "test",
language = ""
)
]
)
await bot.send_rich_message(chat_id=chat_id,rich_message=rich_message)
result:
File ".../telebot/types.py", line 16726, in to_dict
data['text'] = self.text.to_dict()
^^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'to_dict'
Using a RichText object:
rich_message = InputRichMessage(
blocks = [
InputRichBlockFooter(
text = RichTextBold(
text = "bold footer text"
)
)
]
)
await bot.send_rich_message(chat_id=chat_id,rich_message=rich_message)
result:
File ".../telebot/types.py", line 16696, in to_dict
data['text'] = self.text.to_dict()
^^^^^^^^^^^^^^^^^
AttributeError: 'RichTextBold' object has no attribute 'to_dict'
This also affects relaying received rich messages and trying to send them exactly as they were received, which I was attempting to do to test my bot's implementation, since received blocks contain nested RichText values that can be passed into the corresponding InputRichBlock objects. InputRichBlock*.to_dict() assumes "data['text'] = self.text.to_dict()" but RichText can recursively contain strings, lists, and other RichText* objects.
InputRichBlock serialization assumes that every RichText value implements .to_dict(), but RichText fields can contain plain strings as well as RichText* objects (RichTextBold, etc). send_rich_message() fails during serialization for both cases. This is on the latest TeleBot version.
With a plain string:
result:
Using a RichText object:
result:
This also affects relaying received rich messages and trying to send them exactly as they were received, which I was attempting to do to test my bot's implementation, since received blocks contain nested RichText values that can be passed into the corresponding InputRichBlock objects. InputRichBlock*.to_dict() assumes "data['text'] = self.text.to_dict()" but RichText can recursively contain strings, lists, and other RichText* objects.