@tlgr/button
TypeScript icon, indicating that this package has built-in type declarations

1.5.2 • Public • Published

Button component

Installation

npm

npm install @tlgr/button

yarn

yarn add @tlgr/button

pnpm

pnpm add @tlgr/button

Overview

Button provides simple functionality for button.

This component realize click event.

Each button has unique identified.

Example

// simple example without overrides
const bot = new Telegraf(TOKEN);
const button = new Button(bot, 'Custom Name', options)

bot.command('button', (ctx) => {
  ctx.sendMessage(ctx.chat.id, 'Hello with button example', {
    reply_markup: {
      inline_keyboard: [
        [button.render('SOME_DATA')],
      ],
    }
})

})

button.on('click',(ctx, button) =>{
    console.log('button info', button)

// button = {
// uuid: hash,
// name: '@tlgr/button/<hash>'
// prefix: '@tlgr/button',
// render() // telegram render function
// payload: SOME_DATA
// }
});

// without hash
const buttonWithoutHash = new Button(bot, 'button without hash',{
disableUUID: true
});

buttonWithoutHash.on('click', (ctx, button) => {
  console.log('button info without hash:',button);
// button = {
// uuid: hash,
// name: '@tlgr/button'
// prefix: '@tlgr/button',
// render() // telegram render function
// payload: '' (since render function is not called)
// }

// with custom name
const buttonWithName = new Button(bot, 'button without hash',{
prefix: '@tlgr/custom-name'
});

buttonWithName.on('click', (ctx, button) => {
  console.log('button info without hash:',button);
// button = {
// uuid: hash,
// name: '@tlgr/custom-name/<hash>'
// prefix: @tlgr/custom-name',
// render() // telegram render function
// payload: '' (since render function is not called)
// }
})

Demo

Code available at bin.ts file.

inline image

Video

Package Sidebar

Install

npm i @tlgr/button

Weekly Downloads

1

Version

1.5.2

License

Apache 2.0

Unpacked Size

36.2 kB

Total Files

15

Last publish

Collaborators

  • vitalicset