'Python-Telegram-Bot use multiple callback_data data when using InlineKeyboard?

Hello I want to pass multiple data in callback_data(list,json,dict anything) when using InlineKeyboard
like this:

def help_command(update: Update, context: CallbackContext) -> None:
    update.message.reply_text("Use /start to test this bot.")
    keyboard = [[InlineKeyboardButton("Test", callback_data=['1','2'])]
    reply_markup = InlineKeyboardMarkup(keyboard)
    update.message.reply_text('Please choose:', reply_markup=reply_markup)

Any solution to solve this problem and thanks.



Solution 1:[1]

That is not possible in telegram, the data type supported by callback is a byte of size 64. Which may also not big enough for the data you are sending.

A wise choice is to initiate a global dictionary and add your data as value and user id as key.

example:

...declare a dictionary on the top of the file....

TINY_DB = {}

...add...

global TINY_DB

TINY_DB[chat_id] = ["this is my big data", 1, 2, "another data"]

...retrive...

if chat_id in TINY_DB: .... no data

else data = TINY_DB[chat_id]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1