diff --git a/src/app.module.ts b/src/app.module.ts index d2cddd0..35b18cf 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -24,7 +24,7 @@ import { UserMetaInfo } from './couchdb-datasources/user-meta-info'; import { PersonalNotificationAdapterService } from './notifications/adapters/personal-notification.adapter/personal-notification.adapter.service'; import { StatusChangeAdapterService } from './notifications/adapters/status-change.adapter.service'; import { CurrentIssuesEccmReportService } from './reports/current-issues-eccm.report.service'; -import { CurrentIssuesBotHandlerService } from './telegram-bot/handlers/current-issues.bot-handler.service'; +import { CurrentIssuesEccmBotHandlerService } from './telegram-bot/handlers/current-issues-eccm.bot-handler.service'; import { CurrentIssuesEccmReportController } from './reports/current-issues-eccm.report.controller'; import { DailyEccmReportController } from './reports/daily-eccm.report.controller'; import { DailyEccmReportService } from './reports/daily-eccm.report.service'; @@ -61,7 +61,7 @@ import { ChangesService } from './changes/changes.service'; PersonalNotificationAdapterService, StatusChangeAdapterService, CurrentIssuesEccmReportService, - CurrentIssuesBotHandlerService, + CurrentIssuesEccmBotHandlerService, DailyEccmReportService, ChangesService, ], diff --git a/src/telegram-bot/handlers/current-issues.bot-handler.service.ts b/src/telegram-bot/handlers/current-issues-eccm.bot-handler.service.ts similarity index 75% rename from src/telegram-bot/handlers/current-issues.bot-handler.service.ts rename to src/telegram-bot/handlers/current-issues-eccm.bot-handler.service.ts index 78f9e60..2392ccc 100644 --- a/src/telegram-bot/handlers/current-issues.bot-handler.service.ts +++ b/src/telegram-bot/handlers/current-issues-eccm.bot-handler.service.ts @@ -2,17 +2,23 @@ import { Injectable, Logger } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import TelegramBot from 'node-telegram-bot-api'; import { EccmConfig } from 'src/models/eccm-config.model'; -import { CurrentIssuesEccmReport, CurrentIssuesEccmReportService } from 'src/reports/current-issues-eccm.report.service'; +import { + CurrentIssuesEccmReport, + CurrentIssuesEccmReportService, +} from 'src/reports/current-issues-eccm.report.service'; import { UserMetaInfoService } from 'src/user-meta-info/user-meta-info.service'; import { TelegramBotService } from '../telegram-bot.service'; +import { TelegramBotHandlerInterface } from '../telegram.bot-handler.interface'; @Injectable() -export class CurrentIssuesBotHandlerService { - private forName = /\/current_issues_eccm (.+) (.+)/; +export class CurrentIssuesEccmBotHandlerService + implements TelegramBotHandlerInterface +{ + private forName = /\/current_issues_eccm (.+)/; private forCurrentUser = /\/current_issues_eccm/; private service: TelegramBotService; private eccmConfig: EccmConfig.Config; - private logger = new Logger(CurrentIssuesBotHandlerService.name); + private logger = new Logger(CurrentIssuesEccmBotHandlerService.name); constructor( private configService: ConfigService, @@ -44,4 +50,8 @@ export class CurrentIssuesBotHandlerService { }); }); } + + getHelpMsg(): string { + return '/current_issues_eccm - ваши текущие задачи из проекта ECCM'; + } } diff --git a/src/telegram-bot/telegram-bot.service.ts b/src/telegram-bot/telegram-bot.service.ts index 37da5fa..5c5dfe2 100644 --- a/src/telegram-bot/telegram-bot.service.ts +++ b/src/telegram-bot/telegram-bot.service.ts @@ -5,7 +5,8 @@ import TelegramBot from 'node-telegram-bot-api'; import { UserMetaInfoService } from 'src/user-meta-info/user-meta-info.service'; import axios from 'axios'; import { UserMetaInfoModel } from 'src/models/user-meta-info.model'; -import { CurrentIssuesBotHandlerService } from './handlers/current-issues.bot-handler.service'; +import { CurrentIssuesEccmBotHandlerService } from './handlers/current-issues-eccm.bot-handler.service'; +import { TelegramBotHandlerInterface } from './telegram.bot-handler.interface'; @Injectable() export class TelegramBotService { @@ -16,16 +17,19 @@ export class TelegramBotService { private registerRe = /\/register (\d+) (.+)/; + private handlers: TelegramBotHandlerInterface[] = []; + constructor( private userMetaInfoService: UserMetaInfoService, private usersService: UsersService, private configService: ConfigService, - private currentIssuesBotHandlerService: CurrentIssuesBotHandlerService, + private currentIssuesBotHandlerService: CurrentIssuesEccmBotHandlerService, ) { this.telegramBotToken = this.configService.get('telegramBotToken'); this.redminePublicUrlPrefix = this.configService.get('redmineUrlPublic'); this.initTelegramBot(); + this.handlers.push(this.currentIssuesBotHandlerService); } private async initTelegramBot(): Promise { @@ -51,19 +55,22 @@ export class TelegramBotService { msg.chat.id, ); let helpMessage: string; + /* eslint-disable */ if (userMetaInfo) { - // eslint-disable-next-line prettier/prettier + const handlersMessages = this.handlers + .map((handler) => handler.getHelpMsg()) + .join('\n'); helpMessage = [ - `/current_issues - мои текущие задачи`, + handlersMessages, `/help` ].join('\n'); } else { - // eslint-disable-next-line prettier/prettier helpMessage = [ `/register `, - `/help` + `/help`, ].join('\n'); } + /* eslint-enable */ this.logger.debug( `Sent help message for telegramChatId = ${msg.chat.id}, ` + `message = ${helpMessage}`, diff --git a/src/telegram-bot/telegram.bot-handler.interface.ts b/src/telegram-bot/telegram.bot-handler.interface.ts new file mode 100644 index 0000000..cc20fc3 --- /dev/null +++ b/src/telegram-bot/telegram.bot-handler.interface.ts @@ -0,0 +1,7 @@ +import TelegramBot from 'node-telegram-bot-api'; +import { TelegramBotService } from './telegram-bot.service'; + +export interface TelegramBotHandlerInterface { + init(service: TelegramBotService, bot: TelegramBot): Promise; + getHelpMsg(): string; +}