🤖 Powerful Nest module for easy and fast creation Telegram bots
Go to file
2021-03-06 11:54:46 +03:00
.github ci(): use latest nodejs versions 2020-12-30 20:41:06 +03:00
lib Update to Telegraf v4.0.0 (#212) 2021-01-11 16:17:32 +03:00
sample/01-complete-app fix(sample): context typings 2021-03-06 11:54:46 +03:00
website merge refactor/v2 2021-01-05 00:32:31 +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 dependency eslint-config-prettier to v7.2.0 (#228) 2021-01-19 11:51:04 +03:00
package.json chore(deps): update dependency eslint-config-prettier to v7.2.0 (#228) 2021-01-19 11:51:04 +03:00
README.md Update to Telegraf v4.0.0 (#212) 2021-01-11 16:17:32 +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! (in progress...)

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');
  }
}