matrix-rss-bridge silently fails when a blog post is too large (for example, matrix.org's post dated 19th April).
The first issue here, is that the API functions don't return anything:
await self._send_room(room_id=room_id,
Changing that function to return the result, I get an object that tells me it failed to send because the message was over the limit of 65,536. However, I'd expect an exception to be thrown if there was an error, so ideally this function could check the response and throw an exception if it failed.
Second issue is to have a convenient way to send such large messages automatically. It would be nice if it simply split the message nicely and sent it in parts without needing to implement that logic in each application.
This is the code I created so far:
while msg:
if len(msg) > 30000:
i = msg.rfind("\n", 0, 30000)
part = msg[:i]
msg = msg[i+1:]
else:
part = msg
msg = ""
await self._bot.api.send_markdown_message(room_id, part)
One problem is that I think .send_markdown_message() includes the content twice (as HTML and MD?), which means that I can't tell how big the message will actually be, but my actual limit is likely 30,000-35,000 bytes. I've just cut it at 30,000 bytes for now, which seems to be working, but may be splitting some messages unnecessarily.
This can also mess up formatting by cutting in the middle of a code/quote block or similar. Maybe it would be better to try and look for <h1> to split at, then falling back to h2 and h3 before falling back to \n.
matrix-rss-bridge silently fails when a blog post is too large (for example, matrix.org's post dated 19th April).
The first issue here, is that the API functions don't return anything:
https://codeberg.org/imbev/simplematrixbotlib/src/commit/fda7fa0f19876f9fa128624f3e4f4c644b7ccc43/simplematrixbotlib/api.py#L296
Changing that function to return the result, I get an object that tells me it failed to send because the message was over the limit of 65,536. However, I'd expect an exception to be thrown if there was an error, so ideally this function could check the response and throw an exception if it failed.
Second issue is to have a convenient way to send such large messages automatically. It would be nice if it simply split the message nicely and sent it in parts without needing to implement that logic in each application.
This is the code I created so far:
```
while msg:
if len(msg) > 30000:
i = msg.rfind("\n", 0, 30000)
part = msg[:i]
msg = msg[i+1:]
else:
part = msg
msg = ""
await self._bot.api.send_markdown_message(room_id, part)
```
One problem is that I think .send_markdown_message() includes the content twice (as HTML and MD?), which means that I can't tell how big the message will actually be, but my actual limit is likely 30,000-35,000 bytes. I've just cut it at 30,000 bytes for now, which seems to be working, but may be splitting some messages unnecessarily.
This can also mess up formatting by cutting in the middle of a code/quote block or similar. Maybe it would be better to try and look for `<h1>` to split at, then falling back to h2 and h3 before falling back to `\n`.