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
  • How to handle other updates
  • Allowed updates
  1. Handling updates

Handling other updates

Handle other updates

How to handle other updates

app.controller.ts
import { OnCommand, Controller } from 'nestgram';
import { AppService } from './app.service';

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

  @OnCommand('start')
  async start(): Promise<string> {
    return 'Hello, world!';
  }
}

In this code, bot says Hello, world if user writes command /start (@OnCommand is responsible for this). But you can also handle other updates: when user sends some message, channel writes a post, user edits a message, channel edits a post, user writes message with some entities or other updates. To handle other updates, you just need to import the appropriate decorator and use it. You can see an example below, in this, bot handles update when a channel publishes a post

app.controller.ts
import { OnPost, Controller, Message, IMessage } from 'nestgram';
import { AppService } from './app.service';

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

  @OnPost()
  async post(@Message() message: IMessage): Promise<any> {
    console.log(message);
  }
}

Allowed updates

Decorator
Description
Params

OnCommand

When the user writes some command (e.g. /start)

text?: string - The command text you want to listen to. Optional. If not specified, listens for all commands.

OnText

When the user writes some text messages (e.g. "Hello!")

text?: string - The text you want to listen to. Optional. If not specified, listens for all text messages.

OnMessage

When the user sends some message

subtype?: 'edit' | 'post' | 'edit_post'

OnMessageEdit

When the user edits a message

none

OnPost

When the channel publishes some post

none

OnPostEdit

When the channel edits a post

none

OnEntity

When the user sends a message with some entity (e.g. url, command, bold)

When the user clicks on the underTheMessage button

buttonId: string

OnMedia

When the user sends some media file

fileType?: string - Media file type you want to listen to

OnPhoto

When the user sends some photo

none

OnVideo

When the user sends some video

none

OnAudio

When the user sends some audio

none

OnAnimation

When the user sends some animation (for example, gif)

none

OnVoice

When the user sends some voice message

none

OnVideoNote

When the user sends some video note message

none

OnDocument

When the user sends some document

none

OnLocation

When the user sends a location

none

OnVenue

When the user sends a venue

none

OnContact

When the user sends a contact

none

OnPoll

When the user or channel sends a poll

none

OnPollEdit

When the poll edited (for example, when the channel closed the poll)

none

OnPollAnswer

When the user answers to the poll (only not anonymous)

none

OnUpdate

When the bot gets some update

none

OnForward

When the user forwards some message

none

OnDice

When the user sends dice

none

OnJoinRequest

When the user sends chat join request

none

PreviousHandling text messagesNextEntities: url, email and other

Last updated 2 years ago

entity?:

đŸ”ŧ
string
OnClick