elif call.data == 'oxota':
photo = open(r"C:\Users\Вадим\Downloads\msg5595864732-34949.jpg", 'rb')
bot.send_photo(call.message.chat.id, photo=photo, caption='Содержимое:\nTehthesththththht')
@bot.message_handler(commands=['start'])
def start(message):
buttons = types.InlineKeyboardMarkup()
button1 = types.InlineKeyboardButton("button 1", callback_data="1")
button2 = types.InlineKeyboardButton("button 2", callback_data="2")
buttons.add(button1, button2)
bot.send_message(message.chat.id, "кнопочки", reply_markup=buttons)
@bot.callback_query_handler(func=lambda c: True)
def callback(c):
if c.data == '1':
bot.send_message(c.message.chat.id, "Вы нажали на кнопку 1!")
if c.data == '2':
bot.send_message(c.message.chat.id, "Вы нажали на кнопку 2!")
from telegram import InlineKeyboardMarkup, InlineKeyboardButton
from telegram.ext import Updater, CallbackQueryHandler
def start(update, context):
keyboard = [[InlineKeyboardButton("Нажми меня", callback_data='oxota')]]
reply_markup = InlineKeyboardMarkup(keyboard)
update.message.reply_text('Привет! Нажми кнопку:', reply_markup=reply_markup)
def button(update, context):
query = update.callback_query
if query.data == 'oxota':
photo_path = r"C:\Users\Вадим\Downloads\msg5595864732-34949.jpg"
caption = 'Содержимое:\nTehthesththththht'
with open(photo_path, 'rb') as photo:
query.message.reply_photo(photo=photo, caption=caption)
updater = Updater('YOUR_TOKEN', use_context=True)
updater.dispatcher.add_handler(CallbackQueryHandler(button))
updater.dispatcher.add_handler(CommandHandler('start', start))
updater.start_polling()
updater.idle()