New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-telegram-keyboard-wrapper

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-telegram-keyboard-wrapper

A support to create keyboards in Telegram via bots

  • 2.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
147
increased by241.86%
Maintainers
1
Weekly downloads
 
Created
Source

Node telegram keyboard wrapper

A support for telegram keyboards management, both inline and reply, and forceReply

This libray aims to provide a set of methods and classes to handle keyboards and force replies in node.js-written Telegram bots.

Built upon yagop's node-telegram-bot-api but can virtually work with any node.js telegram bot api wrapper.


Installation

From NPM:

npm install -s node-telegram-keyboard-wrapper

Downloading from Github, won't give the compiled version, so you'll have to do it by yourself.

npm build

Tests for methods used by ReplyKeyboard and InlineKeyboard are included.

# Installing dev dependencies
npm install -D
npm test

In examples folder, an example bot is available. It requires a bot token to be passed as argument.

npm run example -- 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11

Then just type /replyKeyboard (and answer or click to hide), /inlineKeyboard (and click to trigger) or /forceReply in your Telegram client to see the wrapper in action.

If you have any issue, suggestion of what else, feel free to open a topic in issues. 😉



API Reference



Classes architecture:

This library is divided in the following class architecture:

Visual Keyboard


This class get extended by both InlineKeyboards and ReplyKeyboards and extend ReplyMarkup class. Therefore, the methods inserted in here are valid for both.



Rows methods


.addRow()

Adds a new row with specified elements.

(new InlineKeyboard()).addRow(...keys) : this
(new ReplyKeyboard()).addRow(...keys) : this
ParametersDescriptionTypeOptionalDefault value
keysOne Object per buttonInlineKeyboardButtonfalse-

Returns the object itself for chaining;




.removeRow()

(new InlineKeyboard()).removeRow(index) : this
(new ReplyKeyboard()).removeRow(index) : this

Returns:

The object itself for chaining;

Description:

Removed a specific row.

Both row indexes index < 0 and index > rowQuantity, will make the counter restart from their opposite bound.

Arguments:

ParametersDescriptionTypeOptionalDefault value
indexThe row to be removed.Integerfalse-



.emptyRow()

(new InlineKeyboard()).emptyRow(index) : Number
(new ReplyKeyboard()).emptyRow(index) : Number

Returns:

The index of the emptied row.

Description:

Empty an entire row of keys but without removing the row.

Please note that both index < 0 and index > rowQuantity, will make the counter restart from their opposite bounds.

Arguments:

ParametersDescriptionTypeOptionalDefault value
indexThe row to be emptied.Integerfalse-



.popRow()

(new InlineKeyboard()).popRow(index) : (InlineKeyboardButton | KeyboardButton | string)[]
(new ReplyKeyboard()).popRow(index) : (InlineKeyboardButton | KeyboardButton | string)[]

Returns:

Returns the popped out row (array of the above element).

Description:

Pops out the last row of the keyboard.



.rowLength()

(new InlineKeyboard()).rowLength(index) : Number
(new ReplyKeyboard()).rowLength(index) : Number

Returns:

The length of a specific row.

Description:

Both row indexes index < 0 and index > rowQuantity, will make the counter restart from their opposite bounds.

Arguments:

ParametersDescriptionTypeOptionalDefault value
indexThe row to be emptied.Integerfalse-

Returns the amount of buttons in a row.




Buttons operations



.push()

(new InlineKeyboard()).push(index, ...elements) : Number;
(new ReplyKeyboard()).push(index, ...elements) : Number;

Returns:

The new length of the current row.

Description:

Adds elements to the specified row.

Both row indexes index < 0 and index > rowQuantity, will make the counter restart from their opposite bounds.

Arguments:

ParametersDescriptionTypeOptionalDefault value
indexThe index of the row in which push.Integerfalse-
... elementsThe elements to be pushedArray<InlineKeyboardButton>false-


.pop()

(new InlineKeyboard()).pop(index) : InlineKeyboardButton | KeyboardButton | string
(new ReplyKeyboard()).pop(index) : InlineKeyboardButton | KeyboardButton | string

Returns:

The popped out element.

Description:

Pops out the last element of a row. Both row indexes index < 0 and index > rowQuantity, will make the counter restart from their opposite bounds.

Arguments:

ParametersDescriptionTypeOptionalDefault value
indexThe row from which pop the last element.Integerfalse-


.reset()

(new InlineKeyboard()).reset()
(new ReplyKeyboard()).reset()

Description:

Wipes out the whole content. Probabily the most useless method. I mean: if you want to create a new keyboard, you don't wipe out your old, but create a brand new one.



Getter .length

(new InlineKeyboard()).length : Number
(new ReplyKeyboard()).length : Number

Returns:

The amount rows in the keyboard.



Inline Keyboards


Inline keyboards do not extend Visual Keyboard class with any new method.

Constructor

new InlineKeyboard(oneKey?);
ParametersDescriptionTypeOptionalDefault value
oneKeyFastest way to have one-button keyboard.InlineKeyboardButtontrue-




Reply Keyboards



// keep this always as valid
let replyKeyboard = new ReplyKeyboard();

Constructor

new ReplyKeyboard(oneKey?);
ParametersDescriptionTypeOptionalDefault value
oneKeyUseful for one-button only keyboards.KeyboardButton | Stringtrue-


.open()

replyKeyboard.open(options?);

Returns:

Keyboard structure to open a ReplyKeyboard.

Arguments:

ParametersDescriptionTypeOptionalDefault value
optionsOptions of the buttonObjecttrue{}
options.selectiveIf true, valid only for specific users (e.g. Mentioned), Users which replied the bot of original senderBooleantruefalse
options.one_time_keyboardHides the keyboard after the first usage.Booleantruefalse
options.resize_keyboardTells telegram client to use smaller buttonsBooleantruefalse

See more: Reply Keyboard Markup



.close()

replyKeyboard.close(options?);

Returns:

Keyboard structure to close a ReplyKeyboard.

Arguments:

ParametersDescriptionTypeOptionalDefault value
optionsOptions of the buttonObjecttrue{}
options.selectiveIf true, valid only for specific users (e.g. Mentioned), Users which replied the bot of original senderBooleantruefalse

See: Reply Keyboard Remove





Force Reply



// keep this always as valid
let forceReply = new ForceReply();

Constructor

new ForceReply();


@override .build()

forceReply.export(options?);

Returns:

Returns a keyboard structure for force reply.

Arguments:

ParametersDescriptionTypeOptionalDefault value
optionsOptions of the buttonObjecttrue{}
options.selectiveIf true, valid only for specific users (e.g. Mentioned), Users which replied the bot of original senderBooleantruefalse

See: ForceReply




Inherited methods and properties


These methods are inherited from ReplyMarkup class, which gets inherited by both Visual Keyboards and ForceReply.



.build()

Returns a keyboard structure based on the type.

(new InlineKeyboard()).build();
(new ReplyKeyboard()).build();
(new ForceReply()).build();

Returns:

A built structure conforming to Telegram keyboards.



.extract()

(new InlineKeyboard()).extract();
(new ReplyKeyboard()).extract();
(new ForceReply()).extract();

Returns:

Returns the content of reply_markup.

Keywords

FAQs

Package last updated on 25 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc