mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2025-09-23 09:49:06 +03:00
chore(release): v2.0.0
This commit is contained in:
36
website/docs/extras/bot-injection.md
Normal file
36
website/docs/extras/bot-injection.md
Normal file
@@ -0,0 +1,36 @@
|
||||
---
|
||||
id: bot-injection
|
||||
title: Bot injection
|
||||
sidebar_label: Bot injection
|
||||
slug: /extras/bot-injection
|
||||
---
|
||||
|
||||
At times you may need to access the native `Telegraf` instance. You can inject the Telegraf by using the `@InjectBot()` decorator as follows:
|
||||
|
||||
```typescript {8} title="src/echo/echo.service.ts"
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectBot } from 'nestjs-telegraf';
|
||||
import { Telegraf } from 'telegraf';
|
||||
import { TelegrafContext } from '../common/interfaces/telegraf-context.interface.ts';
|
||||
|
||||
@Injectable()
|
||||
export class EchoService {
|
||||
constructor(@InjectBot() private bot: Telegraf<TelegrafContext>) {}
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
If you run [multiple bots](/docs/extras/multiple-bots) in the same application, explicitly specify the bot name:
|
||||
|
||||
```typescript {8} title="src/echo/echo.service.ts"
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectBot } from 'nestjs-telegraf';
|
||||
import { Telegraf } from 'telegraf';
|
||||
import { TelegrafContext } from '../common/interfaces/telegraf-context.interface.ts';
|
||||
|
||||
@Injectable()
|
||||
export class EchoService {
|
||||
constructor(@InjectBot('cats') private bot: Telegraf<TelegrafContext>) {}
|
||||
...
|
||||
}
|
||||
```
|
Reference in New Issue
Block a user