🤖 Powerful Nest module for easy and fast creation Telegram bots
Go to file
renovate[bot] f124010e29
chore(deps): update commitlint monorepo to v12.1.1 (#353)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2021-04-25 13:46:39 +03: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 Revert "[Fix] Call next after handler" (#310) 2021-03-06 16:11:15 +03:00
sample/01-complete-app chore(deps): update dependency ts-jest to v26.5.5 (#361) 2021-04-25 13:46:15 +03:00
website chore(deps): update dependency @types/react-helmet to v6.1.1 (#358) 2021-04-25 13:45:42 +03: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 commitlint monorepo to v12.1.1 (#353) 2021-04-25 13:46:39 +03:00
package.json chore(deps): update commitlint monorepo to v12.1.1 (#353) 2021-04-25 13:46:39 +03:00
README.md chore(release): v2.0.0 2021-02-14 23:59:26 +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');
  }
}