feat!(): add custom execution context

This commit is contained in:
Morb0
2021-01-03 01:30:57 +03:00
parent 85bb916709
commit af632ea471
64 changed files with 899 additions and 69 deletions

View File

@@ -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';

View File

@@ -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) {}
}
```

View File

@@ -18,8 +18,8 @@ import {
Help,
On,
Hears,
Context,
} from 'nestjs-telegraf';
import { Context } from 'telegraf';
@Injectable()
export class AppService {

View File

@@ -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: