🤖 Powerful Nest module for easy and fast creation Telegram bots
Go to file
renovate[bot] b30a3d5777
chore(deps): update dependency @types/node to v16.11.15 (#662)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2021-12-21 03:17:41 +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 fixed typo in tg-arguments-host.interface.ts 2021-09-16 21:37:59 +03:00
sample/01-complete-app chore(deps): update dependency @types/node to v16.11.15 (#662) 2021-12-21 03:17:41 +00:00
website chore(deps): update dependency @types/react to v17.0.37 (#635) 2021-11-24 23:16:45 +00: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): update typescript-eslint monorepo to v5.8.0 (#661) 2021-12-20 20:23:25 +00:00
package.json chore(deps): update typescript-eslint monorepo to v5.8.0 (#661) 2021-12-20 20:23:25 +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