Handling commands

Handle when user writes a command (e.g. /start, /help, /menu)

Handle command

To handle a command, you can use @OnCommand decorator

Optional. @OnCommand takes command you want to listen to as argument

Get command params

You can get command params too (e.g. when user writes /start hello or follows the bot link with some params). Use @CommandParams property decorator to it

You can read more about property decorators here

Example

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

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

  @OnCommand('start')
  async start(@CommandParams() params: string[]): Promise<string> {
    console.log(params);
    return 'Hello, world!';
  }
}

Last updated