title: Python Telegram Bot how to wait for user answer to a question And Return It
body: <p><strong>Context:</strong></p>
  
  <p>I am using <a href="https://github.com/eternnoir/pyTelegramBotAP" rel="noreferrer">PyTelegramBotAPi</a> or <a href="https://github.com/python-telegram-bot/python-telegram-bot" rel="noreferrer">Python Telegram Bot</a></p>
  
  <p>I have a code I am running when a user starts the conversation.</p>
  
  <p>When the user starts the conversation I need to send him the first picture and a question if He saw something in the picture, the function needs to wait for the user input and return whether he saw it or not.</p>
  
  <p>After that, I will need to keep sending the picture in a loop and wait for the answer and run a bisection algorithm on it.</p>
  
  <p><strong>What I have tried so far:</strong></p>
  
  <p>I tried to use reply markup that waits for a response or an inline keyboard with handlers but I am stuck because my code is running without waiting for the user input.</p>
  
  <p><strong>The code:</strong></p>
  
  <pre><code>@bot.message_handler(func=lambda msg: msg in ['Yes', 'No'])
  @bot.message_handler(commands=['start', 'help'])
  def main(message):
      """
      This is my main function
      """
      chat_id = message.chat.id
      try:
          reply_answer = message.reply_to_message.text
      except AttributeError:
          reply_answer = '0'
      # TODO : should wait for the answer asynchnonossly
      def tester(n, reply_answer):
          """
          Displays the current candidate to the user and asks them to
          check if they see wildfire damages.
          """
          print('call......')
          bisector.index = n
          bot.send_photo(
              chat_id=chat_id,
              photo=bisector.image.save_image(),
              caption=f"Did you see it Yes or No {bisector.date}",
              reply_markup=types.ForceReply(selective=True))
          # I SHOUL WAIT FOR THE INPUT HERE AND RETURN THE USER INPUT
          return eval(reply_answer)
      culprit = bisect(bisector.count, lambda x: x, partial(tester, reply_answer=reply_answer) )
      bisector.index = culprit
      bot.send_message(chat_id, f"Found! First apparition = {bisector.date}")
  
  
  bot.polling(none_stop=True)
  </code></pre>
  
  <p>The algorithm I am running on the user input is something like this :</p>
  
  <pre><code>def bisect(n, mapper, tester):
      """
      Runs a bisection.
  
      - `n` is the number of elements to be bisected
      - `mapper` is a callable that will transform an integer from "0" to "n"
        into a value that can be tested
      - `tester` returns true if the value is within the "right" range
      """
  
      if n &lt; 1:
          raise ValueError('Cannot bissect an empty array')
  
      left = 0
      right = n - 1
  
      while left + 1 &lt; right:
          mid = int((left + right) / 2)
  
          val = mapper(mid)
          tester_values = tester(val) # Here is where I am using the ouput from Telegram bot
          if tester_values:
              right = mid
          else:
              left = mid
  
      return mapper(right)
  </code></pre>
  
  <p>I hope I was clear explaining the problem, feel free to ask any clarification.
  If you know something that can point me in the right direction in order to solve this problem, let me know.</p>
  
  <p>I have tried a similar question but I am not getting answers.</p>