【发布时间】:2020-08-05 14:24:36
【问题描述】:
我正在尝试使用viber-bot-python 和以下代码为 Viber 机器人构建键盘:
keyboard = {
"DefaultHeight": True,
"BgColor": self.background_color,
"Type": "keyboard",
"Buttons": [
{
"Columns": 2,
"Rows": 3,
"BgColor": "#e6f5ff",
"ActionType": 'reply',
"ActionBody": '1',
"ReplyType": "message",
"Text": '1'
},
{
"Columns": 2,
"Rows": 3,
"BgColor": "#e6f5ff",
"ActionType": 'reply',
"ActionBody": '2',
"ReplyType": "message",
"Text": '2'
},
{
"Columns": 2,
"Rows": 3,
"BgColor": "#e6f5ff",
"ActionType": 'reply',
"ActionBody": '3',
"ReplyType": "message",
"Text": '3'
},
{
"Columns": 2,
"Rows": 3,
"BgColor": "#e6f5ff",
"ActionType": 'reply',
"ActionBody": '4',
"ReplyType": "message",
"Text": '4'
},
{
"Columns": 1,
"Rows": 3,
"BgColor": "#e6f5ff",
"ActionType": 'reply',
"ActionBody": '5',
"ReplyType": "message",
"Text": '5'
}
]
}
并期望得到以下结构:
Select button:
[1] [2]
[3] [4]
[ 5 ]
但我得到以下异常:
File "\venv\lib\site-packages\viberbot\api\message_sender.py", line 53, in _post_request
raise Exception(u"failed with status: {0}, message: {1}".format(result['status'], result['status_message']))
Exception: failed with status: 3, message: keyboard is not valid. [numeric instance is greater than the required maximum (maximum: 2, found: 3)]
我已阅读有关 keyboard design 的主题,但没有帮助。 它有什么问题以及如何正确构建 Viber Bot 的键盘?
【问题讨论】:
标签: python viber viber-api viber-bot viber-bot-python