Не работает кнопка назад в Telebot
Всем привет, кто то может подсказать, как починить кнопку назад в меню? Пытался как мог, но ничего не получается
from telebot import types # для указание типов
import configure
bot = telebot.TeleBot(configure.config['token']) # токен в файле config
@bot.message_handler(commands=['start']) #создаем команду
def first_menu(message):
markup = types.InlineKeyboardMarkup(row_width=1)
btn1 = types.InlineKeyboardButton(text = "Узнать сумму к оплате", callback_data = 'sum_opl' )
btn2 = types.InlineKeyboardButton("Оплатить",callback_data = 'oplata' )
btn3 = types.InlineKeyboardButton("Передать показания",callback_data = 'per_pokaz' )
btn4 = types.InlineKeyboardButton("Скачать электронную квитанцию",callback_data = 'download')
btn5 = types.InlineKeyboardButton("Регистрация",callback_data = 'reg' )
markup.add(btn1,btn2,btn3,btn4,btn5)
bot.send_message(message.chat.id, "?Здравствуйте! Что Вы хотите сделать?".format(message.from_user), reply_markup=markup)
types.ReplyKeyboardRemove(selective= True)
@bot.callback_query_handler(func = lambda call:True)
def answer(call):
text = 'Введите номер лицевого счета (9 цифр). Номер лицевого счета можно посмотреть в квитанции.'
img2 = open('photo2.jpeg','rb')
btn_menu = types.InlineKeyboardButton("назад", callback_data = 'menu' )
markup = types.InlineKeyboardMarkup(row_width=1)
if call.data == 'sum_opl':
markup.add(btn_menu)
bot.send_photo(call.message.chat.id, img2, text, reply_markup=markup)
elif call.data == 'oplata':
markup.add(btn_menu)
bot.send_photo(call.message.chat.id, img2, text, reply_markup=markup)
elif call.data == 'per_pokaz':
markup.add(btn_menu)
bot.send_photo(call.message.chat.id, img2, text, reply_markup=markup)
elif call.data == 'download':
markup.add(btn_menu)
bot.send_photo(call.message.chat.id, img2, text, reply_markup=markup)
elif call.data == 'reg' :
markup.add(btn_menu)
bot.send_photo(call.message.chat.id, img2, text, reply_markup=markup)
elif call.data == 'menu':
return
bot.polling(none_stop=True, interval=0)
Ответы (1 шт):
Автор решения: Артём
→ Ссылка
Починил. Вот исправный и рабочий код
import telebot
from telebot import types # для указание типов
import configure
bot = telebot.TeleBot(configure.config['token']) # токен в файле config
@bot.message_handler(commands=['start']) # создаем команду
def first_menu(message):
markup = types.InlineKeyboardMarkup(row_width=1)
btn1 = types.InlineKeyboardButton(text="Узнать сумму к оплате", callback_data='sum_opl')
btn2 = types.InlineKeyboardButton("Оплатить", callback_data='oplata')
btn3 = types.InlineKeyboardButton("Передать показания", callback_data='per_pokaz')
btn4 = types.InlineKeyboardButton("Скачать электронную квитанцию", callback_data='download')
btn5 = types.InlineKeyboardButton("Регистрация", callback_data='reg')
markup.add(btn1, btn2, btn3, btn4, btn5)
bot.send_message(message.chat.id, "?Здравствуйте! Что Вы хотите сделать?".format(message.from_user),
reply_markup=markup)
types.ReplyKeyboardRemove(selective=True)
@bot.callback_query_handler(func=lambda call: True)
def answer(call):
text = 'Введите номер лицевого счета (9 цифр). Номер лицевого счета можно посмотреть в квитанции.'
img2 = open('photo2.jpeg', 'rb')
btn_menu = types.InlineKeyboardButton("назад", callback_data='menu')
markup = types.InlineKeyboardMarkup(row_width=1)
if call.data == 'sum_opl':
markup.add(btn_menu)
bot.send_photo(call.message.chat.id, img2, text, reply_markup=markup)
elif call.data == 'oplata':
markup.add(btn_menu)
bot.send_photo(call.message.chat.id, img2, text, reply_markup=markup)
elif call.data == 'per_pokaz':
markup.add(btn_menu)
bot.send_photo(call.message.chat.id, img2, text, reply_markup=markup)
elif call.data == 'download':
markup.add(btn_menu)
bot.send_photo(call.message.chat.id, img2, text, reply_markup=markup)
elif call.data == 'reg':
markup.add(btn_menu)
bot.send_photo(call.message.chat.id, img2, text, reply_markup=markup)
elif call.data == 'menu':
first_menu(call.message)
bot.polling(none_stop=True, interval=0)