How to split user input data telegram. bot?

I'm writing the bot in the telegram, the bot has a button, when pressed, user input is processed through register_next_step_handler(), then there is a problem, for example: USER1 presses this button and enters a value, the value is stored in a variable and is stored there, but if you come by another user, click on this button, enter a value, the variable will be updated to enter the USER2, I need to separate both the users(there may be a limited number) to the input value are assigned to users how can I do that?
April 3rd 20 at 18:35
1 answer
April 3rd 20 at 18:37
Solution
you can use sqlite , then by userid to get the values
import sqlite3 as db
from sqlite3 import Error
import time


# handler for the start command will transfer the required fields from the message object to the function add user in dB
@bot.message_handler(commands=['start'])
def start(message):
 tupp = (message.from_user.id, message.from_user.username, message.from_user.first_name, message.from_user.last_name, time.ctime())
send_user_info(tupp)


# run once to create database and tables in it
with db.connect('bot_db') as connection:
 cursor = connection.cursor()
 cursor.execute("'CREATE TABLE IF NOT EXISTS USERS (user_id INTEGER NOT NULL PRIMARY KEY, first_name TEXT, last_name TEXT, username TEXT)"')


# calling a function 
def send_user_info(tup):
 connection = db.connect('bot_db'))
 cursor = connection.cursor()
try:
 cursor.execute("INSERT INTO USERS (user_id, username, first_name, last_name, reg_date) VALUES(?,?,?,?,?)", tup)
 except Error:
pass
connection.commit()
 connection.close()

Find more questions by tags PythonBotsTelegram