2022-12-28 10:03:11 +02:00
|
|
|
///
|
|
|
|
|
/// Copyright © 2016-2022 The Thingsboard Authors
|
|
|
|
|
///
|
|
|
|
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
/// you may not use this file except in compliance with the License.
|
|
|
|
|
/// You may obtain a copy of the License at
|
|
|
|
|
///
|
|
|
|
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
///
|
|
|
|
|
/// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
/// See the License for the specific language governing permissions and
|
|
|
|
|
/// limitations under the License.
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
import { NotificationId } from '@shared/models/id/notification-id';
|
|
|
|
|
import { NotificationRequestId } from '@shared/models/id/notification-request-id';
|
|
|
|
|
import { UserId } from '@shared/models/id/user-id';
|
|
|
|
|
import { DashboardId } from '@shared/models/id/dashboard-id';
|
|
|
|
|
import { BaseData } from '@shared/models/base-data';
|
|
|
|
|
import { TenantId } from '@shared/models/id/tenant-id';
|
|
|
|
|
import { NotificationTargetId } from '@shared/models/id/notification-target-id';
|
|
|
|
|
import { NotificationTemplateId } from '@shared/models/id/notification-template-id';
|
|
|
|
|
import { EntityId } from '@shared/models/id/entity-id';
|
|
|
|
|
import { NotificationRuleId } from '@shared/models/id/notification-rule-id';
|
|
|
|
|
|
|
|
|
|
export interface Notification {
|
|
|
|
|
readonly id: NotificationId;
|
|
|
|
|
readonly requestId: NotificationRequestId;
|
|
|
|
|
readonly recipientId: UserId;
|
2023-01-17 18:26:25 +02:00
|
|
|
readonly type: NotificationType;
|
|
|
|
|
readonly subject: string;
|
2022-12-28 10:03:11 +02:00
|
|
|
readonly text: string;
|
|
|
|
|
readonly info: NotificationInfo;
|
|
|
|
|
readonly originatorType: NotificationOriginatorType;
|
|
|
|
|
readonly status: NotificationStatus;
|
2023-01-20 18:08:30 +02:00
|
|
|
readonly createdTime: number;
|
|
|
|
|
readonly additionalConfig?: PushDeliveryMethodAdditionalConfig;
|
2022-12-28 10:03:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface NotificationInfo {
|
|
|
|
|
description: string;
|
|
|
|
|
dashboardId: DashboardId;
|
|
|
|
|
originatorType: NotificationOriginatorType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface NotificationRequest extends Omit<BaseData<NotificationRequestId>, 'label'> {
|
|
|
|
|
tenantId?: TenantId;
|
2023-01-17 18:26:25 +02:00
|
|
|
targets: Array<string>;
|
2022-12-28 10:03:11 +02:00
|
|
|
templateId: NotificationTemplateId;
|
|
|
|
|
info?: NotificationInfo;
|
|
|
|
|
deliveryMethods: Array<NotificationDeliveryMethod>;
|
|
|
|
|
originatorEntityId: EntityId;
|
|
|
|
|
originatorType: NotificationOriginatorType;
|
|
|
|
|
status: NotificationRequestStatus;
|
|
|
|
|
stats: NotificationRequestStats;
|
|
|
|
|
additionalConfig: NotificationRequestConfig;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-18 13:03:37 +02:00
|
|
|
export interface NotificationRequestInfo extends NotificationRequest {
|
|
|
|
|
templateName: string;
|
|
|
|
|
deliveryMethods: NotificationDeliveryMethod[];
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-17 18:26:25 +02:00
|
|
|
export interface NotificationRequestPreview {
|
|
|
|
|
totalRecipientsCount: number;
|
|
|
|
|
recipientsCountByTarget: { [key in string]: number };
|
|
|
|
|
processedTemplates: { [key in NotificationDeliveryMethod]: DeliveryMethodNotificationTemplate };
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-28 10:03:11 +02:00
|
|
|
export interface NotificationRequestStats {
|
|
|
|
|
sent: Map<NotificationDeliveryMethod, any>;
|
|
|
|
|
errors: Map<NotificationDeliveryMethod, Map<string, string>>;
|
|
|
|
|
processedRecipients: Map<NotificationDeliveryMethod, Set<UserId>>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface NotificationRequestConfig {
|
|
|
|
|
sendingDelayInSec: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface NotificationSettings {
|
2023-01-26 13:36:55 +02:00
|
|
|
deliveryMethodsConfigs: { [key in NotificationDeliveryMethod]: NotificationDeliveryMethodConfig };
|
2022-12-28 10:03:11 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-26 13:36:55 +02:00
|
|
|
export interface NotificationDeliveryMethodConfig extends Partial<SlackNotificationDeliveryMethodConfig>{
|
2022-12-28 10:03:11 +02:00
|
|
|
enabled: boolean;
|
|
|
|
|
method: NotificationDeliveryMethod;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-26 13:36:55 +02:00
|
|
|
interface SlackNotificationDeliveryMethodConfig {
|
|
|
|
|
botToken: string;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-28 10:03:11 +02:00
|
|
|
export interface SlackConversation {
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface NotificationRule extends Omit<BaseData<NotificationRuleId>, 'label'>{
|
|
|
|
|
tenantId: TenantId;
|
|
|
|
|
templateId: NotificationTemplateId;
|
|
|
|
|
deliveryMethods: Array<NotificationDeliveryMethod>;
|
|
|
|
|
configuration: NotificationRuleConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface NotificationRuleConfig {
|
|
|
|
|
initialNotificationTargetId: NotificationTargetId;
|
|
|
|
|
escalationConfig: NotificationEscalationConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface NotificationEscalationConfig {
|
|
|
|
|
escalations: Array<NonConfirmedNotificationEscalation>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface NonConfirmedNotificationEscalation {
|
|
|
|
|
delayInSec: number;
|
|
|
|
|
notificationTargetId: NotificationTargetId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface NotificationTarget extends Omit<BaseData<NotificationTargetId>, 'label'>{
|
|
|
|
|
tenantId: TenantId;
|
2023-01-31 13:35:16 +02:00
|
|
|
type: NotificationTargetType;
|
2022-12-28 10:03:11 +02:00
|
|
|
configuration: NotificationTargetConfig;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-31 13:35:16 +02:00
|
|
|
export interface NotificationTargetConfig extends Partial<PlatformUsersNotificationTargetConfig & SlackNotificationTargetConfig> {
|
|
|
|
|
description?: string;
|
|
|
|
|
type: NotificationTargetType;
|
|
|
|
|
}
|
|
|
|
|
export interface PlatformUsersNotificationTargetConfig {
|
|
|
|
|
usersFilter: UsersFilter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface UsersFilter extends
|
2023-01-06 19:28:12 +02:00
|
|
|
Partial<UserListNotificationTargetConfig & CustomerUsersNotificationTargetConfig>{
|
2022-12-28 10:03:11 +02:00
|
|
|
type: NotificationTargetConfigType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface UserListNotificationTargetConfig {
|
|
|
|
|
usersIds: Array<string>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface CustomerUsersNotificationTargetConfig {
|
|
|
|
|
customerId: string;
|
|
|
|
|
getCustomerIdFromOriginatorEntity: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-31 13:35:16 +02:00
|
|
|
export interface SlackNotificationTargetConfig {
|
2023-01-31 17:06:55 +02:00
|
|
|
conversationType: SlackChanelType;
|
|
|
|
|
conversation: SlackConversation;
|
2023-01-31 13:35:16 +02:00
|
|
|
}
|
|
|
|
|
export enum NotificationTargetType {
|
|
|
|
|
PLATFORM_USERS = 'PLATFORM_USERS',
|
|
|
|
|
SLACK = 'SLACK'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const NotificationTargetTypeTranslationMap = new Map<NotificationTargetType, string>([
|
|
|
|
|
[NotificationTargetType.PLATFORM_USERS, 'notification.platform-users'],
|
|
|
|
|
[NotificationTargetType.SLACK, 'notification.slack']
|
|
|
|
|
]);
|
|
|
|
|
|
2022-12-28 10:03:11 +02:00
|
|
|
export interface NotificationTemplate extends Omit<BaseData<NotificationTemplateId>, 'label'>{
|
|
|
|
|
tenantId: TenantId;
|
2023-01-17 18:26:25 +02:00
|
|
|
notificationType: NotificationType;
|
2022-12-28 10:03:11 +02:00
|
|
|
configuration: NotificationTemplateConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface NotificationTemplateConfig {
|
|
|
|
|
defaultTextTemplate: string;
|
2023-01-12 18:11:37 +02:00
|
|
|
notificationSubject: string;
|
|
|
|
|
deliveryMethodsTemplates: {
|
|
|
|
|
[key in NotificationDeliveryMethod]: DeliveryMethodNotificationTemplate
|
|
|
|
|
};
|
2022-12-28 10:03:11 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-12 18:11:37 +02:00
|
|
|
export interface DeliveryMethodNotificationTemplate extends
|
2023-01-12 12:38:03 +02:00
|
|
|
Partial<PushDeliveryMethodNotificationTemplate & EmailDeliveryMethodNotificationTemplate & SlackDeliveryMethodNotificationTemplate>{
|
|
|
|
|
body?: string;
|
2023-01-12 18:11:37 +02:00
|
|
|
enabled: boolean;
|
2022-12-28 10:03:11 +02:00
|
|
|
method: NotificationDeliveryMethod;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 12:38:03 +02:00
|
|
|
interface PushDeliveryMethodNotificationTemplate {
|
|
|
|
|
subject?: string;
|
2023-01-20 18:08:30 +02:00
|
|
|
additionalConfig: PushDeliveryMethodAdditionalConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface PushDeliveryMethodAdditionalConfig {
|
|
|
|
|
icon: {
|
|
|
|
|
enabled: boolean;
|
|
|
|
|
icon: string;
|
|
|
|
|
color: string;
|
|
|
|
|
};
|
|
|
|
|
actionButtonConfig: {
|
|
|
|
|
enabled: boolean;
|
|
|
|
|
text: string;
|
|
|
|
|
color: string;
|
|
|
|
|
link: string;
|
|
|
|
|
};
|
2023-01-12 12:38:03 +02:00
|
|
|
}
|
|
|
|
|
|
2022-12-28 10:03:11 +02:00
|
|
|
interface EmailDeliveryMethodNotificationTemplate {
|
|
|
|
|
subject: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface SlackDeliveryMethodNotificationTemplate {
|
|
|
|
|
conversationType: SlackChanelType;
|
|
|
|
|
conversationId: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export enum NotificationOriginatorType {
|
|
|
|
|
ADMIN = 'ADMIN',
|
|
|
|
|
ALARM = 'ALARM',
|
|
|
|
|
RULE_NODE = 'RULE_NODE'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export enum NotificationStatus {
|
|
|
|
|
SENT = 'SENT',
|
|
|
|
|
READ = 'READ'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export enum NotificationDeliveryMethod {
|
2023-01-12 12:38:03 +02:00
|
|
|
PUSH = 'PUSH',
|
2022-12-28 10:03:11 +02:00
|
|
|
SMS = 'SMS',
|
|
|
|
|
EMAIL = 'EMAIL',
|
|
|
|
|
SLACK = 'SLACK'
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-17 18:26:25 +02:00
|
|
|
export const NotificationDeliveryMethodTranslateMap = new Map<NotificationDeliveryMethod, string>([
|
|
|
|
|
[NotificationDeliveryMethod.PUSH, 'notification.delivery-method-type.push'],
|
|
|
|
|
[NotificationDeliveryMethod.SMS, 'notification.delivery-method-type.sms'],
|
|
|
|
|
[NotificationDeliveryMethod.EMAIL, 'notification.delivery-method-type.email'],
|
|
|
|
|
[NotificationDeliveryMethod.SLACK, 'notification.delivery-method-type.slack'],
|
|
|
|
|
]);
|
|
|
|
|
|
2022-12-28 10:03:11 +02:00
|
|
|
export enum NotificationRequestStatus {
|
2023-01-17 18:26:25 +02:00
|
|
|
PROCESSING = 'PROCESSING',
|
|
|
|
|
SCHEDULED = 'SCHEDULED',
|
|
|
|
|
SENT = 'SENT'
|
2022-12-28 10:03:11 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-17 18:26:25 +02:00
|
|
|
export const NotificationRequestStatusTranslateMap = new Map<NotificationRequestStatus, string>([
|
2023-01-31 17:06:55 +02:00
|
|
|
[NotificationRequestStatus.PROCESSING, 'notification.request-status.processing'],
|
|
|
|
|
[NotificationRequestStatus.SCHEDULED, 'notification.request-status.scheduled'],
|
|
|
|
|
[NotificationRequestStatus.SENT, 'notification.request-status.sent']
|
2023-01-17 18:26:25 +02:00
|
|
|
]);
|
|
|
|
|
|
2022-12-28 10:03:11 +02:00
|
|
|
export enum SlackChanelType {
|
2023-01-12 18:11:37 +02:00
|
|
|
DIRECT= 'DIRECT',
|
2022-12-28 10:03:11 +02:00
|
|
|
PUBLIC_CHANNEL = 'PUBLIC_CHANNEL',
|
|
|
|
|
PRIVATE_CHANNEL = 'PRIVATE_CHANNEL'
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-26 13:36:55 +02:00
|
|
|
export const SlackChanelTypesTranslateMap = new Map<SlackChanelType, string>([
|
|
|
|
|
[SlackChanelType.DIRECT, 'notification.slack-chanel-types.direct'],
|
|
|
|
|
[SlackChanelType.PUBLIC_CHANNEL, 'notification.slack-chanel-types.public-channel'],
|
|
|
|
|
[SlackChanelType.PRIVATE_CHANNEL, 'notification.slack-chanel-types.private-channel']
|
|
|
|
|
]);
|
|
|
|
|
|
2022-12-28 10:03:11 +02:00
|
|
|
export enum NotificationTargetConfigType {
|
|
|
|
|
USER_LIST = 'USER_LIST',
|
|
|
|
|
CUSTOMER_USERS = 'CUSTOMER_USERS',
|
|
|
|
|
ALL_USERS = 'ALL_USERS'
|
|
|
|
|
}
|
2023-01-06 19:28:12 +02:00
|
|
|
|
|
|
|
|
export const NotificationTargetConfigTypeTranslateMap = new Map<NotificationTargetConfigType, string>([
|
|
|
|
|
[NotificationTargetConfigType.ALL_USERS, 'notification.target-type.all-users'],
|
|
|
|
|
[NotificationTargetConfigType.USER_LIST, 'notification.target-type.user-list'],
|
|
|
|
|
[NotificationTargetConfigType.CUSTOMER_USERS, 'notification.target-type.customer-users'],
|
|
|
|
|
]);
|
2023-01-12 12:38:03 +02:00
|
|
|
|
2023-01-17 18:26:25 +02:00
|
|
|
export enum NotificationType {
|
2023-01-12 18:11:37 +02:00
|
|
|
GENERAL = 'GENERAL',
|
2023-01-12 12:38:03 +02:00
|
|
|
ALARM = 'ALARM'
|
|
|
|
|
}
|
2023-01-12 18:11:37 +02:00
|
|
|
|
|
|
|
|
interface NotificationTemplateTypeTranslate {
|
|
|
|
|
name: string;
|
|
|
|
|
hint?: string;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-17 18:26:25 +02:00
|
|
|
export const NotificationTemplateTypeTranslateMap = new Map<NotificationType, NotificationTemplateTypeTranslate>([
|
|
|
|
|
[NotificationType.GENERAL,
|
2023-01-12 18:11:37 +02:00
|
|
|
{
|
|
|
|
|
name: 'notification.template-type.general',
|
|
|
|
|
hint: 'hint'
|
|
|
|
|
}
|
|
|
|
|
],
|
2023-01-17 18:26:25 +02:00
|
|
|
[NotificationType.ALARM,
|
2023-01-12 18:11:37 +02:00
|
|
|
{
|
|
|
|
|
name: 'notification.template-type.alarm',
|
|
|
|
|
hint: 'hint'
|
|
|
|
|
}]
|
|
|
|
|
]);
|