nestjs-telegraf/website/versioned_docs/version-1.3.0/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 @Hears, @On, @Action 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 {
  Start,
  Help,
  On,
  Hears,
  Context,
} from 'nestjs-telegraf';

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

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

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

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