telegraf-keyboard
v1.1.5
Published
Keyboard builder for Telegraf
Downloads
48
Readme
Telegraf Keyboard Builder
Simple keyboard builder for Telegraf
Installation
Just use npm
npm i telegraf-keyboard --save
Example
const Telegraf = require('telegraf');
const Keyboard = require('telegraf-keyboard');
//...
const bot = new Telegraf(process.env.BOT_TOKEN);
bon.on('text', (ctx) => {
const options = {
inline: false, // default
duplicates: false, // default
newline: false, // default
};
const keyboard = new Keyboard(options);
keyboard
.add('Item 1', 'Item 2', 'Item 3') // first line
.add('Item 10') // second line
.remove('Item 2')
.rename('Item 10', 'Item 2')
ctx.reply('Keyboard', keyboard.draw());
})
More examples you may find in example
API
Create keyboard
const Keyboard = require('telegraf-keyboard');
const keyboard = new Keyboard(options);
Arguments
options
- object (optional)
Options
inline
- iftrue
then the keyboard will be inline (default: false)duplicates
- iftrue
then allow adding buttons with the same name (default: false)newline
- iftrue
each button will be on a new line else iffalse
then eachadd
will move button to new line (default: false)
keyboard.add(buttons)
keyboard
.add('Button 1', 'Button 2')
.add(['Button 3', 'Button 4'])
if the inline
option is set then you can add an action for the button through the colon, but this is not necessary
keyboard
.add('Button 1:action 1', 'Button 2:action 2')
.add(['Button 3:action 3', 'Button 4'])
In this example, Button 1
has action action 1
, Button 2
has action action 2
, but Button 4
has action Button 4
Arguments
button
- string array or arguments
keyboard.rename(button_old, button_new)
Not for inline keyboard
keyboard
.add('Button 1')
.rename('Button 1', 'Button 0')
Button 1
now has title Button 0
keyboard.remove(button)
Not for inline keyboard
keyboard
.add('Button 1', 'Button 2')
.remove('Button 1')
keyboard.draw()
bot.reply('Keyboard', keyboard.draw());
keyboard.clear()
bot.reply('Keyboard', keyboard.clear());