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 +

+ Nest Logo +

-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.

+

+NPM Version +Package License +NPM Downloads +CircleCI +Coverage +Discord +Backers on Open Collective +Sponsors on Open Collective + + Support us + +

-## 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 { - async transform(ctx: Context) { - const user = // get user from DB - - return { - login: user.login, - isManager: user.isManager, - } - } -} - -@Injectable() -export class SomethingActions { - @TelegramActionHandler({ command: '/say' }) - async say( - ctx: Context, - // apply this transformer like this - @PipeContext(CurrentSender) user: TokenPayloadModel, - ) { - const { login } = user - - // now you can use `login` - await ctx.reply(`Hello, ${login}`) - } -} -``` - -Also, you can write `Catchers` for exceptions (like Filters in NestJS). Example: - -```js -import { TelegramErrorHandler, TelegramCatch, Context } from 'nest-telegram' - -@TelegramCatch(MyExecption) -export class MyCatcher - implements TelegramErrorHandler { - public async catch(ctx: Context, exception: MyExecption) { - await ctx.reply(exception.message) - } -} -``` - -Stay tuned, stable release is coming. 🤓 +Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE). \ No newline at end of file diff --git a/package.json b/package.json index 04a2320..edce4bc 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,41 @@ { "name": "nestjs-telegraf", "version": "0.5.1", - "repository": "git@github.com:igorkamyshev/nest-telegram.git", - "author": "Igor Kamyshev ", + "description": "Telegraf module for Nest framework", + "keywords": [ + "nest", + "nestjs", + "nodejs", + "typescript", + "telegraf", + "telegram", + "telegram bot", + "telegram bot api", + "bot", + "bot api", + "bot framework" + ], + "homepage": "https://github.com/bukhalo/nestjs-telegraf#readme", + "bugs": { + "url": "https://github.com/bukhalo/nestjs-telegraf/issues", + "email": "aleksandr@bukhalo.com" + }, "license": "MIT", + "author": "Aleksandr Bukhalo ", + "contributors": [ + "Aleksandr Bukhalo (https://bukhalo.com/)", + "Igor Kamyshev (https://kamyshev.me/)" + ], + "repository": "git@github.com:bukhalo/nestjs-telegraf.git", + "scripts": { + "build": "rm -rf dist && tsc -p tsconfig.json", + "precommit": "lint-staged", + "prepublish:npm": "npm run build", + "publish:npm": "npm publish --access public" + }, "dependencies": { "lodash": "^4.17.13" }, - "peerDependencies": { - "@nestjs/common": "^6.7.0", - "@nestjs/core": "^6.7.0", - "reflect-metadata": "^0.1.13", - "telegraf": "^3.35.0" - }, "devDependencies": { "@nestjs/common": "^6.7.0", "@nestjs/core": "^6.7.0", @@ -24,11 +47,11 @@ "telegraf": "^3.35.0", "typescript": "^3.7.4" }, - "scripts": { - "build": "rm -rf dist && tsc -p tsconfig.json", - "precommit": "lint-staged", - "prepublish:npm": "npm run build", - "publish:npm": "npm publish --access public" + "peerDependencies": { + "@nestjs/common": "^6.7.0", + "@nestjs/core": "^6.7.0", + "reflect-metadata": "^0.1.13", + "telegraf": "^3.35.0" }, "husky": { "hooks": {