diff --git a/back/src/app.module.ts b/back/src/app.module.ts index b637b5a8..2e9a2bf1 100644 --- a/back/src/app.module.ts +++ b/back/src/app.module.ts @@ -33,9 +33,9 @@ export class AppModule implements NestModule { public configure(consumer: MiddlewareConsumer) { this.telegramBot.init(this.moduleRef) - // if (this.config.isDev()) { - // // in dev use long poll - // this.telegramBot.startPolling() - // } + if (this.config.isDev()) { + // in dev use long poll + this.telegramBot.startPolling() + } } } diff --git a/back/src/telegram/telegram.module.ts b/back/src/telegram/telegram.module.ts index b9f0291f..2e9e7c36 100644 --- a/back/src/telegram/telegram.module.ts +++ b/back/src/telegram/telegram.module.ts @@ -2,8 +2,10 @@ import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common' import { TelegramModule as OriginalTelegramModule } from 'nest-telegram' import { ConfigModule } from '@back/config/config.module' +import { UtilsModule } from '@back/utils/utils.module' import { TelegramOptionsFactory } from './TelegramOptionsFactory' +import { HelpActions } from './telegram/actions/HelpActions' @Module({ imports: [ @@ -11,8 +13,9 @@ import { TelegramOptionsFactory } from './TelegramOptionsFactory' imports: [ConfigModule], useClass: TelegramOptionsFactory, }), + UtilsModule, ], - providers: [TelegramOptionsFactory], + providers: [TelegramOptionsFactory, HelpActions], exports: [OriginalTelegramModule], }) export class TelegramModule implements NestModule { diff --git a/back/src/telegram/telegram/actions/HelpActions.ts b/back/src/telegram/telegram/actions/HelpActions.ts new file mode 100644 index 00000000..c08a7e93 --- /dev/null +++ b/back/src/telegram/telegram/actions/HelpActions.ts @@ -0,0 +1,16 @@ +import { Injectable } from '@nestjs/common' +import { Context, TelegramActionHandler } from 'nest-telegram' + +import { Templating } from '@back/utils/infrastructure/Templating/Templating' + +@Injectable() +export class HelpActions { + public constructor(private readonly templating: Templating) {} + + @TelegramActionHandler({ command: '/help' }) + public async income(ctx: Context) { + const responseText = await this.templating.render('telegram/help', {}) + + await ctx.reply(responseText) + } +} diff --git a/back/src/user/presentation/telegram/actions/AuthActions.ts b/back/src/user/presentation/telegram/actions/AuthActions.ts index 8068794d..45f52ceb 100644 --- a/back/src/user/presentation/telegram/actions/AuthActions.ts +++ b/back/src/user/presentation/telegram/actions/AuthActions.ts @@ -3,6 +3,7 @@ import { TelegramActionHandler, Context, PipeContext } from 'nest-telegram' import { Authenticator } from '@back/user/application/Authenticator' import { Registrator } from '@back/user/application/Registrator' +import { Templating } from '@back/utils/infrastructure/Templating/Templating' import { IsKnownUser } from '../transformer/IsKnownUser' @@ -11,6 +12,7 @@ export class AuthActions { constructor( private readonly authenticator: Authenticator, private readonly registrator: Registrator, + private readonly templating: Templating, ) {} @TelegramActionHandler({ onStart: true }) @@ -18,11 +20,11 @@ export class AuthActions { ctx: Context, @PipeContext(IsKnownUser) loggedIn: boolean, ) { - await ctx.reply('Hello!') + const responseText = await this.templating.render('telegram/start', { + loggedIn, + }) - await ctx.reply( - loggedIn ? 'Welcome back!' : 'To auth send me "/auth login password"', - ) + await ctx.reply(responseText) } @TelegramActionHandler({ command: 'auth' }) diff --git a/back/src/user/user.module.ts b/back/src/user/user.module.ts index c7d55945..eee0313a 100644 --- a/back/src/user/user.module.ts +++ b/back/src/user/user.module.ts @@ -4,6 +4,7 @@ import { TypeOrmModule } from '@nestjs/typeorm' import { ConfigModule } from '@back/config/config.module' import { DbModule } from '@back/db/db.module' +import { UtilsModule } from '@back/utils/utils.module' import { AuthController } from './presentation/http/controller/AuthController' import { ProfileController } from './presentation/http/controller/ProfileController' @@ -29,6 +30,7 @@ import { PasswordEncoder } from './infrastructure/PasswordEncoder/PasswordEncode @Module({ imports: [ DbModule, + UtilsModule, TypeOrmModule.forFeature([User]), JwtModule.registerAsync({ imports: [ConfigModule], diff --git a/back/templates/telegram/help.hbs b/back/templates/telegram/help.hbs new file mode 100644 index 00000000..badbbab1 --- /dev/null +++ b/back/templates/telegram/help.hbs @@ -0,0 +1,14 @@ +I am Checkmoney Robot + +My site — https://checkmoney.space +Mirror — https://checkmoney.ml + +Available commands: + +To create outcome transaction: +/outcome 100 usd Lunch + +To create income transaction: +/income 10000 eur ESA + +Of course, you can use any amounts, currencies and comments. diff --git a/back/templates/telegram/start.hbs b/back/templates/telegram/start.hbs new file mode 100644 index 00000000..5fd5acd7 --- /dev/null +++ b/back/templates/telegram/start.hbs @@ -0,0 +1,5 @@ +Hello! + +{{#if loggedIn}}Welcome back{{else}}To auth send me "/auth login password"{{/if}} + +If you need help, just send me /help \ No newline at end of file