mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2025-09-23 09:49:06 +03:00
feat!(): add custom execution context
This commit is contained in:
@@ -12,6 +12,7 @@ The described functionality is under development, the functionality has not been
|
||||
### Update
|
||||
|
||||
`@Update` class decorator, it's like NestJS [`@Controller`](https://docs.nestjs.com/controllers) decorator, but for [Telegram Bot API updates](https://core.telegram.org/bots/api#getting-updates).
|
||||
It is required for the class that will receive updates from Telegram.
|
||||
|
||||
```typescript {3}
|
||||
import { Update, Context } from 'nestjs-telegraf';
|
||||
|
@@ -8,10 +8,11 @@ slug: /bot-injection
|
||||
At times you may need to access the native `Telegraf` instance. For example, you may want to connect stage middleware. You can inject the Telegraf by using the `@InjectBot()` decorator as follows:
|
||||
```typescript
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectBot, TelegrafProvider } from 'nestjs-telegraf';
|
||||
import { InjectBot } from 'nestjs-telegraf';
|
||||
import { Telegraf } from 'telegraf';
|
||||
|
||||
@Injectable()
|
||||
export class BotSettingsService {
|
||||
constructor(@InjectBot() private bot: TelegrafProvider) {}
|
||||
constructor(@InjectBot() private bot: Telegraf) {}
|
||||
}
|
||||
```
|
||||
|
@@ -18,8 +18,8 @@ import {
|
||||
Help,
|
||||
On,
|
||||
Hears,
|
||||
Context,
|
||||
} from 'nestjs-telegraf';
|
||||
import { Context } from 'telegraf';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
|
@@ -9,12 +9,13 @@ If you want to configure a telegram bot webhook, you need to get a middleware fr
|
||||
|
||||
To access it, you must use the `app.get()` method, followed by the provider reference:
|
||||
```typescript
|
||||
const telegrafProvider = app.get('TelegrafProvider');
|
||||
import { Telegraf } from 'telegraf';
|
||||
const telegraf = app.get(Telegraf);
|
||||
```
|
||||
|
||||
Now you can connect middleware:
|
||||
```typescript
|
||||
app.use(telegrafProvider.webhookCallback('/secret-path'));
|
||||
app.use(telegraf.webhookCallback('/secret-path'));
|
||||
```
|
||||
|
||||
The last step is to specify launchOptions in `forRoot` method:
|
||||
|
Reference in New Issue
Block a user