0
0
mirror of https://github.com/Maks1mS/nestjs-telegraf.git synced 2025-10-08 22:33:13 +03:00
Files
.github
.husky
lib
sample
website
docs
extras
bot-injection.md
middlewares.md
multiple-bots.md
standalone-applications.md
migrating
async-configuration.md
getting-updates.md
installation.md
telegraf-methods.md
src
static
babel.config.js
docusaurus.config.js
package-lock.json
package.json
sidebars.js
tsconfig.json
.commitlintrc.json
.eslintrc.js
.gitignore
.npmignore
.prettierrc
LICENSE.md
README.md
package-lock.json
package.json
tsconfig.json
tsconfig.typedoc.json
nestjs-telegraf/website/docs/extras/bot-injection.md
Aleksandr Bukhalo 90667fe876 fix docs urls
2021-08-05 13:35:47 +03:00

1.1 KiB

id, title, sidebar_label, slug
id title sidebar_label slug
bot-injection Bot injection Bot injection /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:

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 in the same application, explicitly specify the bot name:

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>) {}
  ...
}