简体   繁体   English

Telegram 允许的 callback_data 大小小于 file_id 大小

[英]Telegram permitted callback_data size less than file_id size

I need to resend file id in callback data like that:我需要像这样在回调数据中重新发送文件ID:

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但是file_id的大小,我得到

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). https://github.com/eternnoir/pyTelegramBotAPI的标准方法)超过允许的 callback_data 大小(1-64 字节)。

Actual size for callback_data 's strings is 128 bytes for cd1 and 132 bytes for cd2. callback_data字符串的实际大小对于 cd1 为 128 字节,对于 cd2 为 132 字节。

file_id looks like DQACAgIAAxkDAAIHZ14-nxWa7ckt2ZG7UQMrq_PuxIxRAAK4BQACzfj4SdBn7Y70cYWSGAQ and size is 120 bytes. file_id看起来像DQACAgIAAxkDAAIHZ14-nxWa7ckt2ZG7UQMrq_PuxIxRAAK4BQACzfj4SdBn7Y70cYWSGAQ ,大小为 120 字节。

Any ideas?有任何想法吗? Really hope on your help.真的希望得到你的帮助。

I had the same problem and looks like there is no way to send a file_id in the callback data.我遇到了同样的问题,看起来无法在回调数据中发送file_id

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.如果您从发送给机器人的消息中获取file_id ,则可以使用message_id来解决,它是一个渐进式索引,用于标识聊天中的消息。

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.不幸的是,Telegram API 没有一种方法可以让您恢复具有其 id 的过去消息,但是当您收到消息时,您可以存储映射message_id -> file_id (在内存或数据库中)并将密钥作为 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.当然这不是世界上最好的东西,但我认为这是我们可以拥有的最好的东西,直到他们增加 callback_data 的大小。

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 .我遇到了同样的问题,我通过将file_id存储在包含以下内容的表中来解决它: id (int) 和file_id (text) 并将它的id写在callback_data中。 When I receive callback_data with id, I can get the file_id当我收到带有 id 的callback_data时,我可以获得file_id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python 电报机器人 api 内联键盘按钮没有得到回调数据 - python telegram bot api inlinekeyboardbutton not getting callback_data 如何在 InlineKeyboardButton python 电报中同时使用 callback_data 和 url - How to use both callback_data and url in InlineKeyboardButton python telegram 使用电报机器人通过 file_id 发送大型视频文件 - Send large video file by file_id with telegram bot 如何通过python-telegram-bot接收file_id? - How to receive file_id through python-telegram-bot? 如何在 python-telegram-bot 中获取 file_id(语音)? - How can take file_id (voice) in python-telegram-bot? 避免 Telegram 的文件大小限制 - Avoid Telegram's file size limit mjpeg @ 0x27ee9e0缓冲区小于最小缓冲区大小:如何创建小于最小缓冲区大小的视频文件? - mjpeg @ 0x27ee9e0 buffer smaller than minimum size: How to create a video file with size less than the minimum buffer size? 如何获取文件大小小于500mb的Windows文件列表? - how to get list of files on windows which have file size less than say 500mb? 如何使用 python PIL 库压缩小于限制文件大小的图片? - How to compress a picture less than a limit file size using python PIL library? Bot无法通过file_id发送频道照片 - Bot can't send channel photo by file_id
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM