🤖 Powerful Nest module for easy and fast creation Telegram bots
Go to file
renovate[bot] 7c37527f76
chore(deps): update dependency jest to v27.1.1 (#512)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2021-09-08 11:42:09 +00:00
.github ci(): use latest nodejs versions 2020-12-30 20:41:06 +03:00
.husky chore(release): v2.0.0 2021-02-14 23:59:26 +03:00
lib Merge pull request #289 from toolstik/feature/modules-deep-scan 2021-08-05 12:13:18 +03:00
sample/01-complete-app chore(deps): update dependency jest to v27.1.1 (#512) 2021-09-08 11:42:09 +00:00
website chore(deps): update dependency @types/react to v17.0.20 (#509) 2021-09-05 10:57:53 +00:00
.commitlintrc.json feat(): add commitlint 2021-01-07 13:35:32 +03:00
.eslintrc.js fix(eslint): use prettier plugin 2021-01-06 16:57:27 +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): update typescript-eslint monorepo to v4.31.0 (#510) 2021-09-06 20:15:13 +00:00
package.json chore(deps): update typescript-eslint monorepo to v4.31.0 (#510) 2021-09-06 20:15:13 +00:00
README.md fix docs urls 2021-08-05 13:35:47 +03:00
renovate.json chore(deps): replace dependabot with renovate bot 2020-12-07 18:14:58 +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