nestjs-telegraf/website/docs/telegraf-methods.md

46 lines
1.1 KiB
Markdown
Raw Normal View History

---
id: telegraf-methods
title: Telegraf methods
sidebar_label: Telegraf methods
slug: /telegraf-methods
---
2021-02-14 23:59:26 +03:00
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`](https://telegraf.js.org/classes/telegraf.html#hears), [`@On`](https://telegraf.js.org/classes/telegraf.html#on), [`@Action`](https://telegraf.js.org/classes/telegraf.html#action) and so on.
2021-02-14 23:59:26 +03:00
Now let's try simple example:
2021-02-14 23:59:26 +03:00
```typescript title="src/app.update.ts"
import {
2021-02-14 23:59:26 +03:00
Update,
Ctx,
Start,
Help,
On,
Hears,
} from '@maks1ms/nestjs-telegraf';
2021-02-14 23:59:26 +03:00
import { TelegrafContext } from './common/interfaces/telegraf-context.interface.ts';
2021-02-14 23:59:26 +03:00
@Update()
export class AppUpdate {
@Start()
2021-02-14 23:59:26 +03:00
async start(@Ctx() ctx: TelegrafContext) {
await ctx.reply('Welcome');
}
@Help()
2021-02-14 23:59:26 +03:00
async help(@Ctx() ctx: TelegrafContext) {
await ctx.reply('Send me a sticker');
}
@On('sticker')
2021-02-14 23:59:26 +03:00
async on(@Ctx() ctx: TelegrafContext) {
await ctx.reply('👍');
}
@Hears('hi')
2021-02-14 23:59:26 +03:00
async hears(@Ctx() ctx: TelegrafContext) {
await ctx.reply('Hey there');
}
}
```