Python 电报机器人。键盘和以异步方式将选项另存为变量
我有一个非常简单的任务,在简单的Python中是这样的Python 电报机器人。键盘和以异步方式将选项另存为变量,python,bots,telegram,telegram-bot,Python,Bots,Telegram,Telegram Bot,我有一个非常简单的任务,在简单的Python中是这样的 faculty_list = ['CS', 'Philology', 'LA'] inpt = input('Choice the faculty: ') if inpt in faculty_list: n = input('Choice question number') print(data[inpt][int(n)]) # pandas lookup for the question in the table els
faculty_list = ['CS', 'Philology', 'LA']
inpt = input('Choice the faculty: ')
if inpt in faculty_list:
n = input('Choice question number')
print(data[inpt][int(n)]) # pandas lookup for the question in the table
else:
print('There is no such faculty!')
然而,在电报中开发这样一种算法是相当困难的。第一个键盘
选择列表中的教员
,教员列表作为选项。这个选择被记录在内存中。在此键盘之后,进入列表中的第二个也是最后一个键盘选择问题,其中包含预定义问题列表,并可查阅教员(熊猫数据框中的列)和问题(熊猫数据框中的行)
我没有为电报开发bot的任何经验,也不知道如何简单地为特定用户保存变量
@dp.message_handler(commands='start')
async def start_cmd_handler(message: types.Message):
keyboard_markup = types.ReplyKeyboardMarkup(row_width=3)
btns_text = tuple(data.columns.to_list()) # list of buttons generated from the pandas dataframe.
keyboard_markup.row(*(types.KeyboardButton(text) for text in btns_text))
await message.reply("Good evening! Please choice your faculty.", reply_markup=keyboard_markup)
# how to save the choice that user have chosen?
多谢各位