Help move the argument some_data into the callback_query_handler. #2076
Unanswered
AMDTonyRyzen
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
`import telebot
from telebot import types
bot = telebot.TeleBot("TOKEN")
def create_keyboard(keyboard_data:dict, row_width=1) -> dict:
keyboard = types.InlineKeyboardMarkup(row_width=row_width)
for text,callback in keyboard_data.items():
keyboard.add(types.InlineKeyboardButton(text=text,callback_data=callback))
keyboard.row()
return keyboard
@bot.callback_query_handler(func=lambda call:call.data)
def callback_worker(call):
bot.answer_callback_query(call.id)
if call.data=="test":
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="test") # text=str(some_data)
@bot.message_handler(content_types=["text"])
def main(message):
if message.text == "start":
some_data={"some":True,"data":True} #.... data for callback
bot.send_message(chat_id=message.chat.id,text=f"test",reply_markup=create_keyboard({"yes":"test","no":"no"}))
bot.infinity_polling(timeout=10, long_polling_timeout=5)`
Please Help me understand how it is possible to pass variables that are generated after receiving messages (some_data) to callback_query_handler without using a global variables.
Beta Was this translation helpful? Give feedback.
All reactions