mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2025-10-18 09:09:20 +03:00
initial commit
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { EchoUpdate } from './echo.update';
|
||||
import { EchoService } from './echo.service';
|
||||
import { RandomNumberScene } from '../greeter/scenes/random-number.scene';
|
||||
|
||||
@Module({
|
||||
providers: [EchoUpdate, EchoService, RandomNumberScene],
|
||||
})
|
||||
export class EchoModule {}
|
@@ -1,8 +0,0 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class EchoService {
|
||||
echo(text: string): string {
|
||||
return `Echo: ${text}`;
|
||||
}
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
import { UseFilters, UseGuards, UseInterceptors } from '@nestjs/common';
|
||||
import {
|
||||
Help,
|
||||
InjectBot,
|
||||
On,
|
||||
Message,
|
||||
Start,
|
||||
Update,
|
||||
Command,
|
||||
} from 'nestjs-telegraf';
|
||||
import { Telegraf } from 'telegraf';
|
||||
import { EchoService } from './echo.service';
|
||||
import { GreeterBotName } from '../app.constants';
|
||||
import { Context } from '../interfaces/context.interface';
|
||||
import { ReverseTextPipe } from '../common/pipes/reverse-text.pipe';
|
||||
import { ResponseTimeInterceptor } from '../common/interceptors/response-time.interceptor';
|
||||
import { AdminGuard } from '../common/guards/admin.guard';
|
||||
import { TelegrafExceptionFilter } from '../common/filters/telegraf-exception.filter';
|
||||
|
||||
@Update()
|
||||
@UseInterceptors(ResponseTimeInterceptor)
|
||||
@UseFilters(TelegrafExceptionFilter)
|
||||
export class EchoUpdate {
|
||||
constructor(
|
||||
@InjectBot(GreeterBotName)
|
||||
private readonly bot: Telegraf<Context>,
|
||||
private readonly echoService: EchoService,
|
||||
) {}
|
||||
|
||||
@Start()
|
||||
async onStart(): Promise<string> {
|
||||
const me = await this.bot.telegram.getMe();
|
||||
return `Hey, I'm ${me.first_name}`;
|
||||
}
|
||||
|
||||
@Help()
|
||||
async onHelp(): Promise<string> {
|
||||
return 'Send me any text';
|
||||
}
|
||||
|
||||
@Command('admin')
|
||||
@UseGuards(AdminGuard)
|
||||
onAdminCommand(): string {
|
||||
return 'Welcome judge';
|
||||
}
|
||||
|
||||
@On('text')
|
||||
onMessage(
|
||||
@Message('text', new ReverseTextPipe()) reversedText: string,
|
||||
): string {
|
||||
return this.echoService.echo(reversedText);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user