skip to Main Content
def process_color_step(message):
    chat_id = message.chat.id
    product.color = message.text
    msg = bot.send_message(chat_id, 'ok, send me a photo of your phone')
    bot.register_next_step_handler(msg,process_image_step)

def process_image_step(message):
    chat_id = message.chat.id
    product.image = message.photo[1].file_id
    msg = bot.send_message(chat_id, 'Ok, send me a description of your phone?')
    bot.register_next_step_handler(msg,process_description_step)

Above is snippets of the code. The image file_id is passed on to product.image.

2

Answers


  1. I would use an image library to try to load the file. Something like pillow would do the trick.

    Login or Signup to reply.
  2. You can use message handler as a list of handlers. for example in your conversation handler:

    conv_handler = ConversationHandler(
        entry_points=[CommandHandler('start', start)],
        states={
            PHOTO: [MessageHandler(Filters.photo, 'your function for getting photo),
                    MessageHandler(Filters.all, 'your function for wrong entry),]
    }
    )
    

    In this case if user update isn’t photo, first MessageHandler for getting photo is not acceptable so handler try to catch next MessageHandler in the list:

    MessageHandler(Filters.all, 'your function for wrong entry) 
    

    you have to define a function to response to user wrong entry and put it in second element of handlers list.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search