Closed da1z closed 2 months ago
This is a contradiction. If you want to save the session data from each update, then you have to process the messages in sequence.
If you want to cancel the update processing of one update while processing another update, then these updates have to be processed concurrently.
So in summary, you want to process updates both sequentially and not sequentially at the same time, which does not make sense.
@KnorpelSenf maybe I explained it wrong, my use case is very simple. I have gpt like bot, when user sends message my bot generates response, all messages I save in history in session. what i want to do is if users sends 2 messages fast, i want to cancel response to first message and reply to second message only, but i still want to keep first message in context in history object in session.
You just repeated the same contradiction.
The solution is not to use sessions. Use a database instead. This will give you control over when data is read and written, which should make it easy to implement the behaviour you're looking for.
Also note that you cannot store the entire message history in your session anyway due to performance issues.
Check out the docs on when to use sessions: https://grammy.dev/plugins/session#when-to-use-sessions
what I am trying to achieve: user sends message to my bot -> bot process message and replies user sends 5 messages really fast -> I want my bot to stop processing 1-4 messages(it least not reply to them) and reply only to message 5 but i still want to save session changes from all messages