3

I'm developing a Telegram Bot via PHP and I want users to answer bot question.

For Example:
Bot: What is your name?
User: (Reply)

But I don't know how to process user reply for specific question from bot.

If I receive user reply via webhook, it doesn't contain last bot message, and I don't know what question this reply is.

Webhook has parameter callback_query, but it works only for messages that contains inline keyboard.

Can you help please?

Andrii Short
  • 51
  • 1
  • 5
  • Look at a conversation handler. Or write your own logic using getUpdates / webhook calls. – 0stone0 Mar 10 '22 at 11:36
  • Does this answer your question? [Telegram Conversation bot in python](https://stackoverflow.com/questions/64424744/telegram-conversation-bot-in-python) – 0stone0 Mar 10 '22 at 11:43

1 Answers1

-1

This process is called conversation. There are various ways to implement this.

The best and common way is to implement a Finite State Machine which will save the current state and accordingly, have a conversation with a user. Famous libraries like python-telegram-bot already implement it, which can give you a general idea on how to do this. Other ways can be storing last message in a database, etc; which is not recommended.

Shivang Kakkar
  • 421
  • 3
  • 15
  • This are just your own thoughts and no facts to support them. Rather give an example using python telegram bot. Also who says is not recommended to store thing in a DB? What if the server your bot is on power cycles, then you'll need some way to know the conversations that was going on. – 0stone0 Mar 10 '22 at 11:42
  • Answers are ment to be backed by facts. On the last one, you don't know what kinda bot OP is making, maybe he want to answer after 12h. – 0stone0 Mar 10 '22 at 12:41
  • @0stone0 if you think OP wants to ask "What is your name?" and reply to the answer after 12 hours then that's your specific "understanding". My answer and recommendation are for general cases and not such edge cases. – Shivang Kakkar Mar 10 '22 at 13:03