-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Description
Please answer these questions before submitting your issue. Thanks!
- What version of pyTelegramBotAPI are you using?
- 4.11.0
- What OS are you using?
- Mac m1
- What version of python are you using?
- python=3.8
Hi guys I have an issue with converting my telebot to an async telebot, I have a callback_query_handler that creates a menu for user to select an option
# Handler for creating user menu
@bot.callback_query_handler(func=None, config=create_menu_factory.filter())
async def create_menu_callback(call: types.CallbackQuery):
callback_data: dict = create_menu_factory.parse(callback_data=call.data)
product_id = int(callback_data['create_menu_id'])
menu = MENU[product_id] # i.e, {'id': '0', 'name': 'Create New user'}
if (menu['id'] == '0'):
msg = await bot.reply_to(call.message,f"Enter a name for the user")
await bot.register_next_step_handler(msg, process_name_step)
and a function process_name_step() :
- Spin up a menu keyboard
- According to what the user selects, enter the information accordingly
- Tried using states in this function, but not really familiar how it works
@bot.message_handler(state=MyStates.number)
async def process_contact_number_step(message):
try:
chat_id = message.chat.id
# contact_number = message.text
await bot.send_message(message.chat.id, 'Please select the following:', reply_markup=create_user_menu_keyboard())
await bot.set_state(message.from_user.id, MyStates.number, message.chat.id)
async with bot.retrieve_data(message.from_user.id, message.chat.id) as data:
data['contact_number'] = message.text
if chat_id in contact_num_dict:
contact_num_dict[chat_id].append(data['contact_number'])
else:
contact_num_dict[chat_id] = data['contact_number']
print(contact_num_dict)
except Exception as e:
await bot.reply_to(message, 'broken')
Basically what I need is to create a menu > when user chooses an options it will lead to another menu > prompt user to enter the information > store the information
Metadata
Metadata
Assignees
Labels
No labels