Send Image or Document with Inline Menu

Viewed 1837

I am coding an Python Telegram Bot with python-telegram-bot. I created a custom inline menu.

I want that the User could press a button and will get an picture. The send_photo function needs an instance of bot an update.

But I don't know how to pass that on to the CallBackQuery handler.

Does anyone have an idea how to solve it?

The send photo function:

def gvu(bot, update):
    bot.send_photo(update.message.chat_id, photo=open('botpic/gvu.jpg', 'rb'))

The Handler in Main Routine:

updater.dispatcher.add_handler(CallbackQueryHandler(pattern="1", callback=gvu))
return self.callback(dispatcher.bot, update, **optional_args)

The error:

TypeError: callback_handler() got an unexpected keyword argument 'chat_data'

2 Answers

This works for me:

    buttonsMenu = [
    [telegram.InlineKeyboardButton("UP", callback_data="UpVote")],
    [telegram.InlineKeyboardButton("DOWN", callback_data="DownVote")],
    ]
    keyboard_markup = telegram.InlineKeyboardMarkup(buttonsMenu)
    context.bot.sendPhoto(chat_id=update.message.chat.id, photo=open('./imgpath.jpg'), 'rb'),caption='messageText', reply_markup=keyboard_markup)
     

This will send an image, with text and 2 butttons below the text msg.

Now for the callback query, i did this in main():

# Callbacks for the msg buttons
dp.add_handler(CallbackQueryHandler(vote, pattern="UpVote"))
dp.add_handler(CallbackQueryHandler(vote, pattern="DownVote"))

Where vote , is a def that runs the code i want for that callback. hope it makes sense.

Related