mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2024-12-24 23:14:39 +03:00
docs(): update readme
This commit is contained in:
parent
d1a67fb440
commit
d9ab26f11a
56
README.md
56
README.md
@ -1,15 +1,21 @@
|
|||||||
<p align="center">
|
# NestJS Telegraf ![npm](https://img.shields.io/npm/dm/nestjs-telegraf) ![GitHub last commit](https://img.shields.io/github/last-commit/bukhalo/nestjs-telegraf) ![NPM](https://img.shields.io/npm/l/nestjs-telegraf)
|
||||||
<a href="http://nestjs.com/" target="blank">
|
|
||||||
<img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
# NestJS Telegraf
|
<img align="right" width="95" height="148" title="NestJS logotype"
|
||||||
![npm](https://img.shields.io/npm/dm/nestjs-telegraf)
|
src="https://nestjs.com/img/logo-small.svg">
|
||||||
![GitHub last commit](https://img.shields.io/github/last-commit/bukhalo/nestjs-telegraf)
|
|
||||||
![NPM](https://img.shields.io/npm/l/nestjs-telegraf)
|
|
||||||
|
|
||||||
[Telegraf](https://github.com/telegraf/telegraf) module for [NestJS](https://github.com/nestjs/nest).
|
NestJS Telegraf – powerful solution for creating Telegram bots.
|
||||||
|
|
||||||
|
This package uses the best of the NodeJS world under the hood. [Telegraf](https://github.com/telegraf/telegraf) is the most powerful library for creating bots and [NestJS](https://github.com/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
|
## Documentation
|
||||||
If you want to dive fully into NestJS Telegraf then don't waste your time in this dump, check out the [documentation site](https://nestjs-telegraf.vercel.app).
|
If you want to dive fully into NestJS Telegraf then don't waste your time in this dump, check out the [documentation site](https://nestjs-telegraf.vercel.app).
|
||||||
@ -20,8 +26,8 @@ If you want to dive fully into NestJS Telegraf then don't waste your time in thi
|
|||||||
$ npm i nestjs-telegraf
|
$ npm i nestjs-telegraf
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
Once the installation process is complete, we can import the `TelegrafModule` into the root `AppModule`:
|
Once the installation process is complete, we can import the `TelegrafModule` into the root `AppModule`:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { TelegrafModule } from 'nestjs-telegraf';
|
import { TelegrafModule } from 'nestjs-telegraf';
|
||||||
@ -36,38 +42,42 @@ import { TelegrafModule } from 'nestjs-telegraf';
|
|||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
```
|
```
|
||||||
|
|
||||||
Then add some decorators into the `app.service.ts` for handling Telegram bot API updates:
|
Then create `app.update.ts` file and add some decorators for handling Telegram bot API updates:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import {
|
import {
|
||||||
|
Update,
|
||||||
Start,
|
Start,
|
||||||
Help,
|
Help,
|
||||||
On,
|
On,
|
||||||
Hears,
|
Hears,
|
||||||
Context,
|
Context,
|
||||||
} from 'nestjs-telegraf';
|
} from 'nestjs-telegraf';
|
||||||
|
import { AppService } from './app.service';
|
||||||
|
import { Context } from './context.interface';
|
||||||
|
|
||||||
|
@Update()
|
||||||
|
export class AppUpdate {
|
||||||
|
constructor(private readonly appService: AppService)
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class AppService {
|
|
||||||
@Start()
|
@Start()
|
||||||
start(ctx: Context) {
|
async startCommand(ctx: Context) {
|
||||||
ctx.reply('Welcome');
|
await ctx.reply('Welcome');
|
||||||
}
|
}
|
||||||
|
|
||||||
@Help()
|
@Help()
|
||||||
help(ctx: Context) {
|
async helpCommand(ctx: Context) {
|
||||||
ctx.reply('Send me a sticker');
|
await ctx.reply('Send me a sticker');
|
||||||
}
|
}
|
||||||
|
|
||||||
@On('sticker')
|
@On('sticker')
|
||||||
on(ctx: Context) {
|
async onSticker(ctx: Context) {
|
||||||
ctx.reply('👍');
|
await ctx.reply('👍');
|
||||||
}
|
}
|
||||||
|
|
||||||
@Hears('hi')
|
@Hears('hi')
|
||||||
hears(ctx: Context) {
|
async hearsHi(ctx: Context) {
|
||||||
ctx.reply('Hey there');
|
await ctx.reply('Hey there');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user