Eleirbag89 / TelegramBotPHP

A very simple PHP Telegram Bot API for sending messages.
http://eleirbag89.github.io/TelegramBotPHP
MIT License
812 stars 342 forks source link

How can I ask user for an input (like email)? #249

Closed aghorbanmehr closed 2 years ago

aghorbanmehr commented 3 years ago

Hi, First of all thanks for this great telegram bot PHP. I have started to use it. but I have a question! How can I ask the user for input (like email) and wait until they answer? I need to do something like a survey! ask some questions and wait for a related answer and then ask another qustion!

Thanks.

Mohsen322 commented 3 years ago

Hi there You should use database. Just save a keyword for every question. For example: user start bot. The bot say please enter your name. U can save user_id and next step keyword.

Next time first of all check keyword and store user entry related the saved keyword. Hope help you

matinkg commented 3 years ago

o

Hi, First of all thanks for this great telegram bot PHP. I have started to use it. but I have a question! How can I ask the user for input (like email) and wait until they answer? I need to do something like a survey! ask some questions and wait for a related answer and then ask another qustion!

Thanks.

Hi, it's impossible with telegram bot API to store the user state. You should store users' states in a database. Suppose we want a robot that has a main menu. In the main menu, there are two buttons, "Email" and "Phone Number". If user clicked on each of them, we want to take a value from the user. The bot should work like this:

If (new user send a message to our bot) => we set their initial state which is main_menu


For current users:
    if (users state = main_menu):
        if (sent text = "email") => change user state to "enter_email"
        else if (sent text = "phone") => change user state to "enter_phone"
        else => users answer is incorrect

    else if (user state = enter_email):
        if (sent text was an email address) => store user's email address and change user state to "main_manu"
        else => users answer is incorrect

    else if (user state = enter_phone):
        if (sent text was an phone number) => store user's phone number and change user state to "main_manu"
        else => users answer is incorrect```
stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.