A
A
artem201520002015-08-07 15:22:45
css
artem20152000, 2015-08-07 15:22:45

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

3 answer(s)
M
Maxim Timofeev, 2019-01-21
@Leh_ryb

This is an ordinary accordion or a hamburger or collapse , there are a lot of ready-made scripts.

V
Viktor Paperno, 2015-08-08
@AviPaperno

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()

The bottom line is that a custom keyboard simply allows you to type words or characters not by letter, but immediately.

B
black443, 2016-06-20
@black443

Is it possible to arrange something similar, as in the picture , for example, the button is called
yes it is
, when the button is pressed, the
\yes command is executed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question