@oneuptime/common 10.0.66 → 10.0.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Models/AnalyticsModels/AuditLog.ts +370 -0
- package/Models/DatabaseModels/Alert.ts +2 -0
- package/Models/DatabaseModels/ApiKey.ts +2 -0
- package/Models/DatabaseModels/DatabaseBaseModel/DatabaseBaseModel.ts +3 -0
- package/Models/DatabaseModels/GlobalConfig.ts +56 -0
- package/Models/DatabaseModels/Incident.ts +2 -0
- package/Models/DatabaseModels/Index.ts +4 -0
- package/Models/DatabaseModels/Label.ts +2 -0
- package/Models/DatabaseModels/Monitor.ts +2 -0
- package/Models/DatabaseModels/OnCallDutyPolicy.ts +2 -0
- package/Models/DatabaseModels/Project.ts +110 -0
- package/Models/DatabaseModels/ScheduledMaintenance.ts +2 -0
- package/Models/DatabaseModels/StatusPage.ts +2 -0
- package/Models/DatabaseModels/Team.ts +2 -0
- package/Models/DatabaseModels/TelegramLog.ts +1025 -0
- package/Models/DatabaseModels/UserNotificationRule.ts +49 -0
- package/Models/DatabaseModels/UserNotificationSetting.ts +17 -0
- package/Models/DatabaseModels/UserOnCallLogTimeline.ts +48 -0
- package/Models/DatabaseModels/UserTelegram.ts +312 -0
- package/Server/API/UserTelegramAPI.ts +167 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1776761171349-MigrationName.ts +325 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1776801030808-MigrationName.ts +35 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +4 -0
- package/Server/Services/AuditLogService.ts +574 -0
- package/Server/Services/DatabaseService.ts +71 -0
- package/Server/Services/Index.ts +8 -0
- package/Server/Services/TelegramLogService.ts +15 -0
- package/Server/Services/TelegramService.ts +139 -0
- package/Server/Services/UserNotificationRuleService.ts +350 -1
- package/Server/Services/UserNotificationSettingService.ts +114 -0
- package/Server/Services/UserTelegramService.ts +140 -0
- package/Server/Utils/Monitor/MonitorResource.ts +29 -15
- package/Server/Utils/Monitor/MonitorTemplateUtil.ts +29 -16
- package/Tests/Types/Date.test.ts +158 -0
- package/Types/AnalyticsDatabase/AnalyticsTableName.ts +1 -0
- package/Types/AuditLog/AuditLogAction.ts +7 -0
- package/Types/BaseDatabase/EnableAuditLogOn.ts +5 -0
- package/Types/Database/EnableAuditLog.ts +18 -0
- package/Types/Date.ts +12 -3
- package/Types/Icon/IconProp.ts +1 -0
- package/Types/Permission.ts +24 -0
- package/Types/Telegram/TelegramMessage.ts +9 -0
- package/Types/TelegramStatus.ts +14 -0
- package/UI/Components/Icon/Icon.tsx +15 -0
- package/build/dist/Models/AnalyticsModels/AuditLog.js +337 -0
- package/build/dist/Models/AnalyticsModels/AuditLog.js.map +1 -0
- package/build/dist/Models/DatabaseModels/Alert.js +2 -0
- package/build/dist/Models/DatabaseModels/Alert.js.map +1 -1
- package/build/dist/Models/DatabaseModels/ApiKey.js +2 -0
- package/build/dist/Models/DatabaseModels/ApiKey.js.map +1 -1
- package/build/dist/Models/DatabaseModels/DatabaseBaseModel/DatabaseBaseModel.js.map +1 -1
- package/build/dist/Models/DatabaseModels/GlobalConfig.js +59 -0
- package/build/dist/Models/DatabaseModels/GlobalConfig.js.map +1 -1
- package/build/dist/Models/DatabaseModels/Incident.js +2 -0
- package/build/dist/Models/DatabaseModels/Incident.js.map +1 -1
- package/build/dist/Models/DatabaseModels/Index.js +4 -0
- package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
- package/build/dist/Models/DatabaseModels/Label.js +2 -0
- package/build/dist/Models/DatabaseModels/Label.js.map +1 -1
- package/build/dist/Models/DatabaseModels/Monitor.js +2 -0
- package/build/dist/Models/DatabaseModels/Monitor.js.map +1 -1
- package/build/dist/Models/DatabaseModels/OnCallDutyPolicy.js +2 -0
- package/build/dist/Models/DatabaseModels/OnCallDutyPolicy.js.map +1 -1
- package/build/dist/Models/DatabaseModels/Project.js +114 -0
- package/build/dist/Models/DatabaseModels/Project.js.map +1 -1
- package/build/dist/Models/DatabaseModels/ScheduledMaintenance.js +2 -0
- package/build/dist/Models/DatabaseModels/ScheduledMaintenance.js.map +1 -1
- package/build/dist/Models/DatabaseModels/StatusPage.js +2 -0
- package/build/dist/Models/DatabaseModels/StatusPage.js.map +1 -1
- package/build/dist/Models/DatabaseModels/Team.js +2 -0
- package/build/dist/Models/DatabaseModels/Team.js.map +1 -1
- package/build/dist/Models/DatabaseModels/TelegramLog.js +1056 -0
- package/build/dist/Models/DatabaseModels/TelegramLog.js.map +1 -0
- package/build/dist/Models/DatabaseModels/UserNotificationRule.js +49 -0
- package/build/dist/Models/DatabaseModels/UserNotificationRule.js.map +1 -1
- package/build/dist/Models/DatabaseModels/UserNotificationSetting.js +19 -0
- package/build/dist/Models/DatabaseModels/UserNotificationSetting.js.map +1 -1
- package/build/dist/Models/DatabaseModels/UserOnCallLogTimeline.js +48 -0
- package/build/dist/Models/DatabaseModels/UserOnCallLogTimeline.js.map +1 -1
- package/build/dist/Models/DatabaseModels/UserTelegram.js +331 -0
- package/build/dist/Models/DatabaseModels/UserTelegram.js.map +1 -0
- package/build/dist/Server/API/UserTelegramAPI.js +99 -0
- package/build/dist/Server/API/UserTelegramAPI.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1776761171349-MigrationName.js +116 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1776761171349-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1776801030808-MigrationName.js +18 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1776801030808-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +4 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
- package/build/dist/Server/Services/AuditLogService.js +402 -0
- package/build/dist/Server/Services/AuditLogService.js.map +1 -0
- package/build/dist/Server/Services/DatabaseService.js +68 -8
- package/build/dist/Server/Services/DatabaseService.js.map +1 -1
- package/build/dist/Server/Services/Index.js +8 -0
- package/build/dist/Server/Services/Index.js.map +1 -1
- package/build/dist/Server/Services/TelegramLogService.js +13 -0
- package/build/dist/Server/Services/TelegramLogService.js.map +1 -0
- package/build/dist/Server/Services/TelegramService.js +100 -0
- package/build/dist/Server/Services/TelegramService.js.map +1 -0
- package/build/dist/Server/Services/UserNotificationRuleService.js +272 -21
- package/build/dist/Server/Services/UserNotificationRuleService.js.map +1 -1
- package/build/dist/Server/Services/UserNotificationSettingService.js +94 -0
- package/build/dist/Server/Services/UserNotificationSettingService.js.map +1 -1
- package/build/dist/Server/Services/UserTelegramService.js +133 -0
- package/build/dist/Server/Services/UserTelegramService.js.map +1 -0
- package/build/dist/Server/Utils/Monitor/MonitorResource.js +25 -12
- package/build/dist/Server/Utils/Monitor/MonitorResource.js.map +1 -1
- package/build/dist/Server/Utils/Monitor/MonitorTemplateUtil.js +24 -12
- package/build/dist/Server/Utils/Monitor/MonitorTemplateUtil.js.map +1 -1
- package/build/dist/Tests/Types/Date.test.js +96 -0
- package/build/dist/Tests/Types/Date.test.js.map +1 -1
- package/build/dist/Types/AnalyticsDatabase/AnalyticsTableName.js +1 -0
- package/build/dist/Types/AnalyticsDatabase/AnalyticsTableName.js.map +1 -1
- package/build/dist/Types/AuditLog/AuditLogAction.js +8 -0
- package/build/dist/Types/AuditLog/AuditLogAction.js.map +1 -0
- package/build/dist/Types/BaseDatabase/EnableAuditLogOn.js +2 -0
- package/build/dist/Types/BaseDatabase/EnableAuditLogOn.js.map +1 -0
- package/build/dist/Types/Database/EnableAuditLog.js +15 -0
- package/build/dist/Types/Database/EnableAuditLog.js.map +1 -0
- package/build/dist/Types/Date.js +9 -3
- package/build/dist/Types/Date.js.map +1 -1
- package/build/dist/Types/Icon/IconProp.js +1 -0
- package/build/dist/Types/Icon/IconProp.js.map +1 -1
- package/build/dist/Types/Permission.js +21 -0
- package/build/dist/Types/Permission.js.map +1 -1
- package/build/dist/Types/Telegram/TelegramMessage.js +2 -0
- package/build/dist/Types/Telegram/TelegramMessage.js.map +1 -0
- package/build/dist/Types/TelegramStatus.js +15 -0
- package/build/dist/Types/TelegramStatus.js.map +1 -0
- package/build/dist/UI/Components/Icon/Icon.js +5 -0
- package/build/dist/UI/Components/Icon/Icon.js.map +1 -1
- package/package.json +2 -2
package/Server/Services/Index.ts
CHANGED
|
@@ -36,6 +36,7 @@ import LabelService from "./LabelService";
|
|
|
36
36
|
import KubernetesClusterService from "./KubernetesClusterService";
|
|
37
37
|
import DockerHostService from "./DockerHostService";
|
|
38
38
|
import LlmProviderService from "./LlmProviderService";
|
|
39
|
+
import AuditLogService from "./AuditLogService";
|
|
39
40
|
import LogService from "./LogService";
|
|
40
41
|
import MailService from "./MailService";
|
|
41
42
|
import MetricService from "./MetricService";
|
|
@@ -104,7 +105,9 @@ import ShortLinkService from "./ShortLinkService";
|
|
|
104
105
|
// SMS Log Service
|
|
105
106
|
import SmsLogService from "./SmsLogService";
|
|
106
107
|
import WhatsAppLogService from "./WhatsAppLogService";
|
|
108
|
+
import TelegramLogService from "./TelegramLogService";
|
|
107
109
|
import SmsService from "./SmsService";
|
|
110
|
+
import TelegramService from "./TelegramService";
|
|
108
111
|
import SpanService from "./SpanService";
|
|
109
112
|
import StatusPageAnnouncementService from "./StatusPageAnnouncementService";
|
|
110
113
|
import StatusPageAnnouncementTemplateService from "./StatusPageAnnouncementTemplateService";
|
|
@@ -146,6 +149,7 @@ import UserWebAuthnService from "./UserWebAuthnService";
|
|
|
146
149
|
import UserSmsService from "./UserSmsService";
|
|
147
150
|
import UserIncomingCallNumberService from "./UserIncomingCallNumberService";
|
|
148
151
|
import UserWhatsAppService from "./UserWhatsAppService";
|
|
152
|
+
import UserTelegramService from "./UserTelegramService";
|
|
149
153
|
import WorkflowLogService from "./WorkflowLogService";
|
|
150
154
|
// Workflows.
|
|
151
155
|
import WorkflowService from "./WorkflowService";
|
|
@@ -307,7 +311,9 @@ const services: Array<BaseService> = [
|
|
|
307
311
|
ShortLinkService,
|
|
308
312
|
SmsLogService,
|
|
309
313
|
WhatsAppLogService,
|
|
314
|
+
TelegramLogService,
|
|
310
315
|
SmsService,
|
|
316
|
+
TelegramService,
|
|
311
317
|
|
|
312
318
|
StatusPageAnnouncementService,
|
|
313
319
|
StatusPageAnnouncementTemplateService,
|
|
@@ -346,6 +352,7 @@ const services: Array<BaseService> = [
|
|
|
346
352
|
UserSmsService,
|
|
347
353
|
UserIncomingCallNumberService,
|
|
348
354
|
UserWhatsAppService,
|
|
355
|
+
UserTelegramService,
|
|
349
356
|
UserTotpAuthService,
|
|
350
357
|
UserWebAuthnService,
|
|
351
358
|
|
|
@@ -441,6 +448,7 @@ export const AnalyticsServices: Array<
|
|
|
441
448
|
MonitorLogService,
|
|
442
449
|
ProfileService,
|
|
443
450
|
ProfileSampleService,
|
|
451
|
+
AuditLogService,
|
|
444
452
|
];
|
|
445
453
|
|
|
446
454
|
export default services;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IsBillingEnabled } from "../EnvironmentConfig";
|
|
2
|
+
import DatabaseService from "./DatabaseService";
|
|
3
|
+
import Model from "../../Models/DatabaseModels/TelegramLog";
|
|
4
|
+
|
|
5
|
+
export class Service extends DatabaseService<Model> {
|
|
6
|
+
public constructor() {
|
|
7
|
+
super(Model);
|
|
8
|
+
|
|
9
|
+
if (IsBillingEnabled) {
|
|
10
|
+
this.hardDeleteItemsOlderThanInDays("createdAt", 3);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default new Service();
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { AppApiHostname } from "../EnvironmentConfig";
|
|
2
|
+
import ClusterKeyAuthorization from "../Middleware/ClusterKeyAuthorization";
|
|
3
|
+
import BaseService from "./BaseService";
|
|
4
|
+
import EmptyResponseData from "../../Types/API/EmptyResponse";
|
|
5
|
+
import HTTPResponse from "../../Types/API/HTTPResponse";
|
|
6
|
+
import Protocol from "../../Types/API/Protocol";
|
|
7
|
+
import Route from "../../Types/API/Route";
|
|
8
|
+
import URL from "../../Types/API/URL";
|
|
9
|
+
import { JSONObject } from "../../Types/JSON";
|
|
10
|
+
import ObjectID from "../../Types/ObjectID";
|
|
11
|
+
import TelegramMessage from "../../Types/Telegram/TelegramMessage";
|
|
12
|
+
import API from "../../Utils/API";
|
|
13
|
+
import CaptureSpan from "../Utils/Telemetry/CaptureSpan";
|
|
14
|
+
|
|
15
|
+
export class TelegramService extends BaseService {
|
|
16
|
+
public constructor() {
|
|
17
|
+
super();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@CaptureSpan()
|
|
21
|
+
public async sendTelegramMessage(
|
|
22
|
+
message: TelegramMessage,
|
|
23
|
+
options: {
|
|
24
|
+
projectId?: ObjectID | undefined;
|
|
25
|
+
isSensitive?: boolean | undefined;
|
|
26
|
+
userOnCallLogTimelineId?: ObjectID | undefined;
|
|
27
|
+
incidentId?: ObjectID | undefined;
|
|
28
|
+
alertId?: ObjectID | undefined;
|
|
29
|
+
alertEpisodeId?: ObjectID | undefined;
|
|
30
|
+
incidentEpisodeId?: ObjectID | undefined;
|
|
31
|
+
monitorId?: ObjectID | undefined;
|
|
32
|
+
scheduledMaintenanceId?: ObjectID | undefined;
|
|
33
|
+
statusPageId?: ObjectID | undefined;
|
|
34
|
+
statusPageAnnouncementId?: ObjectID | undefined;
|
|
35
|
+
userId?: ObjectID | undefined;
|
|
36
|
+
onCallPolicyId?: ObjectID | undefined;
|
|
37
|
+
onCallPolicyEscalationRuleId?: ObjectID | undefined;
|
|
38
|
+
onCallDutyPolicyExecutionLogTimelineId?: ObjectID | undefined;
|
|
39
|
+
onCallScheduleId?: ObjectID | undefined;
|
|
40
|
+
teamId?: ObjectID | undefined;
|
|
41
|
+
} = {},
|
|
42
|
+
): Promise<HTTPResponse<EmptyResponseData>> {
|
|
43
|
+
const body: JSONObject = {
|
|
44
|
+
to: message.to,
|
|
45
|
+
body: message.body,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
if (message.parseMode) {
|
|
49
|
+
body["parseMode"] = message.parseMode;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (message.disableWebPagePreview !== undefined) {
|
|
53
|
+
body["disableWebPagePreview"] = message.disableWebPagePreview;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (options.projectId) {
|
|
57
|
+
body["projectId"] = options.projectId.toString();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (options.isSensitive !== undefined) {
|
|
61
|
+
body["isSensitive"] = options.isSensitive;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (options.userOnCallLogTimelineId) {
|
|
65
|
+
body["userOnCallLogTimelineId"] =
|
|
66
|
+
options.userOnCallLogTimelineId.toString();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (options.incidentId) {
|
|
70
|
+
body["incidentId"] = options.incidentId.toString();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (options.alertId) {
|
|
74
|
+
body["alertId"] = options.alertId.toString();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (options.alertEpisodeId) {
|
|
78
|
+
body["alertEpisodeId"] = options.alertEpisodeId.toString();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (options.monitorId) {
|
|
82
|
+
body["monitorId"] = options.monitorId.toString();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (options.scheduledMaintenanceId) {
|
|
86
|
+
body["scheduledMaintenanceId"] =
|
|
87
|
+
options.scheduledMaintenanceId.toString();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (options.statusPageId) {
|
|
91
|
+
body["statusPageId"] = options.statusPageId.toString();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (options.statusPageAnnouncementId) {
|
|
95
|
+
body["statusPageAnnouncementId"] =
|
|
96
|
+
options.statusPageAnnouncementId.toString();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (options.userId) {
|
|
100
|
+
body["userId"] = options.userId.toString();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (options.onCallPolicyId) {
|
|
104
|
+
body["onCallPolicyId"] = options.onCallPolicyId.toString();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (options.onCallPolicyEscalationRuleId) {
|
|
108
|
+
body["onCallPolicyEscalationRuleId"] =
|
|
109
|
+
options.onCallPolicyEscalationRuleId.toString();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (options.onCallDutyPolicyExecutionLogTimelineId) {
|
|
113
|
+
body["onCallDutyPolicyExecutionLogTimelineId"] =
|
|
114
|
+
options.onCallDutyPolicyExecutionLogTimelineId.toString();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (options.onCallScheduleId) {
|
|
118
|
+
body["onCallScheduleId"] = options.onCallScheduleId.toString();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (options.teamId) {
|
|
122
|
+
body["teamId"] = options.teamId.toString();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return await API.post<EmptyResponseData>({
|
|
126
|
+
url: new URL(
|
|
127
|
+
Protocol.HTTP,
|
|
128
|
+
AppApiHostname,
|
|
129
|
+
new Route("/api/notification/telegram/send"),
|
|
130
|
+
),
|
|
131
|
+
data: body,
|
|
132
|
+
headers: {
|
|
133
|
+
...ClusterKeyAuthorization.getClusterKeyHeaders(),
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export default new TelegramService();
|
|
@@ -9,6 +9,7 @@ import IncidentSeverityService from "./IncidentSeverityService";
|
|
|
9
9
|
import MailService from "./MailService";
|
|
10
10
|
import ShortLinkService from "./ShortLinkService";
|
|
11
11
|
import SmsService from "./SmsService";
|
|
12
|
+
import TelegramService from "./TelegramService";
|
|
12
13
|
import WhatsAppService from "./WhatsAppService";
|
|
13
14
|
import UserEmailService from "./UserEmailService";
|
|
14
15
|
import UserOnCallLogService from "./UserOnCallLogService";
|
|
@@ -32,6 +33,7 @@ import ObjectID from "../../Types/ObjectID";
|
|
|
32
33
|
import PushDeviceType from "../../Types/PushNotification/PushDeviceType";
|
|
33
34
|
import Phone from "../../Types/Phone";
|
|
34
35
|
import SMS from "../../Types/SMS/SMS";
|
|
36
|
+
import TelegramMessage from "../../Types/Telegram/TelegramMessage";
|
|
35
37
|
import WhatsAppMessage from "../../Types/WhatsApp/WhatsAppMessage";
|
|
36
38
|
import {
|
|
37
39
|
renderWhatsAppTemplate,
|
|
@@ -74,6 +76,7 @@ export interface NotificationMethodDescriptor {
|
|
|
74
76
|
userSmsId?: ObjectID;
|
|
75
77
|
userCallId?: ObjectID;
|
|
76
78
|
userWhatsAppId?: ObjectID;
|
|
79
|
+
userTelegramId?: ObjectID;
|
|
77
80
|
userPushId?: ObjectID;
|
|
78
81
|
}
|
|
79
82
|
|
|
@@ -165,6 +168,11 @@ export class Service extends DatabaseService<Model> {
|
|
|
165
168
|
phone: true,
|
|
166
169
|
isVerified: true,
|
|
167
170
|
},
|
|
171
|
+
userTelegram: {
|
|
172
|
+
telegramChatId: true,
|
|
173
|
+
telegramUserHandle: true,
|
|
174
|
+
isVerified: true,
|
|
175
|
+
},
|
|
168
176
|
userEmail: {
|
|
169
177
|
email: true,
|
|
170
178
|
isVerified: true,
|
|
@@ -896,6 +904,184 @@ export class Service extends DatabaseService<Model> {
|
|
|
896
904
|
});
|
|
897
905
|
}
|
|
898
906
|
|
|
907
|
+
// send Telegram.
|
|
908
|
+
if (
|
|
909
|
+
notificationRuleItem.userTelegram?.telegramChatId &&
|
|
910
|
+
notificationRuleItem.userTelegram?.isVerified
|
|
911
|
+
) {
|
|
912
|
+
if (
|
|
913
|
+
options.userNotificationEventType ===
|
|
914
|
+
UserNotificationEventType.AlertCreated &&
|
|
915
|
+
alert
|
|
916
|
+
) {
|
|
917
|
+
logTimelineItem.status = UserNotificationStatus.Sending;
|
|
918
|
+
logTimelineItem.statusMessage = `Sending Telegram message.`;
|
|
919
|
+
logTimelineItem.userTelegramId = notificationRuleItem.userTelegram.id!;
|
|
920
|
+
|
|
921
|
+
const updatedLog: UserOnCallLogTimeline =
|
|
922
|
+
await UserOnCallLogTimelineService.create({
|
|
923
|
+
data: logTimelineItem,
|
|
924
|
+
props: {
|
|
925
|
+
isRoot: true,
|
|
926
|
+
},
|
|
927
|
+
});
|
|
928
|
+
|
|
929
|
+
const telegramMessage: TelegramMessage = {
|
|
930
|
+
to: notificationRuleItem.userTelegram.telegramChatId,
|
|
931
|
+
body: await this.generateTelegramBodyForAlertCreated(
|
|
932
|
+
alert,
|
|
933
|
+
updatedLog.id!,
|
|
934
|
+
),
|
|
935
|
+
parseMode: "HTML",
|
|
936
|
+
disableWebPagePreview: true,
|
|
937
|
+
};
|
|
938
|
+
|
|
939
|
+
TelegramService.sendTelegramMessage(telegramMessage, {
|
|
940
|
+
projectId: alert.projectId,
|
|
941
|
+
alertId: alert.id!,
|
|
942
|
+
userOnCallLogTimelineId: updatedLog.id!,
|
|
943
|
+
userId: notificationRuleItem.userId!,
|
|
944
|
+
onCallPolicyId: options.onCallPolicyId,
|
|
945
|
+
onCallPolicyEscalationRuleId: options.onCallPolicyEscalationRuleId,
|
|
946
|
+
teamId: options.userBelongsToTeamId,
|
|
947
|
+
onCallDutyPolicyExecutionLogTimelineId:
|
|
948
|
+
options.onCallDutyPolicyExecutionLogTimelineId,
|
|
949
|
+
onCallScheduleId: options.onCallScheduleId,
|
|
950
|
+
}).catch(async (err: Error) => {
|
|
951
|
+
await UserOnCallLogTimelineService.updateOneById({
|
|
952
|
+
id: updatedLog.id!,
|
|
953
|
+
data: {
|
|
954
|
+
status: UserNotificationStatus.Error,
|
|
955
|
+
statusMessage: err.message || "Error sending Telegram message.",
|
|
956
|
+
},
|
|
957
|
+
props: {
|
|
958
|
+
isRoot: true,
|
|
959
|
+
},
|
|
960
|
+
});
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
if (
|
|
965
|
+
options.userNotificationEventType ===
|
|
966
|
+
UserNotificationEventType.IncidentCreated &&
|
|
967
|
+
incident
|
|
968
|
+
) {
|
|
969
|
+
logTimelineItem.status = UserNotificationStatus.Sending;
|
|
970
|
+
logTimelineItem.statusMessage = `Sending Telegram message.`;
|
|
971
|
+
logTimelineItem.userTelegramId = notificationRuleItem.userTelegram.id!;
|
|
972
|
+
|
|
973
|
+
const updatedLog: UserOnCallLogTimeline =
|
|
974
|
+
await UserOnCallLogTimelineService.create({
|
|
975
|
+
data: logTimelineItem,
|
|
976
|
+
props: {
|
|
977
|
+
isRoot: true,
|
|
978
|
+
},
|
|
979
|
+
});
|
|
980
|
+
|
|
981
|
+
const telegramMessage: TelegramMessage = {
|
|
982
|
+
to: notificationRuleItem.userTelegram.telegramChatId,
|
|
983
|
+
body: await this.generateTelegramBodyForIncidentCreated(
|
|
984
|
+
incident,
|
|
985
|
+
updatedLog.id!,
|
|
986
|
+
),
|
|
987
|
+
parseMode: "HTML",
|
|
988
|
+
disableWebPagePreview: true,
|
|
989
|
+
};
|
|
990
|
+
|
|
991
|
+
TelegramService.sendTelegramMessage(telegramMessage, {
|
|
992
|
+
projectId: incident.projectId,
|
|
993
|
+
incidentId: incident.id!,
|
|
994
|
+
userOnCallLogTimelineId: updatedLog.id!,
|
|
995
|
+
userId: notificationRuleItem.userId!,
|
|
996
|
+
onCallPolicyId: options.onCallPolicyId,
|
|
997
|
+
onCallPolicyEscalationRuleId: options.onCallPolicyEscalationRuleId,
|
|
998
|
+
teamId: options.userBelongsToTeamId,
|
|
999
|
+
onCallDutyPolicyExecutionLogTimelineId:
|
|
1000
|
+
options.onCallDutyPolicyExecutionLogTimelineId,
|
|
1001
|
+
onCallScheduleId: options.onCallScheduleId,
|
|
1002
|
+
}).catch(async (err: Error) => {
|
|
1003
|
+
await UserOnCallLogTimelineService.updateOneById({
|
|
1004
|
+
id: updatedLog.id!,
|
|
1005
|
+
data: {
|
|
1006
|
+
status: UserNotificationStatus.Error,
|
|
1007
|
+
statusMessage: err.message || "Error sending Telegram message.",
|
|
1008
|
+
},
|
|
1009
|
+
props: {
|
|
1010
|
+
isRoot: true,
|
|
1011
|
+
},
|
|
1012
|
+
});
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
if (
|
|
1017
|
+
options.userNotificationEventType ===
|
|
1018
|
+
UserNotificationEventType.AlertEpisodeCreated &&
|
|
1019
|
+
alertEpisode
|
|
1020
|
+
) {
|
|
1021
|
+
logTimelineItem.status = UserNotificationStatus.Sending;
|
|
1022
|
+
logTimelineItem.statusMessage = `Sending Telegram message.`;
|
|
1023
|
+
logTimelineItem.userTelegramId = notificationRuleItem.userTelegram.id!;
|
|
1024
|
+
|
|
1025
|
+
const updatedLog: UserOnCallLogTimeline =
|
|
1026
|
+
await UserOnCallLogTimelineService.create({
|
|
1027
|
+
data: logTimelineItem,
|
|
1028
|
+
props: {
|
|
1029
|
+
isRoot: true,
|
|
1030
|
+
},
|
|
1031
|
+
});
|
|
1032
|
+
|
|
1033
|
+
const telegramMessage: TelegramMessage = {
|
|
1034
|
+
to: notificationRuleItem.userTelegram.telegramChatId,
|
|
1035
|
+
body: await this.generateTelegramBodyForAlertEpisodeCreated(
|
|
1036
|
+
alertEpisode,
|
|
1037
|
+
updatedLog.id!,
|
|
1038
|
+
),
|
|
1039
|
+
parseMode: "HTML",
|
|
1040
|
+
disableWebPagePreview: true,
|
|
1041
|
+
};
|
|
1042
|
+
|
|
1043
|
+
TelegramService.sendTelegramMessage(telegramMessage, {
|
|
1044
|
+
projectId: alertEpisode.projectId,
|
|
1045
|
+
alertEpisodeId: alertEpisode.id!,
|
|
1046
|
+
userOnCallLogTimelineId: updatedLog.id!,
|
|
1047
|
+
userId: notificationRuleItem.userId!,
|
|
1048
|
+
onCallPolicyId: options.onCallPolicyId,
|
|
1049
|
+
onCallPolicyEscalationRuleId: options.onCallPolicyEscalationRuleId,
|
|
1050
|
+
teamId: options.userBelongsToTeamId,
|
|
1051
|
+
onCallDutyPolicyExecutionLogTimelineId:
|
|
1052
|
+
options.onCallDutyPolicyExecutionLogTimelineId,
|
|
1053
|
+
onCallScheduleId: options.onCallScheduleId,
|
|
1054
|
+
}).catch(async (err: Error) => {
|
|
1055
|
+
await UserOnCallLogTimelineService.updateOneById({
|
|
1056
|
+
id: updatedLog.id!,
|
|
1057
|
+
data: {
|
|
1058
|
+
status: UserNotificationStatus.Error,
|
|
1059
|
+
statusMessage: err.message || "Error sending Telegram message.",
|
|
1060
|
+
},
|
|
1061
|
+
props: {
|
|
1062
|
+
isRoot: true,
|
|
1063
|
+
},
|
|
1064
|
+
});
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
if (
|
|
1070
|
+
notificationRuleItem.userTelegram &&
|
|
1071
|
+
!notificationRuleItem.userTelegram?.isVerified
|
|
1072
|
+
) {
|
|
1073
|
+
logTimelineItem.status = UserNotificationStatus.Error;
|
|
1074
|
+
logTimelineItem.statusMessage = `Telegram message not sent because the Telegram account is not verified.`;
|
|
1075
|
+
logTimelineItem.userTelegramId = notificationRuleItem.userTelegram.id!;
|
|
1076
|
+
|
|
1077
|
+
await UserOnCallLogTimelineService.create({
|
|
1078
|
+
data: logTimelineItem,
|
|
1079
|
+
props: {
|
|
1080
|
+
isRoot: true,
|
|
1081
|
+
},
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
|
|
899
1085
|
// send call.
|
|
900
1086
|
if (
|
|
901
1087
|
notificationRuleItem.userCall?.phone &&
|
|
@@ -1680,6 +1866,161 @@ export class Service extends DatabaseService<Model> {
|
|
|
1680
1866
|
return sms;
|
|
1681
1867
|
}
|
|
1682
1868
|
|
|
1869
|
+
private async buildOnCallAcknowledgeShortUrl(
|
|
1870
|
+
userOnCallLogTimelineId: ObjectID,
|
|
1871
|
+
): Promise<URL> {
|
|
1872
|
+
const host: Hostname = await DatabaseConfig.getHost();
|
|
1873
|
+
const httpProtocol: Protocol = await DatabaseConfig.getHttpProtocol();
|
|
1874
|
+
|
|
1875
|
+
const shortUrl: ShortLink = await ShortLinkService.saveShortLinkFor(
|
|
1876
|
+
new URL(
|
|
1877
|
+
httpProtocol,
|
|
1878
|
+
host,
|
|
1879
|
+
new Route(AppApiRoute.toString())
|
|
1880
|
+
.addRoute(new UserOnCallLogTimeline().crudApiPath!)
|
|
1881
|
+
.addRoute("/acknowledge-page/" + userOnCallLogTimelineId.toString()),
|
|
1882
|
+
),
|
|
1883
|
+
);
|
|
1884
|
+
return await ShortLinkService.getShortenedUrl(shortUrl);
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
/*
|
|
1888
|
+
* Telegram's HTML parse_mode supports <b>, <i>, <a>, <code>. Only <, >, and &
|
|
1889
|
+
* need escaping inside those tags' text content.
|
|
1890
|
+
*/
|
|
1891
|
+
private escapeTelegramHtml(value: string): string {
|
|
1892
|
+
return value
|
|
1893
|
+
.replace(/&/g, "&")
|
|
1894
|
+
.replace(/</g, "<")
|
|
1895
|
+
.replace(/>/g, ">");
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
@CaptureSpan()
|
|
1899
|
+
public async generateTelegramBodyForAlertCreated(
|
|
1900
|
+
alert: Alert,
|
|
1901
|
+
userOnCallLogTimelineId: ObjectID,
|
|
1902
|
+
): Promise<string> {
|
|
1903
|
+
const ackUrl: URL = await this.buildOnCallAcknowledgeShortUrl(
|
|
1904
|
+
userOnCallLogTimelineId,
|
|
1905
|
+
);
|
|
1906
|
+
|
|
1907
|
+
const alertIdentifier: string =
|
|
1908
|
+
alert.alertNumber !== undefined
|
|
1909
|
+
? `${alert.alertNumberWithPrefix || "#" + alert.alertNumber} — ${alert.title || "Alert"}`
|
|
1910
|
+
: alert.title || "Alert";
|
|
1911
|
+
|
|
1912
|
+
const lines: Array<string> = [
|
|
1913
|
+
"🚨 <b>New alert assigned to you</b>",
|
|
1914
|
+
"",
|
|
1915
|
+
`📋 <b>${this.escapeTelegramHtml(alertIdentifier)}</b>`,
|
|
1916
|
+
"",
|
|
1917
|
+
"👤 You're getting this because you're on call.",
|
|
1918
|
+
];
|
|
1919
|
+
|
|
1920
|
+
if (alert.projectId && alert.id) {
|
|
1921
|
+
const dashboardUrl: URL = await AlertService.getAlertLinkInDashboard(
|
|
1922
|
+
alert.projectId,
|
|
1923
|
+
alert.id,
|
|
1924
|
+
);
|
|
1925
|
+
lines.push(
|
|
1926
|
+
"",
|
|
1927
|
+
`🔎 <a href="${this.escapeTelegramHtml(dashboardUrl.toString())}">View alert in OneUptime</a>`,
|
|
1928
|
+
);
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
lines.push(
|
|
1932
|
+
"",
|
|
1933
|
+
`✅ <a href="${this.escapeTelegramHtml(ackUrl.toString())}">Tap to acknowledge</a>`,
|
|
1934
|
+
);
|
|
1935
|
+
|
|
1936
|
+
return lines.join("\n");
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1939
|
+
@CaptureSpan()
|
|
1940
|
+
public async generateTelegramBodyForIncidentCreated(
|
|
1941
|
+
incident: Incident,
|
|
1942
|
+
userOnCallLogTimelineId: ObjectID,
|
|
1943
|
+
): Promise<string> {
|
|
1944
|
+
const ackUrl: URL = await this.buildOnCallAcknowledgeShortUrl(
|
|
1945
|
+
userOnCallLogTimelineId,
|
|
1946
|
+
);
|
|
1947
|
+
|
|
1948
|
+
const incidentIdentifier: string =
|
|
1949
|
+
incident.incidentNumber !== undefined
|
|
1950
|
+
? `${incident.incidentNumberWithPrefix || "#" + incident.incidentNumber} — ${incident.title || "Incident"}`
|
|
1951
|
+
: incident.title || "Incident";
|
|
1952
|
+
|
|
1953
|
+
const lines: Array<string> = [
|
|
1954
|
+
"🔥 <b>New incident assigned to you</b>",
|
|
1955
|
+
"",
|
|
1956
|
+
`📋 <b>${this.escapeTelegramHtml(incidentIdentifier)}</b>`,
|
|
1957
|
+
"",
|
|
1958
|
+
"👤 You're getting this because you're on call.",
|
|
1959
|
+
];
|
|
1960
|
+
|
|
1961
|
+
if (incident.projectId && incident.id) {
|
|
1962
|
+
const dashboardUrl: URL =
|
|
1963
|
+
await IncidentService.getIncidentLinkInDashboard(
|
|
1964
|
+
incident.projectId,
|
|
1965
|
+
incident.id,
|
|
1966
|
+
);
|
|
1967
|
+
lines.push(
|
|
1968
|
+
"",
|
|
1969
|
+
`🔎 <a href="${this.escapeTelegramHtml(dashboardUrl.toString())}">View incident in OneUptime</a>`,
|
|
1970
|
+
);
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
lines.push(
|
|
1974
|
+
"",
|
|
1975
|
+
`✅ <a href="${this.escapeTelegramHtml(ackUrl.toString())}">Tap to acknowledge</a>`,
|
|
1976
|
+
);
|
|
1977
|
+
|
|
1978
|
+
return lines.join("\n");
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1981
|
+
@CaptureSpan()
|
|
1982
|
+
public async generateTelegramBodyForAlertEpisodeCreated(
|
|
1983
|
+
alertEpisode: AlertEpisode,
|
|
1984
|
+
userOnCallLogTimelineId: ObjectID,
|
|
1985
|
+
): Promise<string> {
|
|
1986
|
+
const ackUrl: URL = await this.buildOnCallAcknowledgeShortUrl(
|
|
1987
|
+
userOnCallLogTimelineId,
|
|
1988
|
+
);
|
|
1989
|
+
|
|
1990
|
+
const episodeIdentifier: string = alertEpisode.episodeNumberWithPrefix
|
|
1991
|
+
? `${alertEpisode.episodeNumberWithPrefix} — ${alertEpisode.title || "Alert Episode"}`
|
|
1992
|
+
: alertEpisode.episodeNumber !== undefined
|
|
1993
|
+
? `#${alertEpisode.episodeNumber} — ${alertEpisode.title || "Alert Episode"}`
|
|
1994
|
+
: alertEpisode.title || "Alert Episode";
|
|
1995
|
+
|
|
1996
|
+
const lines: Array<string> = [
|
|
1997
|
+
"🔔 <b>New alert episode assigned to you</b>",
|
|
1998
|
+
"",
|
|
1999
|
+
`📋 <b>${this.escapeTelegramHtml(episodeIdentifier)}</b>`,
|
|
2000
|
+
"",
|
|
2001
|
+
"👤 You're getting this because you're on call.",
|
|
2002
|
+
];
|
|
2003
|
+
|
|
2004
|
+
if (alertEpisode.projectId && alertEpisode.id) {
|
|
2005
|
+
const dashboardUrl: URL =
|
|
2006
|
+
await AlertEpisodeService.getEpisodeLinkInDashboard(
|
|
2007
|
+
alertEpisode.projectId,
|
|
2008
|
+
alertEpisode.id,
|
|
2009
|
+
);
|
|
2010
|
+
lines.push(
|
|
2011
|
+
"",
|
|
2012
|
+
`🔎 <a href="${this.escapeTelegramHtml(dashboardUrl.toString())}">View alert episode in OneUptime</a>`,
|
|
2013
|
+
);
|
|
2014
|
+
}
|
|
2015
|
+
|
|
2016
|
+
lines.push(
|
|
2017
|
+
"",
|
|
2018
|
+
`✅ <a href="${this.escapeTelegramHtml(ackUrl.toString())}">Tap to acknowledge</a>`,
|
|
2019
|
+
);
|
|
2020
|
+
|
|
2021
|
+
return lines.join("\n");
|
|
2022
|
+
}
|
|
2023
|
+
|
|
1683
2024
|
@CaptureSpan()
|
|
1684
2025
|
public async generateWhatsAppTemplateForAlertCreated(
|
|
1685
2026
|
to: Phone,
|
|
@@ -2288,12 +2629,14 @@ export class Service extends DatabaseService<Model> {
|
|
|
2288
2629
|
!createBy.data.userSmsId &&
|
|
2289
2630
|
!createBy.data.userWhatsApp &&
|
|
2290
2631
|
!createBy.data.userWhatsAppId &&
|
|
2632
|
+
!createBy.data.userTelegram &&
|
|
2633
|
+
!createBy.data.userTelegramId &&
|
|
2291
2634
|
!createBy.data.userEmailId &&
|
|
2292
2635
|
!createBy.data.userPushId &&
|
|
2293
2636
|
!createBy.data.userPush
|
|
2294
2637
|
) {
|
|
2295
2638
|
throw new BadDataException(
|
|
2296
|
-
"Call, SMS, WhatsApp, Email, or Push notification is required",
|
|
2639
|
+
"Call, SMS, WhatsApp, Telegram, Email, or Push notification is required",
|
|
2297
2640
|
);
|
|
2298
2641
|
}
|
|
2299
2642
|
|
|
@@ -2355,6 +2698,9 @@ export class Service extends DatabaseService<Model> {
|
|
|
2355
2698
|
if (descriptor.userWhatsAppId) {
|
|
2356
2699
|
rule.userWhatsAppId = descriptor.userWhatsAppId;
|
|
2357
2700
|
}
|
|
2701
|
+
if (descriptor.userTelegramId) {
|
|
2702
|
+
rule.userTelegramId = descriptor.userTelegramId;
|
|
2703
|
+
}
|
|
2358
2704
|
if (descriptor.userPushId) {
|
|
2359
2705
|
rule.userPushId = descriptor.userPushId;
|
|
2360
2706
|
}
|
|
@@ -2376,6 +2722,9 @@ export class Service extends DatabaseService<Model> {
|
|
|
2376
2722
|
if (descriptor.userWhatsAppId) {
|
|
2377
2723
|
query["userWhatsAppId"] = descriptor.userWhatsAppId;
|
|
2378
2724
|
}
|
|
2725
|
+
if (descriptor.userTelegramId) {
|
|
2726
|
+
query["userTelegramId"] = descriptor.userTelegramId;
|
|
2727
|
+
}
|
|
2379
2728
|
if (descriptor.userPushId) {
|
|
2380
2729
|
query["userPushId"] = descriptor.userPushId;
|
|
2381
2730
|
}
|