Skip to content

InlineKeyboardButton

Eric Damian edited this page Feb 18, 2021 · 3 revisions

InlineKeyboardButton Object

This object represents one button of an inline keyboard. You must use exactly one of the optional fields.

Field Type Description
text String Label text on the button
url String Optional. HTTP or tg:// url to be opened when button is pressed
callback_data String Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes
switch_inline_query String Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field. Can be empty, in which case just the bot's username will be inserted.
switch_inline_query_current_chat String Optional. If set, pressing the button will insert the bot's username and the specified inline query in the current chat's input field. Can be empty, in which case only the bot's username will be inserted.

InlineKeyboard image


Utils

getInlineKeyboardButtonWithUrl()

Returns InlineKeyboardButton object with url field

from python_telegram_api import bot_utils

button1 = bot_utils.getInlineKeyboardButtonWithUrl('Button 1', 'https://github.com/xSklero/python-telegram-api')
print(button1)

>>> {'text': 'Button 1', 'url': 'https://github.com/xSklero/python-telegram-api'}

getInlineKeyboardButtonWithCallback()

Returns InlineKeyboardButton object with callback_data field

from python_telegram_api import bot_utils

button2 = bot_utils.getInlineKeyboardButtonWithCallback('Button 2', '12')
print(button2)

>>> {'text': 'Button 2', 'callback_data': '12'}

getInlineKeyboardButtonWithSwichInline()

Returns InlineKeyboardButton object with switch_inline_query field

from python_telegram_api import bot_utils

button3 = bot_utils.getInlineKeyboardButtonWithSwichInline('Button 3', 'Use this bot!')
print(button3)

>>> {'text': 'Button 3', 'switch_inline_query': 'Use this bot!'}

getInlineKeyboardButtonWithSwichInlineCurrentChat()

Returns InlineKeyboardButton object with switch_inline_query_current_chat field

from python_telegram_api import bot_utils

button4 = bot_utils.getInlineKeyboardButtonWithSwichInlineCurrentChat('Button 4', 'Use this bot!')
print(button4)

>>> {'text': 'Button 4', 'switch_inline_query_current_chat': 'Use this bot!'}