G
G
gigisarri982021-10-29 17:09:32
Software design
gigisarri98, 2021-10-29 17:09:32

How to save user state in session in telegram chatbot?

Learning to make a telegram bot using the library https://github.com/TelegramBot/Apiand Laravel. Let's say I want to make a bot that manages quizzes (User can create and complete quizzes stored in the database and stuff like that). I can't understand one thing: how to remember the user's state? I understand that it is possible to use a database or an entry in a text file on the server, but I found the answer that it is possible to do this in sessions using radish. I changed the session driver from normal to Redis in the settings - sessions are correctly recorded, everything is fine. But, when it comes to the telegram, it creates a new storage key in Redis with each request, so it is no longer possible to get a session entry made in the previous message. Can you please tell me how to implement this functionality? Or maybe there is an option how to make such chains of related messages in telegram without sessions? Thanks in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Shumov, 2021-10-30
@gigisarri98

The session key just needs to be managed by yourself based on the user ID in the message.
In fact, in technical terms, there cannot be a user session in a bot, so I would recommend reading about the State Machine and storing states in general. And you can always hammer nails with a microscope, but why

V
Vladislav Orlov, 2021-10-29
@haveacess

I do not fully understand how everything is implemented. but try to bind to chat_id in telegram. Unique user ID. On it and shove what you need

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question