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

27 lines
782 B
TypeScript
Raw Normal View History

2021-01-06 22:48:10 +03:00
import { Command, Ctx, Hears, Start, Update, Sender } from 'nestjs-telegraf';
import { UpdateType as TelegrafUpdateType } 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 22:48:10 +03:00
import { UpdateType } from '../common/decorators/update-type.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 22:48:10 +03:00
onStart(): string {
return 'Say hello to me';
}
2021-01-03 14:26:32 +03:00
@Hears(['hi', 'hello', 'hey', 'qq'])
2021-01-06 22:48:10 +03:00
onGreetings(
@UpdateType() updateType: TelegrafUpdateType,
@Sender('first_name') firstName: string,
): string {
2021-01-06 19:39:41 +03:00
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
}