Z
Z
Zero None2021-11-09 19:51:44
Python
Zero None, 2021-11-09 19:51:44

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:

spoiler

@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("|")) # Получаю данные, после чего превращаю в список
    ...


It is not very convenient for me to shove all the text into one line, and then break it into parts.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-11-09
@ZERRITO

No, just like that.
But no one forbids stuffing json or base64 there

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question