Отправка уведомлений об изменениях статусов
This commit is contained in:
parent
7bc70db364
commit
351a754098
2 changed files with 34 additions and 3 deletions
|
|
@ -23,6 +23,7 @@ import { UserMetaInfoService } from './user-meta-info/user-meta-info.service';
|
|||
import { UserMetaInfo } from './couchdb-datasources/user-meta-info';
|
||||
import { PersonalNotificationAdapterService } from './notifications/adapters/personal-notification.adapter/personal-notification.adapter.service';
|
||||
import { PublicUrlAdapterService } from './notifications/adapters/public-url.adapter.service';
|
||||
import { StatusChangeAdapterService } from './notifications/adapters/status-change.adapter.service';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
|
@ -49,6 +50,7 @@ import { PublicUrlAdapterService } from './notifications/adapters/public-url.ada
|
|||
UserMetaInfo,
|
||||
PersonalNotificationAdapterService,
|
||||
PublicUrlAdapterService,
|
||||
StatusChangeAdapterService,
|
||||
],
|
||||
})
|
||||
export class AppModule implements OnModuleInit {
|
||||
|
|
@ -65,6 +67,7 @@ export class AppModule implements OnModuleInit {
|
|||
private changesCacheWriterService: ChangesCacheWriterService,
|
||||
private telegramBotService: TelegramBotService,
|
||||
private personalNotificationAdapterService: PersonalNotificationAdapterService,
|
||||
private statusChangeAdapterService: StatusChangeAdapterService,
|
||||
) {}
|
||||
|
||||
onModuleInit() {
|
||||
|
|
@ -89,13 +92,19 @@ export class AppModule implements OnModuleInit {
|
|||
this.personalNotificationAdapterService.send(resp);
|
||||
});
|
||||
this.statusChangeNotificationsService.$changes.subscribe((change) => {
|
||||
const messages = change.messages
|
||||
.map((m) => m.change_message)
|
||||
.filter((m) => !!m);
|
||||
const notifications = change.messages
|
||||
.map((m) => m.notification_message)
|
||||
.filter((m) => !!m);
|
||||
this.logger.log(
|
||||
`Get status changes messages for ` +
|
||||
`issue_id = ${change.issue_id}, ` +
|
||||
`messages = ${JSON.stringify(
|
||||
change.messages.map((m) => m.change_message).filter((m) => !!m),
|
||||
)}`,
|
||||
`messages = ${JSON.stringify(messages)}, ` +
|
||||
`notifications = ${JSON.stringify(notifications)}`,
|
||||
);
|
||||
this.statusChangeAdapterService.send(change);
|
||||
});
|
||||
|
||||
this.redmineIssuesCacheWriterService.subject
|
||||
|
|
|
|||
22
src/notifications/adapters/status-change.adapter.service.ts
Normal file
22
src/notifications/adapters/status-change.adapter.service.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { Change } from 'src/models/change.model';
|
||||
import { TelegramBotService } from 'src/telegram-bot/telegram-bot.service';
|
||||
|
||||
@Injectable()
|
||||
export class StatusChangeAdapterService {
|
||||
constructor(private telegramBotService: TelegramBotService) {}
|
||||
|
||||
async send(change: Change): Promise<boolean[]> {
|
||||
const promises = change.messages.map((m) => {
|
||||
if (!m || !m.recipient || !m.recipient.id || !m.notification_message) {
|
||||
return true;
|
||||
}
|
||||
return this.telegramBotService.sendMessageByRedmineId(
|
||||
m.recipient.id,
|
||||
m.notification_message,
|
||||
{ parse_mode: 'HTML' },
|
||||
);
|
||||
});
|
||||
return await Promise.all(promises);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue