-1

I am writing a new Bot for Telegram for the first time using PHP Telegram Bot.
Imagine I want to show What is your name? for /start command and wait for user's answer, wait for user's answer and then show Hello USER_NAME to him.

I could implement /start commands. But how can I get user's reply that is not in form of /command? Actually I need a listener to a non-command message.

Is there anyone who can help me?

Mohammad Saberi
  • 12,864
  • 27
  • 75
  • 127

2 Answers2

1

Mohammad Jan,

You should do it yourself. I suggest you to store the chats in a database table and then store the next command in a column for each chat.

Lets say after /start you're looking for the name of user so you will store /name into the next_command column and whenever you receive a normal message without any /command, then you can check the next_command column and consider the message received as an answer to "What's your name?" question.

You can continue this process to get the full data from the user. For example after getting the name you can ask "How old are you?" and change next_command to /old and then consider the next message as an answer for the previous question.

BTW, It's just a suggestion. You should be able to find the way that is suitable for you. But what is obvious, you should do it yourself since telegram only provide messages to your bot and it's your bot that manage them.

Hope it helps.

Hossein
  • 2,592
  • 4
  • 23
  • 39
  • absolutely I must do it myself. I did not asked about writing its code for me. I just did not find anything in documents. So I had to ask it here. May you tell me more about `next_command`? Does it belong to PHP Telegram Bot? – Mohammad Saberi Jun 05 '17 at 11:31
  • No it's not related to telegram bot or any library that you're using. It's my suggested name for column name of chats table. Please check my reply again. – Hossein Jun 05 '17 at 14:15
-1

Goto @BotFather, and turn off privacy mode

/setprivacy — Set which messages your bot will receive when added to a group. With privacy mode disabled, the bot will receive all messages.

Sean Wei
  • 7,433
  • 1
  • 19
  • 39