nestjs-telegraf/sample/01-complete-app/src/echo/echo.update.ts
2021-01-06 22:48:10 +03:00

54 lines
1.4 KiB
TypeScript

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);
}
}