nestjs-telegraf/website/versioned_docs/version-1.2.1/telegraf-methods.md

1.1 KiB

id title sidebar_label slug
telegraf-methods Telegraf methods Telegraf methods /telegraf-methods

Each Telegraf instance method described here has own decorator in nestjs-telegraf package. The name of the decorator corresponds to the name of the Telegraf method. For example @TelegrafHears, @TelegrafOn, @TelegrafAction and so on.

Now let's try to repeat the example from the Telegraf documentation page.

/* app.service.ts */

import { Injectable } from '@nestjs/common';
import {
  TelegrafStart,
  TelegrafHelp,
  TelegrafOn,
  TelegrafHears,
  Context,
} from 'nestjs-telegraf';

@Injectable()
export class AppService {
  @TelegrafStart()
  start(ctx: Context) {
    ctx.reply('Welcome');
  }

  @TelegrafHelp()
  help(ctx: Context) {
    ctx.reply('Send me a sticker');
  }

  @TelegrafOn('sticker')
  on(ctx: Context) {
    ctx.reply('👍');
  }

  @TelegrafHears('hi')
  hears(ctx: Context) {
    ctx.reply('Hey there');
  }
}