npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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 - if true then the keyboard will be inline (default: false)
  • duplicates - if true then allow adding buttons with the same name (default: false)
  • newline - if true each button will be on a new line else if false then each add 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());

keyboard.new()

keyboard.empty()

keyboard.exist(button)