【发布时间】:2020-04-20 20:25:41
【问题描述】:
我有一本字典,其中有一个问题及其 ID。我遍历所有问题并将它们显示为按钮,然后当我单击按钮时,我应该返回此问题的 id,如何执行此操作??
def start(message):
r = requests.get("http://x.x.x.x/api/tests/list/getusertestlist", headers=headers)# I get JSON file
markup = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True)
for i in dp.values(r.json(), "/tests/*/value"):# value it's questions.
itembtn = types.KeyboardButton(i)
markup.add(itembtn)
bot.send_message(message.chat.id,"Get test",reply_markup=markup)
Structure JSON file.
{'tests': [{'description': 'Choose your preferred answer from the suggested ones.', 'id': 85, 'value': 'test 1'}, {'description': 'Choose your preferred answer from the suggested ones.', 'id': 88, 'value': 'test 1'}]}
最后我应该得到一个带有 2 个按钮测试 1 和测试 2 的键盘,当我点击测试 1 时,我应该得到它的 ID
【问题讨论】:
标签: python python-3.x telegram telegram-bot python-telegram-bot