feat(sample): update sample

This commit is contained in:
Morb0
2021-01-06 22:48:10 +03:00
parent daf0d8ffdf
commit 7f7f786373
8 changed files with 51 additions and 32 deletions

View File

@@ -1,7 +1,8 @@
import { Module } from '@nestjs/common';
import { GreeterUpdate } from './greeter.update';
import { RandomNumberScene } from './scenes/random-number.scene';
@Module({
providers: [GreeterUpdate],
providers: [GreeterUpdate, RandomNumberScene],
})
export class GreeterModule {}

View File

@@ -1,18 +1,21 @@
import { Command, Context as Ctx, Hears, Start, Update } from 'nestjs-telegraf';
import { User } from 'telegraf/typings/telegram-types';
import { Command, Ctx, Hears, Start, Update, Sender } from 'nestjs-telegraf';
import { UpdateType as TelegrafUpdateType } from 'telegraf/typings/telegram-types';
import { Context } from '../interfaces/context.interface';
import { HELLO_SCENE_ID } from '../app.constants';
import { From } from '../common/decorators/from.decorator';
import { UpdateType } from '../common/decorators/update-type.decorator';
@Update()
export class GreeterUpdate {
@Start()
async onStart(@Ctx() ctx: Context): Promise<void> {
await ctx.reply('Say hello to me');
onStart(): string {
return 'Say hello to me';
}
@Hears(['hi', 'hello', 'hey', 'qq'])
onGreetings(@From() { first_name: firstName }: User): string {
onGreetings(
@UpdateType() updateType: TelegrafUpdateType,
@Sender('first_name') firstName: string,
): string {
return `Hey ${firstName}`;
}

View File

@@ -3,23 +3,23 @@ import { HELLO_SCENE_ID } from '../../app.constants';
import { Context } from '../../interfaces/context.interface';
@Scene(HELLO_SCENE_ID)
export class HelloScene {
export class RandomNumberScene {
@SceneEnter()
async onSceneEnter(ctx: Context): Promise<void> {
onSceneEnter(): string {
console.log('Enter to scene');
await ctx.reply('Welcome on scene ✋');
return 'Welcome on scene ✋';
}
@SceneLeave()
async onSceneLeave(ctx: Context): Promise<void> {
onSceneLeave(): string {
console.log('Leave from scene');
await ctx.reply('Bye Bye 👋');
return 'Bye Bye 👋';
}
@Command('hello')
async onHelloCommand(ctx: Context): Promise<void> {
console.log('Use say hello');
await ctx.reply('Hi');
@Command(['rng', 'random'])
onRandomCommand(): number {
console.log('Use "random" command');
return Math.floor(Math.random() * 11);
}
@Command('leave')