import { Keyboard } from "https://deno.land/x/grammy@v1.12.0/convenience/keyboard.ts";
Use this class to simplify building a custom keyboard (something like this: https://core.telegram.org/bots#keyboards).
// Build a custom keyboard:
const keyboard = new Keyboard()
.text('A').text('B').row()
.text('C').text('D')
// Now you can either pass it directly:
await ctx.reply('Here is your custom keyboard!', {
reply_markup: keyboard
})
// Or if you need to specify more options in `reply_markup`:
await ctx.reply('Here is your custom keyboard!', {
reply_markup: {
keyboard: keyboard.build(), // note the `build` call
one_time_keyboard: true,
}
})
Be sure to check out the documentation on custom keyboards in grammY.
Constructors
Initialize a new Keyboard
with an optional two-dimensional array of
KeyboardButton
objects. This is the nested array that holds the custom
keyboard. It will be extended every time you call one of the provided
methods.
Properties
Placeholder to be shown in the input field when the keyboard is active.
Resize the current keyboard according to its buttons. Usually, this will make the keyboard smaller.
Methods
Allows you to add your own KeyboardButton
objects if you already have
them for some reason. You most likely want to call one of the other
methods.
Returns the keyboard that was build. Note that it doesn't return
resize_keyboard
or other options that may be set. You don't usually
need to call this method. It is no longer useful.
Make the current keyboard one-time. See https://grammy.dev/plugins/keyboard.html#one-time-custom-keyboards for more details.
Keyboards are non-one-time by default, use this function to enable it
(without any parameters or pass true
). Pass false
to force the
keyboard to be non-one-time.
Set the current keyboard's input field placeholder. See https://grammy.dev/plugins/keyboard.html#input-field-placeholder for more details.
Adds a new contact request button. The user's phone number will be sent as a contact when the button is pressed. Available in private chats only.
Adds a new location request button. The user's current location will be sent when the button is pressed. Available in private chats only.
Adds a new poll request button. The user will be asked to create a poll and send it to the bot when the button is pressed. Available in private chats only.
Make the current keyboard resized. See https://grammy.dev/plugins/keyboard.html#resize-custom-keyboard for more details.
Keyboards are non-resized by default, use this function to enable it
(without any parameters or pass true
). Pass false
to force the
keyboard to be non-resized.
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 KeyboardButton
objects if you already have the
instances for some reason. You most likely don't want to pass any
arguments to row
.
Make the current keyboard selective. See https://grammy.dev/plugins/keyboard.html#selectively-send-custom-keyboards for more details.
Keyboards are non-selective by default, use this function to enable it
(without any parameters or pass true
). Pass false
to force the
keyboard to be non-selective.
Adds a new text button. This button will simply send the given text as a text message back to your bot if a user clicks on it.
Adds a new web app button. The Web App that will be launched when the user presses the button. The Web App will be able to send a “web_app_data” service message. Available in private chats only.