nestjs-telegraf/docs/telegraf-methods.md

40 lines
1.0 KiB
Markdown
Raw Normal View History

2023-07-24 16:02:21 +03:00
# 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 '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');
}
}
```