> For the complete documentation index, see [llms.txt](https://degreetpro.gitbook.io/nestgram/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://degreetpro.gitbook.io/nestgram/messages/edit-delete-messages.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://degreetpro.gitbook.io/nestgram/messages/edit-delete-messages.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
