M
M
Maxim Kuznetsov2021-09-06 21:52:40
Python
Maxim Kuznetsov, 2021-09-06 21:52:40

How to undress users in a telegram bot?

hello dear gurus. tell. I wrote a telegram bot using the TeleBot library in Python. At startup, the bot is authorized by api on a certain service. the bottom line is that if I log in on one device, the other device immediately enters the session of the first device. all bot users use only one session. how to change it?

data = {
        "data": {
            "login": login, #[email protected]
            "password": password #novikov
        },
        "request": {
            "method": "login",
            "model" : "auth",
            "module": "quickfox"
        }
    }
        #подключение к базе
    url = 'http://b2b.i-t-p.pro/api/2'
    data_json = json.dumps(data)
    response = requests.post(url, data=data_json)
    sys.stdout.write(response.text)
    r = response.json()
    if r['success'] == True:
        session = r['session']
        main_menu(message)
    else:
        bot.send_message(message.from_user.id, 'Неверный логин или пароль. попробуйте снова')
        bot.register_next_step_handler(message, get_login)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2021-09-16
@mosx1

To solve your problem, you need to create a database where each user will store either a session key or authorization data.
The implementation itself must be asynchronous, otherwise the session state of one user may fall into the context of another.
As I understand you are using api vk. Then the best solution would be to ask the user for a token with the right permissions, and store it in the database as long as it is valid, and request a new one in case of revocation. When processing any request from the user, its entry in the database is associated, and a request is made to the api for its token.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question