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, private readonly echoService: EchoService, ) {} @Start() async onStart(): Promise { const me = await this.bot.telegram.getMe(); return `Hey, I'm ${me.first_name}`; } @Help() async onHelp(): Promise { 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); } }