chore(package.json): remove sample app start

This commit is contained in:
Morb0
2021-01-03 16:39:13 +03:00
parent 4420e01d8a
commit 6ab86f9fad
12 changed files with 1 additions and 3 deletions

View File

@@ -0,0 +1,3 @@
export const HELLO_SCENE_ID = 'HELLO_SCENE_ID';
export const GreeterBotName = 'greeter';

View File

@@ -0,0 +1,25 @@
import { Module } from '@nestjs/common';
import { TelegrafModule } from '../lib';
import { EchoModule } from './echo/echo.module';
import { GreeterModule } from './greeter/greeter.module';
import { sessionMiddleware } from './middleware/session.middleware';
import { GreeterBotName } from './app.constants';
@Module({
imports: [
TelegrafModule.forRoot({
token: '1417509321:AAEHz8a2QSAP4cTHh4Z6-ulePysFaUx4SjY', // Don't steal >:(
middlewares: [sessionMiddleware],
include: [EchoModule],
}),
TelegrafModule.forRoot({
name: GreeterBotName,
token: '1435922623:AAHmBmnyqroHxDbuK6OKsLV8Y_oB_Lf9E6E', // Don't steal >:(
middlewares: [sessionMiddleware],
include: [GreeterModule],
}),
EchoModule,
GreeterModule,
],
})
export class AppModule {}

View File

@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { EchoUpdate } from './echo.update';
import { EchoService } from './echo.service';
import { HelloScene } from './scenes/hello.scene';
@Module({
providers: [EchoUpdate, EchoService, HelloScene],
})
export class EchoModule {}

View File

@@ -0,0 +1,8 @@
import { Injectable } from '@nestjs/common';
@Injectable()
export class EchoService {
echo(text: string): string {
return `Echo: ${text}`;
}
}

View File

@@ -0,0 +1,43 @@
import { Telegraf } from 'telegraf';
import { Command, Help, InjectBot, On, Start, Update } from '../../lib';
import { EchoService } from './echo.service';
import { HELLO_SCENE_ID } from '../app.constants';
import { Context } from '../interfaces/context.interface';
@Update()
export class EchoUpdate {
constructor(
@InjectBot()
private readonly bot: Telegraf<Context>,
private readonly echoService: EchoService,
) {}
@Start()
async onStart(ctx: Context): Promise<void> {
const me = await this.bot.telegram.getMe();
await ctx.reply(`Hey, I'm ${me.first_name}`);
}
@Help()
async onHelp(ctx: Context): Promise<void> {
await ctx.reply('Send me any text');
}
@Command('scene')
async onSceneCommand(ctx: Context): Promise<void> {
await ctx.scene.enter(HELLO_SCENE_ID);
}
@On('message')
async onMessage(ctx: Context): Promise<void> {
console.log('New message received');
if ('text' in ctx.message) {
const messageText = ctx.message.text;
const echoText = this.echoService.echo(messageText);
await ctx.reply(echoText);
} else {
await ctx.reply('Only text messages');
}
}
}

View File

@@ -0,0 +1,29 @@
import { HELLO_SCENE_ID } from '../../app.constants';
import { Context } from '../../interfaces/context.interface';
import { Scene, SceneEnter, SceneLeave, Command } from '../../../lib';
@Scene(HELLO_SCENE_ID)
export class HelloScene {
@SceneEnter()
async onSceneEnter(ctx: Context): Promise<void> {
console.log('Enter to scene');
await ctx.reply('Welcome on scene ✋');
}
@SceneLeave()
async onSceneLeave(ctx: Context): Promise<void> {
console.log('Leave from scene');
await ctx.reply('Bye Bye 👋');
}
@Command('hello')
async onHelloCommand(ctx: Context): Promise<void> {
console.log('Use say hello');
await ctx.reply('Hi');
}
@Command('leave')
async onLeaveCommand(ctx: Context): Promise<void> {
await ctx.scene.leave();
}
}

View File

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

View File

@@ -0,0 +1,16 @@
import { Hears, Start, Update } from '../../lib';
import { Context } from '../interfaces/context.interface';
@Update()
export class GreeterUpdate {
@Start()
async onStart(ctx: Context): Promise<void> {
await ctx.reply('Say hello to me');
}
@Hears(['hi', 'hello', 'hey', 'qq'])
async onGreetings(ctx: Context): Promise<void> {
const { first_name } = ctx.from;
await ctx.reply(`Hey ${first_name}`);
}
}

View File

@@ -0,0 +1,4 @@
import { SceneContextMessageUpdate } from 'telegraf/typings/stage';
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface Context extends SceneContextMessageUpdate {}

View File

@@ -0,0 +1,7 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
await NestFactory.createApplicationContext(AppModule);
}
bootstrap();

View File

@@ -0,0 +1,3 @@
import { session } from 'telegraf';
export const sessionMiddleware = session();