{"id":16527953,"url":"https://github.com/igorkamyshev/nest-telegram","last_synced_at":"2025-06-17T11:38:22.226Z","repository":{"id":52022732,"uuid":"172977939","full_name":"igorkamyshev/nest-telegram","owner":"igorkamyshev","description":"NestJS module for creating Telegram bots by telegraf.js framework","archived":false,"fork":false,"pushed_at":"2021-05-08T05:32:39.000Z","size":42673,"stargazers_count":36,"open_issues_count":4,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-24T20:16:18.159Z","etag":null,"topics":["nestjs","nodejs","telegraf-framework","telegram","telegram-bot"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/igorkamyshev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-27T19:38:24.000Z","updated_at":"2024-10-10T02:20:38.000Z","dependencies_parsed_at":"2022-08-29T19:12:17.875Z","dependency_job_id":null,"html_url":"https://github.com/igorkamyshev/nest-telegram","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/igorkamyshev/nest-telegram","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorkamyshev%2Fnest-telegram","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorkamyshev%2Fnest-telegram/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorkamyshev%2Fnest-telegram/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorkamyshev%2Fnest-telegram/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/igorkamyshev","download_url":"https://codeload.github.com/igorkamyshev/nest-telegram/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorkamyshev%2Fnest-telegram/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260350332,"owners_count":22995736,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nestjs","nodejs","telegraf-framework","telegram","telegram-bot"],"created_at":"2024-10-11T17:37:39.979Z","updated_at":"2025-06-17T11:38:17.213Z","avatar_url":"https://github.com/igorkamyshev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nest-telegram\n\n[![Scripts sets up by @solid-soda/scripts v2.1.0](https://img.shields.io/static/v1?label=@solid-soda/scripts\u0026message=2.1.0\u0026color=75ddf4)](https://github.com/solid-soda/scripts)\n\nIntegrate [telegraf.js](https://telegraf.js.org/) to [NestJS](https://nestjs.com/) application.\n\n\u003e Warning! Package under development, please waiting for v1 release.\n\n## Instalation\n\n`yarn add nest-telegram`\n\n## Setup\n\n### Add TelegramModule to your app\n\n```ts\nimport { TelegramModule, TelegramModuleOptionsFactory } from 'nest-telegram'\n\n// In real app, please, don't store token in source code\nclass TelegramOptionsFactory implements TelegramModuleOptionsFactory {\n  createOptions(): TelegramModuleOptions {\n    return {\n      token: 'TelegramToken#1213',\n      sitePublicUrl: 'https://my-site.com',\n    }\n  }\n}\n\n@Module({\n  imports: [\n    TelegramModule.forRootAsync({,\n      imports: [/* all modules for initialize TelegramOptionsFactory*/]\n      useClass: TelegramOptionsFactory,\n    }),\n    UtilsModule,\n  ],\n})\nexport class MyModule implements NestModule {\n  constructor(\n    private readonly moduleRef: ModuleRef,\n    private readonly telegramBot: TelegramBot,\n  ) {}\n\n  onModuleInit() {\n    const isDev = process.env.NODE_ENV === 'development'\n\n    // in dev mode, we can't use webhook, polling starts automatically\n    this.telegramBot.init(this.moduleRef, isDev);\n  }\n\n  // ...\n}\n```\n\n### Add custom middleware to your app\n\n```ts\nimport { TelegramBot } from 'nest-telegram';\nimport { NestFactory } from '@nestjs/core';\nimport { AppModule } from '@app/app.module';\n\nasync function bootstrap() {\n  const isDev = process.env.NODE_ENV === 'development';\n\n  const app = await NestFactory.create(AppModule);\n\n  const bot = app.get(TelegramBot);\n\n  if (!isDev) {\n    // in production mode, please use webhook with middleware\n    app.use(bot.getMiddleware('hook-path'));\n  }\n\n  await app.listen(3000);\n}\nbootstrap();\n```\n\n## Usage\n\nNow, you can decorate any method with `TelegramActionHandler`.\n\nExample:\n\n```ts\nimport { Injectable } from '@nestjs/common';\nimport { Context, PipeContext, TelegramActionHandler } from 'nest-telegram';\n\n@Injectable()\nexport class HelpActions {\n  @TelegramActionHandler({ onStart: true })\n  async start(ctx: Context) {\n    await ctx.reply('Hello!');\n  }\n}\n```\n\nAvailable actions for decorator:\n\n- `onStart` {boolean}, it triggers on `/start` command.\n- `command` {string}, it triggers on any command, e.g. — `@TelegramActionHandler({ command: '/help' })`.\n- `message` {string|RegExp}, it triggers on text message matching RegExp or string.\n- `location` {boolean}, it triggers on location send.\n\nAlso, you can write Transformators for context (like Pipes in NestJS). Example:\n\n```ts\nimport { Injectable } from '@nestjs/common'\nimport { ContextTransformer, Context } from 'nest-telegram'\n\n@Injectable()\nclass CurrentSender implements ContextTransformer\u003cTokenPayloadModel\u003e {\n  async transform(ctx: Context) {\n    const user = // get user from DB\n\n    return {\n      login: user.login,\n      isManager: user.isManager,\n    }\n  }\n}\n\n@Injectable()\nexport class SomethingActions {\n  @TelegramActionHandler({ command: '/say' })\n  async say(\n    ctx: Context,\n    // apply this transformer like this\n    @PipeContext(CurrentSender) user: TokenPayloadModel,\n  ) {\n    const { login } = user\n\n    // now you can use `login`\n    await ctx.reply(`Hello, ${login}`)\n  }\n}\n```\n\nAlso, you can write `Catchers` for exceptions (like Filters in NestJS). Example:\n\n```js\nimport { TelegramErrorHandler, TelegramCatch, Context } from 'nest-telegram'\n\n@TelegramCatch(MyExecption)\nexport class MyCatcher\n  implements TelegramErrorHandler\u003cMyExecption\u003e {\n  public async catch(ctx: Context, exception: MyExecption) {\n    await ctx.reply(exception.message)\n  }\n}\n```\n\nStay tuned, stable release is coming. 🤓\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figorkamyshev%2Fnest-telegram","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Figorkamyshev%2Fnest-telegram","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figorkamyshev%2Fnest-telegram/lists"}