我写了一个电报机器人。一切顺利,运作良好。但是当我想使用它在 document 中提到的 ReplyKeyboardMarkup 时, 它不起作用!我的意思是键盘没有显示。
这个 JSON 对象有一个键 keyboard,根据它的文档,它的值是:
type: Array of Array of String.
description: Array of button rows, each represented by an Array of Strings
这是我发送请求的代码:
reply_markup = {'keyboard': [['1'],['2']], 'resize_keyboard': True, 'one_time_keyboard': True}
params = urllib.urlencode({
'chat_id': str(chat_id),
'text': msg.encode('utf-8'),
'reply_markup': reply_markup,
'disable_web_page_preview': 'true',
# 'reply_to_message_id': str(message_id),
})
resp = urllib2.urlopen(BASE_URL + 'sendMessage', params).read()
请您参考如下方法:
您必须单独将 reply_markup 序列化为 JSON 字符串,就像在这个答案 Telegram bot custom keyboard in PHP 中一样
