我希望我的电报机器人重复我发送给它的任何消息(它是一些要处理的 url),并且机器人应该将这个 url 回显给我,并使用表示为 InineKeyboardButtons 的几个处理选项(如“下载”、“重新发送”、“复制” ETC..)。 当我单击任何内联按钮时,将调用 keyboard_callback 方法。 我想从消息正文访问 url 和从 keyboard_callback 访问内联按钮回调数据(其中包含 url 处理操作名称)
是否有可能或者有更好的方法来实现我的目标?
async def echo(update: Update, context: CallbackContext) -> None:
keyboard = InlineKeyboardMarkup(inline_keyboard=[[InlineKeyboardButton('download', callback_data=f"/download"), InlineKeyboardButton('resend', callback_data='/resend')]])
await send_message(update=update, context=context, msg=update.message.text, keyboard=keyboard)
async def keyboard_callback(update, context):
query = update.callback_query
if '/download' in query.data:
download(url_from_message)
elif query.data == '/resend':
resend(url_from_message)
我尝试将 url 从消息正文传递到每个按钮的 callback_data,但它违反了电报 api 64 字节的限制。