Nestgram
  • ⭐About Nestgram
  • 📄Guide
  • 📰News
  • đŸ”ŧHandling updates
    • Handling commands
    • Handling text messages
    • Handling other updates
    • Entities: url, email and other
    • Other arguments in handler
    • Handling media files and download it
  • đŸĒļNestgram Features
    • Services
    • Middlewares and Params
    • Sending messages correctly
    • Answer class
    • Scopes
    • States
    • Views
  • đŸ’ŦMessages
    • Sending a photo, video and other media
    • Sending a media group
    • Send location (live) or venue
    • Send contact
    • Send poll
    • Send dice
    • Edit/delete messages
    • Copy or Forward a message
  • âŒ¨ī¸Keyboards
    • Keyboard types, building keyboard
    • Handle underTheMessage keyboard button click by Alert or Toast
    • Keyboard layouts
  • âš™ī¸Config
    • CLI
    • Webhooks and run config
    • Api class
    • Modules
      • Mongo module
    • Controller Helper class
  • 🤖API Reference
    • Set chat action
    • Save user profile photo
    • Ban, unban user or chat
    • Restrict or Promote user
    • Set chat permissions
    • Set chat admin custom title
    • Chat invite links
    • Join requests
    • Update chat info, photo, title, description and more
    • Pin or unpin messages
    • Get chat info, leave chat
    • Check user subscription
    • Chat sticker set
    • My commands
    • My default admin rights
    • Menu button
Powered by GitBook
On this page
  • Why do you need to use keyboard layouts?
  • Create keyboard layout
  • Use keyboard layout
  1. Keyboards

Keyboard layouts

You can save the keyboard as a layout and reuse it.

Why do you need to use keyboard layouts?

If you have a reusable keyboard (like a menu back button), you can export it as a layout and reuse it on other keyboards in different files

Create keyboard layout

You can simply create a Keyboard class instance and export it

menu.keyboard.ts
import { Keyboard, KeyboardTypes } from 'nestgram';

export const MenuKeyboard = new Keyboard(KeyboardTypes.underTheMessage)
  .btn('btn1', 'one') // you can create buttons
  .btn('btn2', 'two')
  .row() // you can also create rows
  .btn('Menu', 'menu'); // one button in the next row

Use keyboard layout

To use keyboard layout, just call .use Keyboard method

.use method takes argument: layout you want to use (Keyboard class instance)

app.controller.ts
import { Controller, Keyboard, KeyboardTypes, MessageSend, OnCommand } from 'nestgram';
import { AppService } from './app.service';
import { MenuKeyboard } from './menu.keyboard.ts';

@Controller()
export class AppController {
  constructor(private readonly appService?: AppService) {}

  @OnCommand('start')
  async start(): Promise<MessageSend> {
    return new MessageSend(
      'Keyboard layout',
      new Keyboard(KeyboardTypes.underTheMessage)
        .btn('First button', 'first')
        .btn('Second button', 'second')
        .row() // you can create rows
        .btn('Third button', 'third')
        .use(MenuKeyboard) // add first row in layout to the button, and add second row from menu layout
        .btn('More buttons', 'fourth'), // you can continue adding buttons
    );
  }
}
PreviousHandle underTheMessage keyboard button click by Alert or ToastNextCLI

Last updated 2 years ago

âŒ¨ī¸