[英]Python-telegram-bot How to send InlineKeyboard via url
Trying to send message with callback keybord attached to it, bot no good. 尝试发送附加了回调keybord的消息,bot不好。 Tels me
给我打电话
TypeError: must be str, not ReplyKeyboardMarkup
Can't find any exemples how to do it correctly. 找不到任何示例如何正确执行。
keyboard = [[InlineKeyboardButton("Выполнено", callback_data='Done')],
[InlineKeyboardButton("MAC", callback_data='MAC'),
InlineKeyboardButton("Phone", callback_data='Phone'),
InlineKeyboardButton("История", callback_data='History')]]
reply_markup = ReplyKeyboardMarkup(keyboard)
requests.post(url='https://api.telegram.org/bot{blah}/'
'sendMessage?chat_id=' + str(query.message.chat_id) + '&text="TEST"&reply_markup=' + reply_markup)
Firstly, you should use InlineKeyboardMarkup
instead of ReplyKeyboardMarkup
to craete the markup object made of InlineKeyboardButton
s. 首先,你应该使用
InlineKeyboardMarkup
而不是ReplyKeyboardMarkup
来作出了解创建的标记对象InlineKeyboardButton
秒。
Then, you probably should simply use the bot
object to send the message with bot.send_message(query.message.chat_id, 'TEST', reply_markup=reply_markup)
. 然后,您可能应该只使用
bot
对象通过bot.send_message(query.message.chat_id, 'TEST', reply_markup=reply_markup)
发送消息。
Lastly, if you really really need to use requests
to do manual HTTP request, you should provide the parameters in the requests.post()
's data
. 最后,如果确实需要使用
requests
来执行手动HTTP请求,则应在requests.post()
的data
提供参数。
import json
import requests
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
keyboard = [[InlineKeyboardButton("Выполнено", callback_data='Done')],
[InlineKeyboardButton("MAC", callback_data='MAC'),
InlineKeyboardButton("Phone", callback_data='Phone'),
InlineKeyboardButton("История", callback_data='History')]]
reply_markup = InlineKeyboardMarkup(keyboard)
data = {"chat_id": query.message.chat_id,
"text": "TEST",
"reply_markup": json.dumps(reply_markup.to_dict())}
requests.post(url='https://api.telegram.org/bot{blah}/sendMessage', data=data)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.