nestjs-telegraf/sample/01-complete-app/src/greeter/greeter.update.ts

24 lines
727 B
TypeScript
Raw Normal View History

2021-01-06 19:39:41 +03:00
import { Command, Context as Ctx, Hears, Start, Update } from 'nestjs-telegraf';
import { User } from 'telegraf/typings/telegram-types';
2021-01-03 14:26:32 +03:00
import { Context } from '../interfaces/context.interface';
import { HELLO_SCENE_ID } from '../app.constants';
2021-01-06 19:39:41 +03:00
import { From } from '../common/decorators/from.decorator';
2021-01-03 14:26:32 +03:00
@Update()
2021-01-03 14:26:32 +03:00
export class GreeterUpdate {
@Start()
2021-01-06 19:39:41 +03:00
async onStart(@Ctx() ctx: Context): Promise<void> {
await ctx.reply('Say hello to me');
}
2021-01-03 14:26:32 +03:00
@Hears(['hi', 'hello', 'hey', 'qq'])
2021-01-06 19:39:41 +03:00
onGreetings(@From() { first_name: firstName }: User): string {
return `Hey ${firstName}`;
2021-01-03 14:26:32 +03:00
}
@Command('scene')
2021-01-06 19:39:41 +03:00
async onSceneCommand(@Ctx() ctx: Context): Promise<void> {
await ctx.scene.enter(HELLO_SCENE_ID);
}
2021-01-03 14:26:32 +03:00
}