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
  • Edit message text
  • Edit message caption
  • Edit message media
  • Edit message keyboard
  • Edit message: example
  • Delete message
  1. Messages

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:

Argument
Description
Required
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:

Argument
Description
Required
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();
  }
}
PreviousSend diceNextCopy or Forward a message

Last updated 2 years ago

đŸ’Ŧ
More options