V
V
Vyacheslav Grachunov2019-04-07 13:29:21
Python
Vyacheslav Grachunov, 2019-04-07 13:29:21

How to update custom keyboard in telegram?

There is a bot in python, I use telebot (pyTelegramBotAPI).
/start adds a custom keyboard with several buttons to the user - ( telebot.types.ReplyKeyboardMarkup() ). Now I need to add a couple more buttons there. But the user's keyboard is updated only if he does / start again, which he is unlikely to do.
How to make it update automatically?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2019-04-07
@Qwentor

When sending any message, you can refresh the keyboard.

bot = telebot.TeleBot(token)

keyboard = types.ReplyKeyboardMarkup()
bot.send_message(message.chat.id, 'Сообщение', reply_markup=keyboard)

It remains to send all users a message with a new keyboard. For example, collect all the chat_ids of the current users into the list users_list and:
@bot.message_handler(commands=["new_keyboard_for_all_users"])
def send_new_keyboard (message):
    keyboard = types.ReplyKeyboardMarkup() # Новая клавиатура
    for user in users_list:
        bot.send_message(user, 'Произвольное сообщение', reply_markup=keyboard)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question