Telegram Bot профиль с календарем - PullRequest
0 голосов

Я пишу профиль бота. После ответа следует задать следующий вопрос. На одном из этапов вам нужно выбрать дату. Пользуюсь готовым календарем. Но после выбора даты следующий вопрос не задается, но сценарий не обрабатывает sh, а только ждет ввода и выдает исключение, определенное в приведенном ниже коде. Как исправить, что бы возник следующий вопрос «Как тебя зовут?». Спасибо. Вот часть кода, которая включает предыдущий вопрос календаря и следующий вопрос:

def process_Personenanzahl_step(message):
    try:
        chat_id = message.chat.id
        user = user_dict[chat_id]
        user.carModel = message.text

        markup = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True)
        itembtn1 = types.KeyboardButton('1')
        itembtn2 = types.KeyboardButton('2')
        itembtn3 = types.KeyboardButton('3')
        itembtn4 = types.KeyboardButton('4')
        itembtn5 = types.KeyboardButton('5')
        markup.add(itembtn1, itembtn2, itembtn3, itembtn4, itembtn5)

        msg = bot.send_message(chat_id, 'Qun', reply_markup=markup)
        bot.register_next_step_handler(msg, check_calendar_messages)

    except Exception as e:
        bot.reply_to(message, 'ooops!!')



calendar_1 = CallbackData("calendar_1", "action", "year", "month", "day")


def check_calendar_messages(message):
    now = datetime.datetime.now()  # Get the current date
    bot.send_message(
        message.chat.id,
        "Selected date",
        reply_markup=telebot_calendar.create_calendar(
            name=calendar_1.prefix,
            year=now.year,
            month=now.month,  # Specify the NAME of your calendar
        ),
    )


@bot.callback_query_handler(func=lambda call: call.data.startswith(calendar_1.prefix))
def callback_inline(call: object) -> object:
    # At this point, we are sure that this calendar is ours. So we cut the line by the separator of our calendar
    name, action, year, month, day = call.data.split(calendar_1.sep)
    # Processing the calendar. Get either the date or None if the buttons are of a different type
    date = telebot_calendar.calendar_query_handler(
        bot=bot, call=call, name=name, action=action, year=year, month=month, day=day
    )
    # There are additional steps. Let's say if the date DAY is selected, you can execute your code. I sent a message.
    if action == "DAY":
        msg = bot.send_message(
            chat_id=call.from_user.id,
            text=f"You have chosen {date.strftime('%d.%m.%Y')}",
            reply_markup=ReplyKeyboardRemove(),
        )
        print(f"{calendar_1}: Day: {date.strftime('%d.%m.%Y')}")
        bot.register_next_step_handler(msg, process_fullname_step)


def process_fullname_step(message):
    try:
        chat_id = message.chat.id
        user_dict[chat_id] = User(message.text)


        markup = types.ReplyKeyboardRemove(selective=False)

        msg = bot.send_message(chat_id, 'What is your name?', reply_markup=markup)
        bot.register_next_step_handler(msg, process_fullname_step)

    except Exception as e:
        bot.reply_to(message, 'ooops!!')
...