A
A
Anatoly Belousov2021-08-12 15:49:49
Python
Anatoly Belousov, 2021-08-12 15:49:49

How to add inline button in telegram bot?

How to make an inline button with such an arrow? : 611518bdd044f379038761.jpeg
What would such a menu appear when you click on it above the keyboard? : 611518e14276a198249114.jpeg
I use the PyTelegramBotApi library

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2021-08-12
@no_name_774

Enable the bot's inline mode.
Send an inline keyboard with a parameter switch_inline_query_current_chatequal to, say, "Accumulators"
Add an inline_handler in which to catch the query and generate the desired results

@bot.message_handler(commands=['start'])
def send_start(message):
    markup = InlineKeyboardMarkup()
    markup.add(InlineKeyboardButton('Аккумуляторы', switch_inline_query_current_chat='Аккумуляторы'))
    bot.send_message(message.chat.id, 'Товары', reply_markup=markup)


@bot.inline_handler(lambda query: query.query == 'Аккумуляторы')
def query_video(inline_query):
    r = InlineQueryResultArticle('1', 'SONY VTC6 3000 mah 30A 18650', InputTextMessageContent('Аккумулятор 1'), description='blah', url='https://buy-battery.com/goods/1', hide_url=True, thumb_url='https://via.placeholder.com/50')
    r2 = InlineQueryResultArticle('2', 'SONY VTC5A 2600 mah 35A 18650', InputTextMessageContent('Аккумулятор 2'), description='blah', url='https://buy-battery.com/goods/2', hide_url=True, thumb_url='https://via.placeholder.com/50')
    bot.answer_inline_query(inline_query.id, [r, r2])

Help:
https://core.telegram.org/bots/api#inline-mode
https://github.com/eternnoir/pyTelegramBotAPI/blob...

M
Mikhail Krostelev, 2021-08-12
@twistfire92

Most likely you are interested in the parameter switch_inline_query_current_chat , see here .
To do this, you will need to configure the bot to work in inline mode.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question