1.5.2 • Published 1 year ago

@tlgr/button v1.5.2

Weekly downloads
-
License
Apache 2.0
Repository
-
Last release
1 year ago

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

1.5.2

1 year ago

1.4.4

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago