Answer the question
In order to leave comments, you need to log in
How to do event handling in telegram keyboard in python?
In general, python has a library for working with telegram api https://pypi.python.org/pypi/python-telegram-bot/1.5 (this is it). There's a feature to add a custom keyboard. I need to make a function execute when the button is clicked, how to do it?
PS code for adding a keyboard:
custom_keyboard =
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
self.todo.sendMessage(chat_id = self.chat_id, text = 'Hello', reply_markup=reply_markup)
Answer the question
In order to leave comments, you need to log in
This is an ordinary accordion or a hamburger or collapse , there are a lot of ready-made scripts.
I don't know how to do it in your library, but in this one it's done like this:
import telebot
from telebot import types
API_TOKEN = '<api_token>'
bot = telebot.TeleBot(API_TOKEN)
@bot.message_handler(commands=['help', 'start'])
def send_welcome(message):
markup = types.ReplyKeyboardMarkup(one_time_keyboard=True)
markup.add('1', '2') #Имена кнопок
msg = bot.reply_to(message, 'Test text', reply_markup=markup)
bot.register_next_step_handler(msg, process_step)
def process_step(message):
chat_id = message.chat.id
if message.text=='1':
func1()
else:
func2()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question