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

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
29
decreased by-70.41%
Maintainers
1
Weekly downloads
 
Created
Source

Node.JS Telegram Keyboard Wrapper

A support for telegram keyboards creation, both inline and reply.

This is a support wrapper created to simplify the creation of keyboards inside telegram bot written in Node.JS which used wrapper doesn't have already a support for managing keyboards in such dynamic way.

npm install node-telegram-keyboard-wrapper --save

Tests for all methods are included.

npm install --only=dev
npm test

In examples folder, an example bot is available. It is based on yagop's node-telegram-bot-api. It requires a bot token to be passed as argument.

Execute it by running

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

Inline Keyboards

// keep this always as valid
let inlineKeyboard = new InlineKeyboard();
Constructor
new InlineKeyboard(oneKey);
ParametersDescriptionTypeOptionalDefault value
oneKeyFastest way to have one-button keyboard.InlineKeyboardButtontrue-
Rows
.addRow()

Adds a new row with specified elements.

inlineKeyboard.addRow(...keys);
ParametersDescriptionTypeOptionalDefault value
keysOne Object per buttonInlineKeyboardButtonfalse-

Returns the object itself for chaining;

.removeRow()

Removed an entire row of keys.

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

inlineKeyboard.removeRow(rowIndex);
ParametersDescriptionTypeOptionalDefault value
rowIndexThe row to be removed.Integerfalse-

Returns the object itself for chaining;

.emptyRow()

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

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

inlineKeyboard.emptyRow(rowIndex);
ParametersDescriptionTypeOptionalDefault value
rowIndexThe row to be emptied.Integerfalse-

Returns the object itself for chaining with lastRow property to keep trace of which was the emptied row.

.popRow()

Pops the last row of the keyboard.

inlineKeyboard.popRow(rowIndex);

Returns the object itself for chaining;

.rowLength()

Empty an entire row of keys but without removing the row. Please note that both rowIndex < 0 and rowIndex > rowQuantity, will make the counter restart from their opposite bounds.

inlineKeyboard.rowLength(rowIndex, ignoreLastRow = true);
ParametersDescriptionTypeOptionalDefault value
rowIndexThe row to be emptied.Integerfalse-
ignoreLastRowIgnore last edited rowBooleantruetrue

Returns the amount of buttons in a row.

Buttons
.push()

Adds element to the specified row.

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

inlineKeyboard.push(rowIndex, element, ignoreLastRow = true);
ParametersDescriptionTypeOptionalDefault value
rowIndexThe index of the row in which push.Integerfalse-
elementThe element to pushInlineKeyboardButtonfalse-
ignoreLastRowIgnore last edited rowBooleantruetrue

Returns the object itself for chaining;

.pop()

Pops out the last element of a row. Please note that both rowIndex < 0 and rowIndex > rowQuantity, will make the counter restart from their opposite bounds.

inlineKeyboard.pop(rowIndex);
ParametersDescriptionTypeOptionalDefault value
rowIndexThe row from which pop the last element.Integerfalse-

Returns the object itself for chaining;



Reply Keyboards

// keep this always as valid
let replyKeyboard = new ReplyKeyboard();
Constructor
new ReplyKeyboard(...keys);
ParametersDescriptionTypeOptionalDefault value
keysMultiple strings or objects for each buttonKeyboardButtonfalse-
.addRow()

Adds a new row with specified elements.

replyKeyboard.addRow(...keys);
ParametersDescriptionTypeOptionalDefault value
keysOne Object per buttonInlineKeyboardButtonfalse-

Returns the object itself (chaining) with length property for keyboard rows length.

.open()

Returns a keyboard structure to open a ReplyKeyboard.

replyKeyboard.open(options = { selective: false, one_time_keyboard: false, resize_keyboard: false });
ParametersDescriptionTypeOptionalDefault value
optionsOptions of the buttonObjecttrue{ selective: false, one_time_keyboard: false, resize_keyboard: false }

See for more: Reply Keyboard Markup

.close()

Returns a keyboard structure to close a ReplyKeyboard.

replyKeyboard.close(options = { selective: false });
ParametersDescriptionTypeOptionalDefault value
optionsOptions of the buttonObjecttrue{ selective: false }

See for more: Reply Keyboard Remove

Getter: getKeys

Returns an array containing the keys which compose the keyboard.

Force Reply

Inline Keyboards

// keep this always as valid
let forceReply = new ForceReply();
Constructor
new ForceReply();
@override .export()

Returns a keyboard structure for force reply.

forceReply.export(options = { selective: false });
ParametersDescriptionTypeOptionalDefault value
optionsOptions of the buttonObjecttrue{ selective: false }

See for more: ForceReply



Inherited methods and properties

.export()

Returns a keyboard structure based on the type.

.export(options = {}, override = "");
ParametersDescriptionTypeOptionalDefault value
optionsOptions to be added to reply_markup objectObjecttrue{ }
overrideAn override content to be sent in the structure<Any>true""
.extract()

Returns the content of reply_markup.

.extract(from);
ParametersDescriptionTypeOptionalDefault value
fromThe structure obtained from .export()Objectfalse-

Throws error if in from there's not the property reply_markup.

Getter: length

Returns the length of the keyboard (rows)

Keywords

FAQs

Package last updated on 24 Sep 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