Module

x/grammy/mod.ts

The Telegram Bot Framework.
Go to Latest
class InlineKeyboard
import { InlineKeyboard } from "https://deno.land/x/grammy@v1.10.1/mod.ts";

Use this class to simplify building an inline keyboard (something like this: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating).

// Build an inline keyboard:
const keyboard = new InlineKeyboard()
  .text('A').text('B', 'callack-data').row()
  .text('C').text('D').row()
  .url('Telegram', 'telegram.org')

// Send the keyboard:
await ctx.reply('Here is your inline keyboard!', {
  reply_markup: keyboard
})

Be sure to to check the documentation on inline keyboards in grammY.

Constructors

new
InlineKeyboard(inline_keyboard?: InlineKeyboardButton[][])

Initalize a new InlineKeyboard with an optional two-dimensional array of InlineKeyboardButton objects. This is the nested array that holds the inline keyboard. It will be extended every time you call one of the provided methods.

Methods

add(...buttons: InlineKeyboardButton[])

Allows you to add your own InlineKeyboardButton objects if you already have them for some reason. You most likely want to call one of the other methods.

game(text: string)

Adds a new game query button, confer https://core.telegram.org/bots/api#games

This type of button must always be the first button in the first row.

login(text: string, loginUrl: string | LoginUrl)

Adds a new login button. This can be used as a replacement for the Telegram Login Widget. You must specify an HTTPS URL used to automatically authorize the user.

pay(text: string)

Adds a new payment button, confer https://core.telegram.org/bots/api#payments

This type of button must always be the first button in the first row and can only be used in invoice messages.

row(...buttons: InlineKeyboardButton[])

Adds a 'line break'. Call this method to make sure that the next added buttons will be on a new row.

You may pass a number of InlineKeyboardButton objects if you already have the instances for some reason. You most likely don't want to pass any arguments to row.

switchInline(text: string, query?)

Adds a new inline query button. Telegram clients will let the user pick a chat when this button is pressed. This will start an inline query. The selected chat will be prefilled with the name of your bot. You may provide a text that is specified along with it.

Your bot will in turn receive updates for inline queries. You can listen to inline query updates like this:

bot.on('inline_query', ctx => { ... })
switchInlineCurrent(text: string, query?)

Adds a new inline query button that act on the current chat. The selected chat will be prefilled with the name of your bot. You may provide a text that is specified along with it. This will start an inline query.

Your bot will in turn receive updates for inline queries. You can listen to inline query updates like this:

bot.on('inline_query', ctx => { ... })
text(text: string, data?)

Adds a new callback query button. The button contains a text and a custom payload. This payload will be sent back to your bot when the button is pressed. If you omit the payload, the display text will be sent back to your bot.

Your bot will receive an update every time a user presses any of the text buttons. You can listen to these updates like this:

// Specific buttons:
bot.callbackQuery('button-data', ctx => { ... })
// Any button of any inline keyboard:
bot.on('callback_query:data',    ctx => { ... })
url(text: string, url: string)

Adds a new URL button. Telegram clients will open the provided URL when the button is pressed.

webApp(text: string, url: string)

Adds a new web app button, confer https://core.telegram.org/bots/webapps