4

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?

Andrea Rossi
  • 45
  • 1
  • 5
  • Consider *tying* the `a` variable to request sessions. – Moses Koledoye Sep 07 '17 at 15:04
  • How i can do this @MosesKoledoye ? – Andrea Rossi Sep 07 '17 at 15:57
  • Check out my answer [here](https://stackoverflow.com/questions/47267473/how-can-make-conversation-between-bot-and-user-with-telepot) It would fit to your question as well, but I'm not sure this is a duplicate, because your question is better - but I also don't want to copy-paste my answer – lucidbrot Mar 19 '18 at 08:59

3 Answers3

2

Store with user ID.

a[chat_id] = name
Sean Wei
  • 7,433
  • 1
  • 19
  • 39
0

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.

Majeed Askari
  • 550
  • 5
  • 15
0

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).

Abdul Gandal
  • 97
  • 1
  • 7