Andrea Rossi
Andrea Rossi

Reputation: 45

How to manage more users in a telegram bot?

I did a telegram bot with python, who send a message like

if message == '/start':
    bot.sendMessage(chat_id, "Insert your name:")
    a = 'name'
if a == 'name' and message != '/start'
    name_user = message
    bot.sendMessage(chat_id, "Insert your birthday:")
    a = 'birth'
    and so on for other information...

the problem came when at the same time two users use my bot because the first user change 'a' so the second start with the birth and not with the name, can someone help me please?

Upvotes: 4

Views: 6122

Answers (3)

Abdul Gandal
Abdul Gandal

Reputation: 97

You should to consider a database, create it using sqlite3. Into the database create a table which corrisponds to each user (eg. table: db(str(chat.id))). And into each table create columns where you could put the information of your users (including also chat.id).

Upvotes: 0

Majid Askari
Majid Askari

Reputation: 590

You need to use a database for that purpose. have a field called State with a primary field of user's ChatID. after each response from your users check the state of that user from db.

Sean's answer is also correct but this way you will lose your users states if your program restarts for some reason.

Upvotes: 0

Sean Wei
Sean Wei

Reputation: 7975

Store with user ID.

a[chat_id] = name

Upvotes: 2

Related Questions