ehForwarderBot / efb-telegram-master

EFB Telegram Master Channel, a channel for EH Forwarder Bot.
GNU Affero General Public License v3.0
223 stars 79 forks source link

Implement a per-chat message queue or similar for incoming messages #88

Open blueset opened 4 years ago

blueset commented 4 years ago

Currently (since 2.0.0b26), ETM is using a single message worker thread to process all incoming messages from the Bot admin in order to maintain a proper message order, and processing messages from slave channels on a per-call basis sent to Telegram.

While this former measure does help bring a proper message order, this is blocking all incoming messages in all chats when the worker is trying to process large (usually media) messages. This is obviously a behavior that we don‘t want to have in ETM. The latter is seemingly is not blocking, but this could result in a out-of-order message thread when a specific message needs to take more time than others.

I‘d like to look for help/suggestions to solve this problem by maintain a per-chat message order consistency while prevent blocking as far as possible. That could be a per-chat message queue or anything that could serve the same purpose.

blueset commented 4 years ago

For messages from slave channels, @catbaron0 and @wolfsilver has suggested to use a placeholder first create a message at the “correct position”, then process and upload the actual media.

This is a viable solution to this problem as it works with majority ETM-supported messages types, and seemingly reduces the first request (the placeholder request) to a single simple request. Telegram Bot API (and user API) allows sending media with resources pre-exist on its server, and modifying message media to one of animation, document, audio, photo, video.

To implement this feature, we need to send the placeholder message (preferably a picture) once per bot, and store the file ID somewhere (potentially in the database).

On the other hand, this method does not support some message types frequently used by ETM, namely stickers and voice messages, which means these messages could still be out of order.

If there is no better solution found for this issue, I‘d recon that this shall be implemented as a partial solution to this problem after ETM has a stable version released (i.e. when ETM has a acceptable amount of tests available).

And as always, PRs are welcomed.

catbaron0 commented 4 years ago

send the placeholder message (preferably a picture) once per bot

Would it be better (or possible) to send an empty(0 kb) file as the placeholder?

wolfsilver commented 4 years ago

send the placeholder message (preferably a picture) once per bot

Would it be better (or possible) to send an empty(0 kb) file as the placeholder?

I think if show a picture like this would be better.

image

blueset commented 4 years ago

send the placeholder message (preferably a picture) once per bot

Would it be better (or possible) to send an empty(0 kb) file as the placeholder?

Telegram (both user API and bot API) rejects empty file to be sent. Even if it’s possible, that might not be as visually appealing and straight forward than a picture.

blueset commented 4 years ago

As for the picture, I’d personally prefer something language-neutral, since translating image resources could be kinda painful sometimes.

And this is a prototype I made just now: etm-loading-card

... and how it looks like on Telegram:

image image

catbaron0 commented 4 years ago

Cool. But still I prefer some description of the file type in the text field.

blueset commented 4 years ago

Cool. But still I prefer some description of the file type in the text field.

That could be done in the caption.