nestjs-telegraf
Version:
Telegraf module for NestJS
30 lines (25 loc) • 1.05 kB
Markdown
# Bot injection
At times you may need to access the native `Telegraf` instance. You can inject the Telegraf by using the `` 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';
export class EchoService {
constructor( private bot: Telegraf<TelegrafContext>) {}
...
}
```
If you run [multiple bots](/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';
export class EchoService {
constructor( private bot: Telegraf<TelegrafContext>) {}
...
}
```