Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
feat(telegram): add telegram lib and initial setup
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkamyshev committed Feb 28, 2019
1 parent c700a87 commit 5a95540
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 3 deletions.
3 changes: 2 additions & 1 deletion back/.env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ DB_NAME=checkmoney

PRODUCTION_READY=1

MANNY_API_KEY=Secret
MANNY_API_KEY=Secret
TELEGRAM_BOT_TOKEN=Secret
1 change: 1 addition & 0 deletions back/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"cors": "^2.8.5",
"morgan": "^1.9.1",
"nanoid": "^2.0.1",
"nest-telegram": "^0.1.1",
"pg": "^7.8.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^6.3.3",
Expand Down
20 changes: 18 additions & 2 deletions back/src/app.module.ts
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()
}
}
21 changes: 21 additions & 0 deletions back/src/telegram/TelegramOptionsFactory.ts
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,
}
}
}
25 changes: 25 additions & 0 deletions back/src/telegram/telegram.module.ts
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 back/src/user/presentation/telegram/actions/AuthActions.ts
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')
}
}
2 changes: 2 additions & 0 deletions back/src/user/user.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Registrator } from './application/Registrator'
import { JwtOptionsFactory } from './infrastructure/JwtOptionsFactory'
import { BcryptPasswordEncoder } from './infrastructure/PasswordEncoder/BcryptPasswordEncoder'
import { PasswordEncoder } from './infrastructure/PasswordEncoder/PasswordEncoder'
import { AuthActions } from './presentation/telegram/actions/AuthActions'

@Module({
imports: [
Expand All @@ -44,6 +45,7 @@ import { PasswordEncoder } from './infrastructure/PasswordEncoder/PasswordEncode
ProfileEditor,
UserRepository,
JwtGuard,
AuthActions,
],
exports: [UserRepository, JwtGuard, Authenticator],
})
Expand Down
34 changes: 34 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,11 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.18.tgz#1d3ca764718915584fcd9f6344621b7672665c67"
integrity sha512-fh+pAqt4xRzPfqA6eh3Z2y6fyZavRIumvjhaCL753+TVkGKGhpPeyrJG2JftD0T9q4GF00KjefsQ+PQNDdWQaQ==

"@types/node@^10.1.2":
version "10.12.27"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.27.tgz#eb3843f15d0ba0986cc7e4d734d2ee8b50709ef8"
integrity sha512-e9wgeY6gaY21on3ve0xAjgBVjGDWq/xUteK0ujsE53bUoxycMkqfnkUgMt6ffZtykZ5X12Mg3T7Pw4TRCObDKg==

"@types/prop-types@*":
version "15.5.8"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.5.8.tgz#8ae4e0ea205fe95c3901a5a1df7f66495e3a56ce"
Expand Down Expand Up @@ -7730,6 +7735,14 @@ neo-async@^2.5.0:
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.0.tgz#b9d15e4d71c6762908654b5183ed38b753340835"
integrity sha512-MFh0d/Wa7vkKO3Y3LlacqAEeHK0mckVqzDieUKTT+KGxi+zIpeVsFxymkIiRpbpDziHc290Xr9A1O4Om7otoRA==

nest-telegram@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/nest-telegram/-/nest-telegram-0.1.1.tgz#2ddb9faf41e9f391605b1d44c6bcaacc2d0a4764"
integrity sha512-Ibyx/8xFoYiw/cXnH64yTKrEgIPR4SdeMiFRPmOfYIMje2b03CudMhQ/ubxC3N0G2YLh0WM2YjQxcvlbPw/5Nw==
dependencies:
lodash "^4.17.11"
telegraf "^3.27.1"

netmask@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/netmask/-/netmask-1.0.6.tgz#20297e89d86f6f6400f250d9f4f6b4c1945fcd35"
Expand Down Expand Up @@ -10947,6 +10960,11 @@ safe-regex@^1.1.0:
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==

sandwich-stream@^2.0.1:
version "2.0.2"
resolved "https://registry.yarnpkg.com/sandwich-stream/-/sandwich-stream-2.0.2.tgz#6d1feb6cf7e9fe9fadb41513459a72c2e84000fa"
integrity sha512-jLYV0DORrzY3xaz/S9ydJL6Iz7essZeAfnAavsJ+zsJGZ1MOnsS52yRjU3uF3pJa/lla7+wisp//fxOwOH8SKQ==

sass-lookup@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/sass-lookup/-/sass-lookup-3.0.0.tgz#3b395fa40569738ce857bc258e04df2617c48cac"
Expand Down Expand Up @@ -11934,6 +11952,22 @@ tar@^4:
safe-buffer "^5.1.2"
yallist "^3.0.2"

telegraf@^3.27.1:
version "3.27.1"
resolved "https://registry.yarnpkg.com/telegraf/-/telegraf-3.27.1.tgz#67fbd87a6b4f414a204820f8cb30160e2078b39c"
integrity sha512-RQUnuNAEEWcLhRap81qwGUUqAy1KcvqANnA0G3pzZqFkhMe6LrTk5lVi9tdOaF0Ud/yOx5fdx0rNPYfiB27Z+w==
dependencies:
"@types/node" "^10.1.2"
debug "^4.0.1"
node-fetch "^2.2.0"
sandwich-stream "^2.0.1"
telegram-typings "^3.6.0"

telegram-typings@^3.6.0:
version "3.6.1"
resolved "https://registry.yarnpkg.com/telegram-typings/-/telegram-typings-3.6.1.tgz#1288d547f8694b61f1c01c2993e295f3114d9e25"
integrity sha512-njVv1EAhIZnmQVLocZEADYUyqA1WIXuVcDYlsp+mXua/XB0pxx+PKtMSPeZ/EE4wPWTw9h/hA9ASTT6yQelkiw==

temp@~0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/temp/-/temp-0.4.0.tgz#671ad63d57be0fe9d7294664b3fc400636678a60"
Expand Down

0 comments on commit 5a95540

Please sign in to comment.