Answer the question
In order to leave comments, you need to log in
How to pass multiple arguments to callback?
Using pyTelegramBotAPI
Is it possible to pass multiple arguments to callback other than via callback_data? In the latter case, you can only pass a string, but I would like to pass several values : what the user specified, the chat ID, and a few more. It looks something like this:
@bot.message_handler(commands=["echo"])
def send_echo(message):
content = " ".join( message.text.split(" ")[1:] )
types.InlineKeyboardMarkup().add(
types.InlineKeyboardButton("Отправить контент", callback_query=content+"|"+str(message.chat.id)+"|"+message.from_user.first_name) # Отправляю все данные
)
# Отправляю сообщение и прикрепляю кнопки ...
@bot.callback_query_handler(func=lambda callback: True)
def get_callback(callback):
print(callback.data.split("|")) # Получаю данные, после чего превращаю в список
...
Answer the question
In order to leave comments, you need to log in
No, just like that.
But no one forbids stuffing json or base64 there
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question