Edit/delete messages

You can edit or 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:

ArgumentDescriptionRequired
1

Content you want to edit

Required

2

Keyboard you want to add

Optional

3

Optional

4

Message id you want to edit

Optional. Current message id by default

If you want to know what arguments an API method takes, see the IDE hint

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

app.controller.ts
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')
    );
  }
}

Delete message

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

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

ArgumentDescriptionRequired
1

Message id you want to delete

Optional. Current message id by default

2

Chat id in which the message you want to delete is located

Optional. Current chat id by default

If you want to know what arguments an API method takes, see the IDE hint

app.controller.ts
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();
  }
}

Last updated