skip to Main Content

I need to resend file id in callback data like that:

cd1 = 'publish {}'.format(new_file_id)
cd2 = 'delayed 1 {} *'.format(new_file_id)
...
markup = types.InlineKeyboardMarkup(1)
btn1 = types.InlineKeyboardButton(text='Publish',
                                      callback_data=cd1)
btn2 = types.InlineKeyboardButton(text='Delayed publication',
                                      callback_data=cd2)
markup.add(btn1, btn2)

bot.edit_message_reply_markup(message.chat.id, msg.message_id, reply_markup=markup)

But size of file_id, which I get as

new_file_id = msg.video_note.file_id

(Standard method of https://github.com/eternnoir/pyTelegramBotAPI)
more than permitted callback_data size (1-64 bytes).

Actual size for callback_data‘s strings is 128 bytes for cd1 and 132 bytes for cd2.

file_id looks like DQACAgIAAxkDAAIHZ14-nxWa7ckt2ZG7UQMrq_PuxIxRAAK4BQACzfj4SdBn7Y70cYWSGAQ and size is 120 bytes.

Any ideas? Really hope on your help.

2

Answers


  1. I had the same problem and looks like there is no way to send a file_id in the callback data.

    If you are taking the file_id from a message sent to your bot, a workaround can be using the message_id which is a progressive index that identifies the message in the chat.

    Unfortunately Telegram API doesn’t have a method which let you recover a past message having its id, but when you receive the message you may store a mapping message_id -> file_id (in memory or in a db) and pass the key in as callback_data.

    Sure it’s not the best thing in the world but I think it’s the best thing we can have until they increase the size of callback_data.

    Login or Signup to reply.
  2. I had the same problem and I solved it with storing file_id in a table containing: id (int) and file_id(text) and wrote it’s id in callback_data. When I receive callback_data with id, I can get the file_id

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search