# Edit/delete messages

## Edit message text

To edit message text, use **Edit class-method** or `.edit` **answer/api method**

#### Edit class-method or .edit method take arguments:

<table><thead><tr><th data-type="number">Argument</th><th width="322.9305108145421">Description</th><th>Required</th></tr></thead><tbody><tr><td>1</td><td>Content you want to edit</td><td><strong>Required</strong></td></tr><tr><td>2</td><td>Keyboard you want to add</td><td>Optional</td></tr><tr><td>3</td><td><a href="https://core.telegram.org/bots/api#editmessagetext">More options</a></td><td>Optional</td></tr><tr><td>4</td><td>Message id you want to edit</td><td>Optional. Current message id by default</td></tr></tbody></table>

{% hint style="info" %}
If you want to know what arguments an API method takes, see the IDE hint
{% endhint %}

## Edit message caption

To edit message caption, pass **Caption class-mark** to **Edit class-method** or to `.edit` **answer/api method**

## Edit message media

To edit message media, pass **media class** you want to edit to **Edit class-method** or to `.edit` **answer/api method**

## Edit message keyboard

To edit message keyboard, pass **Keyboard class** you want to edit to **Edit class-method** or to `.edit` **answer/api method**

## Edit message: example

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

```typescript
import { Caption, Controller, Edit, Keyboard, KeyboardTypes, MessageSend, OnClick, OnCommand, Photo } from 'nestgram';
import { AppService } from './app.service';
import * as path from 'path';

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

  @OnCommand('start')
  helloMessage() {
    return new MessageSend(
      new Photo('path', path.resolve(__dirname, 'media_1.jpeg')),
      new Keyboard(KeyboardTypes.underTheMessage)
        .btn('Edit media', 'editMedia').row()
        .btn('Edit caption', 'editCaption').row()
        .btn('Edit keyboard', 'editKeyboard').row(),
      { caption: 'First caption' },
    );
  }

  @OnClick('editMedia')
  editMedia() {
    return new Edit(new Photo('path', path.resolve(__dirname, 'media_2.jpeg')));
  }

  @OnClick('editCaption')
  editCaption() {
    return new Edit(new Caption('Second caption'));
  }

  @OnClick('editKeyboard')
  editKeyboard() {
    return new Edit(
      new Keyboard(KeyboardTypes.underTheMessage)
        .btn('Nice', 'nice')
    );
  }
}
```

{% endcode %}

## Delete message

To delete message, use **Delete class-method** or `.delete` **answer/api method**

#### Delete class-method or .delete answer method take arguments:

<table><thead><tr><th width="150" data-type="number">Argument</th><th width="374">Description</th><th>Required</th></tr></thead><tbody><tr><td>1</td><td>Message id you want to delete</td><td>Optional. Current message id by default</td></tr><tr><td>2</td><td>Chat id in which the message you want to delete is located</td><td>Optional. Current chat id by default</td></tr></tbody></table>

{% hint style="info" %}
If you want to know what arguments an API method takes, see the IDE hint
{% endhint %}

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

```typescript
import { Controller, Delete, Keyboard, KeyboardTypes, MessageSend, OnClick, OnCommand } from 'nestgram';
import { AppService } from './app.service';

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

  @OnCommand('start')
  deleteMePlease(): MessageSend {
    return new MessageSend(
      'Delete me please',
      new Keyboard(KeyboardTypes.underTheMessage)
        .btn('Delete', 'del'),
    )
  }

  @OnClick('del')
  deleteMe(): Delete {
    return new Delete();
  }
}
```

{% 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/messages/edit-delete-messages.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.
