🤖 Powerful Nest module for easy and fast creation Telegram bots
Go to file
dependabot[bot] fa5dbbc6a6
chore(deps-dev): bump eslint from 8.13.0 to 8.14.0 (#798)
Bumps [eslint](https://github.com/eslint/eslint) from 8.13.0 to 8.14.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.13.0...v8.14.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-04-28 09:56:42 +03:00
.github chore(): use global funding config 2022-03-21 16:05:41 +03:00
.husky chore(release): v2.0.0 2021-02-14 23:59:26 +03:00
lib fixed typo in tg-arguments-host.interface.ts 2021-09-16 21:37:59 +03:00
sample/01-complete-app chore(deps): bump ansi-regex in /sample/01-complete-app (#772) 2022-03-29 22:45:27 +03:00
website chore(deps): bump async from 2.6.3 to 2.6.4 in /website (#796) 2022-04-28 09:44:09 +03:00
.commitlintrc.json feat(): add commitlint 2021-01-07 13:35:32 +03:00
.eslintrc.js fix(): eslint configuration 2021-09-08 21:14:59 +03:00
.gitignore chore(gitignore): remove locks from ignore 2021-01-05 15:43:46 +03:00
.npmignore chore(release): v2.0.0-beta.2 2021-01-12 02:23:52 +03:00
.prettierrc feat: complete rewrite 2020-03-19 16:21:35 +03:00
LICENSE.md chore(): update author info 2020-12-30 20:37:11 +03:00
package-lock.json chore(deps-dev): bump eslint from 8.13.0 to 8.14.0 (#798) 2022-04-28 09:56:42 +03:00
package.json chore(deps-dev): bump eslint from 8.13.0 to 8.14.0 (#798) 2022-04-28 09:56:42 +03:00
README.md fix docs urls 2021-08-05 13:35:47 +03:00
tsconfig.json fix(build): remove sample from tsconfig 2021-01-03 16:52:11 +03:00
tsconfig.typedoc.json chore(deps): new typedoc version and configuration 2021-01-02 21:59:41 +03:00

NestJS Telegraf npm GitHub last commit NPM

NestJS Telegraf powerful solution for creating Telegram bots.

This package uses the best of the NodeJS world under the hood. Telegraf is the most powerful library for creating bots and NestJS is a progressive framework for creating well-architectured applications. This module provides fast and easy way for creating Telegram bots and deep integration with your NestJS application.

Features

  • Simple. Easy to use.
  • Ton of decorators available out of the box for handling bot actions.
  • Ability to create custom decorators.
  • Scenes support.
  • Telegraf plugins and custom plugins support.
  • Ability to run multiple bots simultaneously.
  • Full support of NestJS guards, interceptors, filters and pipes!

Documentation

If you want to dive fully into NestJS Telegraf then don't waste your time in this dump, check out the documentation site.

Installation

$ npm i nestjs-telegraf telegraf

Usage

Once the installation process is complete, we can import the TelegrafModule into the root AppModule:

import { Module } from '@nestjs/common';
import { TelegrafModule } from 'nestjs-telegraf';

@Module({
  imports: [
    TelegrafModule.forRoot({
      token: 'TELEGRAM_BOT_TOKEN',
    })
  ],
})
export class AppModule {}

Then create app.update.ts file and add some decorators for handling Telegram bot API updates:

import {
  Update,
  Start,
  Help,
  On,
  Hears,
  Context,
} from 'nestjs-telegraf';
import { AppService } from './app.service';
import { Context } from './context.interface';

@Update()
export class AppUpdate {
  constructor(private readonly appService: AppService)

  @Start()
  async startCommand(ctx: Context) {
    await ctx.reply('Welcome');
  }

  @Help()
  async helpCommand(ctx: Context) {
    await ctx.reply('Send me a sticker');
  }

  @On('sticker')
  async onSticker(ctx: Context) {
    await ctx.reply('👍');
  }

  @Hears('hi')
  async hearsHi(ctx: Context) {
    await ctx.reply('Hey there');
  }
}

Telegraf instance access

If you want to use Telegraf instance directly, you can use @InjectBot for that.

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

See more on a docs page: https://nestjs-telegraf.vercel.app/extras/bot-injection