Добавлен вывод 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 { PersonalNotificationAdapterService } from './notifications/adapters/personal-notification.adapter/personal-notification.adapter.service';
|
||||||
import { StatusChangeAdapterService } from './notifications/adapters/status-change.adapter.service';
|
import { StatusChangeAdapterService } from './notifications/adapters/status-change.adapter.service';
|
||||||
import { CurrentIssuesEccmReportService } from './reports/current-issues-eccm.report.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 { CurrentIssuesEccmReportController } from './reports/current-issues-eccm.report.controller';
|
||||||
import { DailyEccmReportController } from './reports/daily-eccm.report.controller';
|
import { DailyEccmReportController } from './reports/daily-eccm.report.controller';
|
||||||
import { DailyEccmReportService } from './reports/daily-eccm.report.service';
|
import { DailyEccmReportService } from './reports/daily-eccm.report.service';
|
||||||
|
|
@ -61,7 +61,7 @@ import { ChangesService } from './changes/changes.service';
|
||||||
PersonalNotificationAdapterService,
|
PersonalNotificationAdapterService,
|
||||||
StatusChangeAdapterService,
|
StatusChangeAdapterService,
|
||||||
CurrentIssuesEccmReportService,
|
CurrentIssuesEccmReportService,
|
||||||
CurrentIssuesBotHandlerService,
|
CurrentIssuesEccmBotHandlerService,
|
||||||
DailyEccmReportService,
|
DailyEccmReportService,
|
||||||
ChangesService,
|
ChangesService,
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,23 @@ import { Injectable, Logger } from '@nestjs/common';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
import TelegramBot from 'node-telegram-bot-api';
|
import TelegramBot from 'node-telegram-bot-api';
|
||||||
import { EccmConfig } from 'src/models/eccm-config.model';
|
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 { UserMetaInfoService } from 'src/user-meta-info/user-meta-info.service';
|
||||||
import { TelegramBotService } from '../telegram-bot.service';
|
import { TelegramBotService } from '../telegram-bot.service';
|
||||||
|
import { TelegramBotHandlerInterface } from '../telegram.bot-handler.interface';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CurrentIssuesBotHandlerService {
|
export class CurrentIssuesEccmBotHandlerService
|
||||||
private forName = /\/current_issues_eccm (.+) (.+)/;
|
implements TelegramBotHandlerInterface
|
||||||
|
{
|
||||||
|
private forName = /\/current_issues_eccm (.+)/;
|
||||||
private forCurrentUser = /\/current_issues_eccm/;
|
private forCurrentUser = /\/current_issues_eccm/;
|
||||||
private service: TelegramBotService;
|
private service: TelegramBotService;
|
||||||
private eccmConfig: EccmConfig.Config;
|
private eccmConfig: EccmConfig.Config;
|
||||||
private logger = new Logger(CurrentIssuesBotHandlerService.name);
|
private logger = new Logger(CurrentIssuesEccmBotHandlerService.name);
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private configService: ConfigService,
|
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 { UserMetaInfoService } from 'src/user-meta-info/user-meta-info.service';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { UserMetaInfoModel } from 'src/models/user-meta-info.model';
|
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()
|
@Injectable()
|
||||||
export class TelegramBotService {
|
export class TelegramBotService {
|
||||||
|
|
@ -16,16 +17,19 @@ export class TelegramBotService {
|
||||||
|
|
||||||
private registerRe = /\/register (\d+) (.+)/;
|
private registerRe = /\/register (\d+) (.+)/;
|
||||||
|
|
||||||
|
private handlers: TelegramBotHandlerInterface[] = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private userMetaInfoService: UserMetaInfoService,
|
private userMetaInfoService: UserMetaInfoService,
|
||||||
private usersService: UsersService,
|
private usersService: UsersService,
|
||||||
private configService: ConfigService,
|
private configService: ConfigService,
|
||||||
private currentIssuesBotHandlerService: CurrentIssuesBotHandlerService,
|
private currentIssuesBotHandlerService: CurrentIssuesEccmBotHandlerService,
|
||||||
) {
|
) {
|
||||||
this.telegramBotToken = this.configService.get<string>('telegramBotToken');
|
this.telegramBotToken = this.configService.get<string>('telegramBotToken');
|
||||||
this.redminePublicUrlPrefix =
|
this.redminePublicUrlPrefix =
|
||||||
this.configService.get<string>('redmineUrlPublic');
|
this.configService.get<string>('redmineUrlPublic');
|
||||||
this.initTelegramBot();
|
this.initTelegramBot();
|
||||||
|
this.handlers.push(this.currentIssuesBotHandlerService);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async initTelegramBot(): Promise<void> {
|
private async initTelegramBot(): Promise<void> {
|
||||||
|
|
@ -51,19 +55,22 @@ export class TelegramBotService {
|
||||||
msg.chat.id,
|
msg.chat.id,
|
||||||
);
|
);
|
||||||
let helpMessage: string;
|
let helpMessage: string;
|
||||||
|
/* eslint-disable */
|
||||||
if (userMetaInfo) {
|
if (userMetaInfo) {
|
||||||
// eslint-disable-next-line prettier/prettier
|
const handlersMessages = this.handlers
|
||||||
|
.map((handler) => handler.getHelpMsg())
|
||||||
|
.join('\n');
|
||||||
helpMessage = [
|
helpMessage = [
|
||||||
`/current_issues - мои текущие задачи`,
|
handlersMessages,
|
||||||
`/help`
|
`/help`
|
||||||
].join('\n');
|
].join('\n');
|
||||||
} else {
|
} else {
|
||||||
// eslint-disable-next-line prettier/prettier
|
|
||||||
helpMessage = [
|
helpMessage = [
|
||||||
`/register <redmine_id> <redmine_token>`,
|
`/register <redmine_id> <redmine_token>`,
|
||||||
`/help`
|
`/help`,
|
||||||
].join('\n');
|
].join('\n');
|
||||||
}
|
}
|
||||||
|
/* eslint-enable */
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
`Sent help message for telegramChatId = ${msg.chat.id}, ` +
|
`Sent help message for telegramChatId = ${msg.chat.id}, ` +
|
||||||
`message = ${helpMessage}`,
|
`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