D
D
Denys_Arys2020-08-12 08:25:41
Python
Denys_Arys, 2020-08-12 08:25:41

Telegram bot. How to repeat the output of buttons if the user entered text, and did not select one of the options?

Good afternoon.
I want to conduct a dialogue with the client using buttons so that he always chooses one of the options offered.
For example, if a person is looking for an apartment, first he must choose one of the cities, then the district in the previously selected city, etc. For example, if at the step of choosing a city, a person did not select any of the options, but entered the text, I would like to repeat the previous message with the city selection buttons, changing the caption to something like "Choose one of the proposed options." I can't figure out how to do it correctly.

import config
import telebot
from telebot import types  # кнопки
from string import Template
from datetime import datetime
import time
import pymssql


permissions = config.permissions
bot = telebot.TeleBot(config.API_BOT_TEST_TOKEN, threaded=False)

@bot.message_handler(commands=['start'])
def test_message(message):
    chat_id = message.chat.id
    markup = telebot.types.InlineKeyboardMarkup()
    markup.add(telebot.types.InlineKeyboardButton(text='Алматы', callback_data='city_Алматы'))
    markup.add(telebot.types.InlineKeyboardButton(text='Нур-Султан', callback_data='city_Нур-Султан'))
    bot.send_message(chat_id, 'Choose your city', reply_markup=markup)


@bot.callback_query_handler(func=lambda call: 'city' in call.data)
def query(call):
    bot.send_message(call.from_user.id, 'Хорошо, город сохранен')
    bot.edit_message_reply_markup(call.from_user.id, message_id=call.message.message_id)



##### Какой обработчик тут должен быть и что он должен содержать, чтобы объяснить пользователю, что он должен выбрать один из предложенных вариантов, в случае, если он ввел текст вместо того, чтобы сделать выбор?


bot.polling()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Studentka1996, 2020-08-12
@Studentka1996

If I understand the problem correctly. Use if else

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question