mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2025-10-01 20:41:27 +03:00
feat(sample): update sample
This commit is contained in:
@@ -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 {}
|
||||
|
@@ -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}`;
|
||||
}
|
||||
|
||||
|
@@ -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')
|
Reference in New Issue
Block a user