This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(telegram): add telegram lib and initial setup
- Loading branch information
1 parent
c700a87
commit 5a95540
Showing
8 changed files
with
113 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ DB_NAME=checkmoney | |
|
||
PRODUCTION_READY=1 | ||
|
||
MANNY_API_KEY=Secret | ||
MANNY_API_KEY=Secret | ||
TELEGRAM_BOT_TOKEN=Secret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,32 @@ | ||
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common' | ||
import { ModuleRef } from '@nestjs/core' | ||
import { TelegramBot } from 'nest-telegram' | ||
|
||
import { ConfigModule } from './config/config.module' | ||
import { DbModule } from './db/db.module' | ||
import { MoneyModule } from './money/money.module' | ||
import { UserModule } from './user/user.module' | ||
import { UtilsModule } from './utils/utils.module' | ||
import { TelegramModule } from './telegram/telegram.module' | ||
|
||
@Module({ | ||
imports: [UserModule, MoneyModule, UtilsModule, ConfigModule, DbModule], | ||
imports: [ | ||
UserModule, | ||
MoneyModule, | ||
UtilsModule, | ||
ConfigModule, | ||
DbModule, | ||
TelegramModule, | ||
], | ||
}) | ||
export class AppModule implements NestModule { | ||
public constructor( | ||
private readonly telegramBot: TelegramBot, | ||
private readonly moduleRef: ModuleRef, | ||
) {} | ||
|
||
public configure(consumer: MiddlewareConsumer) { | ||
// pass | ||
this.telegramBot.init(this.moduleRef) | ||
this.telegramBot.start() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Injectable } from '@nestjs/common' | ||
import { | ||
TelegramModuleOptionsFactory, | ||
TelegramModuleOptions, | ||
} from 'nest-telegram' | ||
import { Configuration } from '@back/config/Configuration' | ||
|
||
@Injectable() | ||
export class TelegramOptionsFactory implements TelegramModuleOptionsFactory { | ||
private readonly token: string | ||
|
||
public constructor(config: Configuration) { | ||
this.token = config.getStringOrElse('TELEGRAM_BOT_TOKEN', 'Secret') | ||
} | ||
|
||
public createOptions(): TelegramModuleOptions { | ||
return { | ||
token: this.token, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common' | ||
import { | ||
TelegramModule as OriginalTelegramModule, | ||
TelegramBot, | ||
} from 'nest-telegram' | ||
|
||
import { ConfigModule } from '@back/config/config.module' | ||
|
||
import { TelegramOptionsFactory } from './TelegramOptionsFactory' | ||
|
||
@Module({ | ||
imports: [ | ||
OriginalTelegramModule.fromFactory({ | ||
imports: [ConfigModule], | ||
useClass: TelegramOptionsFactory, | ||
}), | ||
], | ||
providers: [TelegramOptionsFactory], | ||
exports: [OriginalTelegramModule], | ||
}) | ||
export class TelegramModule implements NestModule { | ||
public configure(consumer: MiddlewareConsumer) { | ||
// pass | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
back/src/user/presentation/telegram/actions/AuthActions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Injectable } from '@nestjs/common' | ||
import { TelegramActionHandler, Context } from 'nest-telegram' | ||
|
||
@Injectable() | ||
export class AuthActions { | ||
@TelegramActionHandler({ onStart: true }) | ||
public async hello(ctx: Context) { | ||
await ctx.reply('lol') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters