Skip to content

Telegraf methods

Each Telegraf instance method has own decorator in nestjs-telegraf package. The name of the decorator corresponds to the name of the Telegraf method. For example @Hears, @On, @Action and so on.

Now let's try simple example:

typescript
import {
  Update,
  Ctx,
  Start,
  Help,
  On,
  Hears,
} from 'nestjs-telegraf';
import { TelegrafContext } from './common/interfaces/telegraf-context.interface.ts';

@Update()
export class AppUpdate {
  @Start()
  async start(@Ctx() ctx: TelegrafContext) {
    await ctx.reply('Welcome');
  }

  @Help()
  async help(@Ctx() ctx: TelegrafContext) {
    await ctx.reply('Send me a sticker');
  }

  @On('sticker')
  async on(@Ctx() ctx: TelegrafContext) {
    await ctx.reply('👍');
  }

  @Hears('hi')
  async hears(@Ctx() ctx: TelegrafContext) {
    await ctx.reply('Hey there');
  }
}