# Keyboard layouts

## 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

{% code title="menu.keyboard.ts" %}

```typescript
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
```

{% endcode %}

## Use keyboard layout

To use keyboard layout, just call `.use` **Keyboard method**

{% hint style="info" %}
.use method takes argument: layout you want to use (**Keyboard class instance**)
{% endhint %}

{% code title="app.controller.ts" %}

```typescript
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
    );
  }
}
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://degreetpro.gitbook.io/nestgram/keyboards/keyboard-layouts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
