diff --git a/LICENSE b/LICENSE.md similarity index 93% rename from LICENSE rename to LICENSE.md index c1709c5..dd1a472 100644 --- a/LICENSE +++ b/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 Igor Kamyshev +Copyright (c) 2019 Bukhalo Aleksandr Aleksandrovich & Igor Kamyshev Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index bca55f0..f1b5240 100644 --- a/README.md +++ b/README.md @@ -1,153 +1,48 @@ -# nest-telegram +
-Integrate [telegraf.js](https://telegraf.js.org/) to [NestJS](https://nestjs.com/) application. +[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456 +[circleci-url]: https://circleci.com/gh/nestjs/nest -> Warning! Package under development, please waiting for v1 release. +A progressive Node.js framework for building efficient and scalable server-side applications.
+ -## Instalation +## Description -`yarn add nest-telegram` +[Telegraf](https://github.com/telegraf/telegraf) module for [Nest](https://github.com/nestjs/nest). -## Setup +## Installation -### Add TelegramModule to your app - -```ts -import { TelegramModule, TelegramModuleOptionsFactory } from 'nest-telegram' - -// In real app, please, don't store token in source code -class TelegramOptionsFactory implements TelegramModuleOptionsFactory { - createOptions(): TelegramModuleOptions { - return { - token: 'TelegramToken#1213', - sitePublicUrl: 'https://my-site.com', - } - } -} - -@Module({ - imports: [ - TelegramModule.fromFactory({, - useClass: TelegramOptionsFactory, - }), - UtilsModule, - ], -}) -export class MyModule implements NestModule { - constructor( - private readonly moduleRef: ModuleRef, - private readonly telegramBot: TelegramBot, - ) {} - - onModuleInit() { - const isDev = process.env.NODE_ENV === 'development' - - this.telegramBot.init(this.moduleRef) - - if (isDev) { - // in dev mode, we can't use webhook - this.telegramBot.startPolling() - } - } - - // ... -} -``` - -### Add custom middleware to your app - -```ts -import { TelegramBot } from 'nest-telegram' -import { NestFactory } from '@nestjs/core' -import { AppModule } from '@app/app.module' - -async function bootstrap() { - const isDev = process.env.NODE_ENV === 'development' - - const app = await NestFactory.create(AppModule) - - const bot = app.get(TelegramBot) - - if (!isDev) { - app.use(bot.getMiddleware('hook-path')) - } - - await app.listen(3000) -} -bootstrap() +```bash +$ npm i nestjs-telegraf telegraf ``` ## Usage +TBD -Now, you can decorate any method with `TelegramActionHandler`. +## Support -Example: +Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support). -```ts -import { Injectable } from '@nestjs/common' -import { Context, PipeContext, TelegramActionHandler } from 'nest-telegram' +## People -@Injectable() -export class HelpActions { - @TelegramActionHandler({ onStart: true }) - async start(ctx: Context) { - await ctx.reply('Hello!') - } -} -``` +- Authors - [Aleksandr Bukhalo](https://bukhalo.com/) & [Igor Kamyshev](https://kamyshev.me/) +- Maintainers - [Aleksandr Bukhalo](https://bukhalo.com/) +- Website - [https://nestjs.com](https://nestjs.com/) -Available actions for decorator: +## License -+ `onStart` {boolean}, it triggers on `/start` command. -+ `command` {string}, it triggers on any command, e.g. — `@TelegramActionHandler({ command: '/help' })`. -+ `message` {string|RegExp}, it triggers on text message matching RegExp or string. - -Also, you can write Transformators for context (like Pipes in NestJS). Example: - -```ts -import { Injectable } from '@nestjs/common' -import { ContextTransformer, Context } from 'nest-telegram' - -@Injectable() -class CurrentSender implements ContextTransformer