【发布时间】:2021-04-22 16:22:08
【问题描述】:
我正在尝试使用 PTB 制作一个超级简单的电报机器人。该机器人有一个按钮,当我单击该按钮时,机器人应该向网络发出 http 请求(无需打开浏览器)。并显示响应数据。这是我正在使用的一段代码:
def get_data():
response = requests.get('https://jsonplaceholder.typicode.com/posts/1').json()
return response['body']
def start(update, context) -> None:
inline_button = [
[
InlineKeyboardButton('test callback', callback_data=get_data())
]
]
reply_markup = InlineKeyboardMarkup(inline_button)
update.message.reply_text("Please choose:", reply_markup=reply_markup)
def button(update, context) -> None:
query = update.callback_query
query.answer()
TEXT = f"<h3>{query.data}</h3>"
query.edit_message_text(text=TEXT, parse_mode=ParseMode.HTML)
# context.bot.send_message(chat_id=update.effective_chat.id, text=f'{query.data}')
它适用于硬编码值和 50 个字符以下的文本,但是当文本大小超过 80 个字符时,我会收到以下错误:
telegram.error.BadRequest: Button_data_invalid
我相信这是由于电报限制 64 字节文本?但在那种情况下,一些机器人如何在一条消息中显示数千个字符数据?我到底做错了什么?
【问题讨论】:
-
或者,你知道,Telegram 实际上并不想要你一次发送这么多文本,因为它对真正的人类来说很糟糕谁必须看到它。
标签: python telegram telegram-bot python-telegram-bot telegram-webhook