Добавлен вывод help сообщений из обработчиков команд из telegram
This commit is contained in:
parent
c4ffa0821b
commit
726596ce12
4 changed files with 36 additions and 12 deletions
|
|
@ -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,
|
||||
],
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
|
@ -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<string>('telegramBotToken');
|
||||
this.redminePublicUrlPrefix =
|
||||
this.configService.get<string>('redmineUrlPublic');
|
||||
this.initTelegramBot();
|
||||
this.handlers.push(this.currentIssuesBotHandlerService);
|
||||
}
|
||||
|
||||
private async initTelegramBot(): Promise<void> {
|
||||
|
|
@ -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 <redmine_id> <redmine_token>`,
|
||||
`/help`
|
||||
`/help`,
|
||||
].join('\n');
|
||||
}
|
||||
/* eslint-enable */
|
||||
this.logger.debug(
|
||||
`Sent help message for telegramChatId = ${msg.chat.id}, ` +
|
||||
`message = ${helpMessage}`,
|
||||
|
|
|
|||
7
src/telegram-bot/telegram.bot-handler.interface.ts
Normal file
7
src/telegram-bot/telegram.bot-handler.interface.ts
Normal file
|
|
@ -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<void>;
|
||||
getHelpMsg(): string;
|
||||
}
|
||||
Loading…
Reference in a new issue