How to wait for the user answer and keep the answer for select

I want to make a telegram Bot for monthly salary. the user sends the user name, then password. the bot send the salary information. The problem is here, the user sends the command of salary, I want to send bot: user name user: tiger bot: password user: 985468

I have problem for waiting for the user and also keep for the first message(username).

3 answers

  • answered 2017-08-12 10:03 PurTahan

    Keep User Action Step and User Input Data in DataBase. and in every received message check User Action Step to do correct job.

  • answered 2017-08-12 10:05 Sean

    You can send Hi Sean, please enter your password with ForceReply, and read .message.reply_to_message.text field.

    I think this is the only way to solve this problem, but I suggest you to use your own database like other answers.

  • answered 2017-08-12 13:47 91DarioDev

    telegram APIs doesn't allow you to do this. You can do this with several methods though.

    • you could use your database to store the status of this conversation
    • you could ask to the user to reply to your messages so you can check what message the reply is to
    • you could use inline keyboards when it's possibile (a choice to select) so you can check the callback_data
    • you could ask to the user to start the message with a particular keyword
    • you could ask the user to write all in one message maybe dividing with a char and then you split that char

    Now what is better for the user?

    • for the user is better the first option, so you store the status of the conversation in the database and after the bot gets the message you check the status of the conversation and you get what is referred to

    What is better for you?

    • i would say that for you is better to use the reply hack, so you don't need a database to store the status of the chat for every user. You can use the force_reply param to make it more clear for the user.

    • i would recommend to use inline keyboards when it's possibile because they make things easier using callback_data. for example you are asking for the age to the user and you could reply with 80 buttons (100 is the limit) and he could press the right age. This is better because you don't have to worry about strange cases when the user write text instead of numbers (e.g. he writes ten instead of 10) and you don't need to check status on the db or check a reply. you just check the callback_data. An idea is that each button could have a callback_data starting with "age_{age option}" and you handle the callback_data starting with age_ taking only the last part. you don't need db, you don't need to check replies, you don't need to handle strange cases when user sends a wrong format, you only need to handling the callback