@oneuptime/common 10.0.66 → 10.0.67
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/DatabaseModels/GlobalConfig.ts +56 -0
- package/Models/DatabaseModels/Index.ts +4 -0
- package/Models/DatabaseModels/Project.ts +30 -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/Index.ts +2 -0
- package/Server/Services/Index.ts +6 -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/Date.ts +12 -3
- package/Types/Icon/IconProp.ts +1 -0
- package/Types/Permission.ts +11 -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/DatabaseModels/GlobalConfig.js +59 -0
- package/build/dist/Models/DatabaseModels/GlobalConfig.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/Project.js +32 -0
- package/build/dist/Models/DatabaseModels/Project.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/Index.js +2 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
- package/build/dist/Server/Services/Index.js +6 -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/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 +10 -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
|
@@ -6,6 +6,7 @@ import UserCall from "./UserCall";
|
|
|
6
6
|
import UserEmail from "./UserEmail";
|
|
7
7
|
import UserPush from "./UserPush";
|
|
8
8
|
import UserSMS from "./UserSMS";
|
|
9
|
+
import UserTelegram from "./UserTelegram";
|
|
9
10
|
import UserWhatsApp from "./UserWhatsApp";
|
|
10
11
|
import BaseModel from "./DatabaseBaseModel/DatabaseBaseModel";
|
|
11
12
|
import Route from "../../Types/API/Route";
|
|
@@ -440,6 +441,54 @@ class UserNotificationRule extends BaseModel {
|
|
|
440
441
|
})
|
|
441
442
|
public userWhatsAppId?: ObjectID = undefined;
|
|
442
443
|
|
|
444
|
+
@ColumnAccessControl({
|
|
445
|
+
create: [Permission.CurrentUser],
|
|
446
|
+
read: [Permission.CurrentUser],
|
|
447
|
+
update: [],
|
|
448
|
+
})
|
|
449
|
+
@TableColumn({
|
|
450
|
+
manyToOneRelationColumn: "userTelegramId",
|
|
451
|
+
type: TableColumnType.Entity,
|
|
452
|
+
modelType: UserTelegram,
|
|
453
|
+
title: "User Telegram",
|
|
454
|
+
description:
|
|
455
|
+
"Relation to User Telegram Resource in which this object belongs",
|
|
456
|
+
})
|
|
457
|
+
@ManyToOne(
|
|
458
|
+
() => {
|
|
459
|
+
return UserTelegram;
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
eager: false,
|
|
463
|
+
nullable: true,
|
|
464
|
+
onDelete: "CASCADE",
|
|
465
|
+
orphanedRowAction: "nullify",
|
|
466
|
+
},
|
|
467
|
+
)
|
|
468
|
+
@JoinColumn({ name: "userTelegramId" })
|
|
469
|
+
public userTelegram?: UserTelegram = undefined;
|
|
470
|
+
|
|
471
|
+
@ColumnAccessControl({
|
|
472
|
+
create: [Permission.CurrentUser],
|
|
473
|
+
read: [Permission.CurrentUser],
|
|
474
|
+
update: [],
|
|
475
|
+
})
|
|
476
|
+
@Index()
|
|
477
|
+
@TableColumn({
|
|
478
|
+
type: TableColumnType.ObjectID,
|
|
479
|
+
required: false,
|
|
480
|
+
canReadOnRelationQuery: true,
|
|
481
|
+
title: "User Telegram ID",
|
|
482
|
+
description: "ID of User Telegram in which this object belongs",
|
|
483
|
+
example: "8f7e6d5c-4b3a-2f1e-0d9c-8b7a6f5e4d3c",
|
|
484
|
+
})
|
|
485
|
+
@Column({
|
|
486
|
+
type: ColumnType.ObjectID,
|
|
487
|
+
nullable: true,
|
|
488
|
+
transformer: ObjectID.getDatabaseTransformer(),
|
|
489
|
+
})
|
|
490
|
+
public userTelegramId?: ObjectID = undefined;
|
|
491
|
+
|
|
443
492
|
@ColumnAccessControl({
|
|
444
493
|
create: [Permission.CurrentUser],
|
|
445
494
|
read: [Permission.CurrentUser],
|
|
@@ -297,6 +297,23 @@ class UserNotificationSetting extends BaseModel {
|
|
|
297
297
|
})
|
|
298
298
|
public alertByWhatsApp?: boolean = undefined;
|
|
299
299
|
|
|
300
|
+
@ColumnAccessControl({
|
|
301
|
+
create: [Permission.CurrentUser],
|
|
302
|
+
read: [Permission.CurrentUser],
|
|
303
|
+
update: [Permission.CurrentUser],
|
|
304
|
+
})
|
|
305
|
+
@TableColumn({
|
|
306
|
+
isDefaultValueColumn: true,
|
|
307
|
+
type: TableColumnType.Boolean,
|
|
308
|
+
defaultValue: false,
|
|
309
|
+
example: false,
|
|
310
|
+
})
|
|
311
|
+
@Column({
|
|
312
|
+
type: ColumnType.Boolean,
|
|
313
|
+
default: false,
|
|
314
|
+
})
|
|
315
|
+
public alertByTelegram?: boolean = undefined;
|
|
316
|
+
|
|
300
317
|
@ColumnAccessControl({
|
|
301
318
|
create: [Permission.CurrentUser],
|
|
302
319
|
read: [Permission.CurrentUser],
|
|
@@ -15,6 +15,7 @@ import UserNotificationRule from "./UserNotificationRule";
|
|
|
15
15
|
import UserPush from "./UserPush";
|
|
16
16
|
import UserOnCallLog from "./UserOnCallLog";
|
|
17
17
|
import UserSMS from "./UserSMS";
|
|
18
|
+
import UserTelegram from "./UserTelegram";
|
|
18
19
|
import UserWhatsApp from "./UserWhatsApp";
|
|
19
20
|
import BaseModel from "./DatabaseBaseModel/DatabaseBaseModel";
|
|
20
21
|
import Route from "../../Types/API/Route";
|
|
@@ -980,6 +981,53 @@ export default class UserOnCallLogTimeline extends BaseModel {
|
|
|
980
981
|
})
|
|
981
982
|
public userWhatsAppId?: ObjectID = undefined;
|
|
982
983
|
|
|
984
|
+
@ColumnAccessControl({
|
|
985
|
+
create: [],
|
|
986
|
+
read: [Permission.CurrentUser],
|
|
987
|
+
update: [],
|
|
988
|
+
})
|
|
989
|
+
@TableColumn({
|
|
990
|
+
manyToOneRelationColumn: "userTelegramId",
|
|
991
|
+
type: TableColumnType.Entity,
|
|
992
|
+
modelType: UserTelegram,
|
|
993
|
+
title: "User Telegram",
|
|
994
|
+
description:
|
|
995
|
+
"Relation to User Telegram Resource in which this object belongs",
|
|
996
|
+
})
|
|
997
|
+
@ManyToOne(
|
|
998
|
+
() => {
|
|
999
|
+
return UserTelegram;
|
|
1000
|
+
},
|
|
1001
|
+
{
|
|
1002
|
+
eager: false,
|
|
1003
|
+
nullable: true,
|
|
1004
|
+
onDelete: "CASCADE",
|
|
1005
|
+
orphanedRowAction: "nullify",
|
|
1006
|
+
},
|
|
1007
|
+
)
|
|
1008
|
+
@JoinColumn({ name: "userTelegramId" })
|
|
1009
|
+
public userTelegram?: UserTelegram = undefined;
|
|
1010
|
+
|
|
1011
|
+
@ColumnAccessControl({
|
|
1012
|
+
create: [],
|
|
1013
|
+
read: [Permission.CurrentUser],
|
|
1014
|
+
update: [],
|
|
1015
|
+
})
|
|
1016
|
+
@Index()
|
|
1017
|
+
@TableColumn({
|
|
1018
|
+
type: TableColumnType.ObjectID,
|
|
1019
|
+
required: false,
|
|
1020
|
+
canReadOnRelationQuery: true,
|
|
1021
|
+
title: "User Telegram ID",
|
|
1022
|
+
description: "ID of User Telegram in which this object belongs",
|
|
1023
|
+
})
|
|
1024
|
+
@Column({
|
|
1025
|
+
type: ColumnType.ObjectID,
|
|
1026
|
+
nullable: true,
|
|
1027
|
+
transformer: ObjectID.getDatabaseTransformer(),
|
|
1028
|
+
})
|
|
1029
|
+
public userTelegramId?: ObjectID = undefined;
|
|
1030
|
+
|
|
983
1031
|
@ColumnAccessControl({
|
|
984
1032
|
create: [],
|
|
985
1033
|
read: [Permission.CurrentUser],
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import Project from "./Project";
|
|
2
|
+
import User from "./User";
|
|
3
|
+
import BaseModel from "./DatabaseBaseModel/DatabaseBaseModel";
|
|
4
|
+
import Route from "../../Types/API/Route";
|
|
5
|
+
import AllowAccessIfSubscriptionIsUnpaid from "../../Types/Database/AccessControl/AllowAccessIfSubscriptionIsUnpaid";
|
|
6
|
+
import ColumnAccessControl from "../../Types/Database/AccessControl/ColumnAccessControl";
|
|
7
|
+
import TableAccessControl from "../../Types/Database/AccessControl/TableAccessControl";
|
|
8
|
+
import ColumnLength from "../../Types/Database/ColumnLength";
|
|
9
|
+
import ColumnType from "../../Types/Database/ColumnType";
|
|
10
|
+
import CrudApiEndpoint from "../../Types/Database/CrudApiEndpoint";
|
|
11
|
+
import CurrentUserCanAccessRecordBy from "../../Types/Database/CurrentUserCanAccessRecordBy";
|
|
12
|
+
import TableColumn from "../../Types/Database/TableColumn";
|
|
13
|
+
import TableColumnType from "../../Types/Database/TableColumnType";
|
|
14
|
+
import TableMetadata from "../../Types/Database/TableMetadata";
|
|
15
|
+
import TenantColumn from "../../Types/Database/TenantColumn";
|
|
16
|
+
import IconProp from "../../Types/Icon/IconProp";
|
|
17
|
+
import ObjectID from "../../Types/ObjectID";
|
|
18
|
+
import Permission from "../../Types/Permission";
|
|
19
|
+
import Text from "../../Types/Text";
|
|
20
|
+
import { Column, Entity, Index, JoinColumn, ManyToOne } from "typeorm";
|
|
21
|
+
|
|
22
|
+
@TenantColumn("projectId")
|
|
23
|
+
@AllowAccessIfSubscriptionIsUnpaid()
|
|
24
|
+
@TableAccessControl({
|
|
25
|
+
create: [Permission.CurrentUser],
|
|
26
|
+
read: [Permission.CurrentUser],
|
|
27
|
+
delete: [Permission.CurrentUser],
|
|
28
|
+
update: [Permission.CurrentUser],
|
|
29
|
+
})
|
|
30
|
+
@CrudApiEndpoint(new Route("/user-telegram"))
|
|
31
|
+
@Entity({
|
|
32
|
+
name: "UserTelegram",
|
|
33
|
+
})
|
|
34
|
+
@TableMetadata({
|
|
35
|
+
tableName: "UserTelegram",
|
|
36
|
+
singularName: "Telegram Account",
|
|
37
|
+
pluralName: "Telegram Accounts",
|
|
38
|
+
icon: IconProp.Telegram,
|
|
39
|
+
tableDescription: "Telegram accounts used for Telegram notifications.",
|
|
40
|
+
})
|
|
41
|
+
@CurrentUserCanAccessRecordBy("userId")
|
|
42
|
+
class UserTelegram extends BaseModel {
|
|
43
|
+
@ColumnAccessControl({
|
|
44
|
+
create: [Permission.CurrentUser],
|
|
45
|
+
read: [Permission.CurrentUser],
|
|
46
|
+
update: [],
|
|
47
|
+
})
|
|
48
|
+
@TableColumn({
|
|
49
|
+
manyToOneRelationColumn: "projectId",
|
|
50
|
+
type: TableColumnType.Entity,
|
|
51
|
+
modelType: Project,
|
|
52
|
+
title: "Project",
|
|
53
|
+
description: "Relation to Project Resource in which this object belongs",
|
|
54
|
+
})
|
|
55
|
+
@ManyToOne(
|
|
56
|
+
() => {
|
|
57
|
+
return Project;
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
eager: false,
|
|
61
|
+
nullable: true,
|
|
62
|
+
onDelete: "CASCADE",
|
|
63
|
+
orphanedRowAction: "nullify",
|
|
64
|
+
},
|
|
65
|
+
)
|
|
66
|
+
@JoinColumn({ name: "projectId" })
|
|
67
|
+
public project?: Project = undefined;
|
|
68
|
+
|
|
69
|
+
@ColumnAccessControl({
|
|
70
|
+
create: [Permission.CurrentUser],
|
|
71
|
+
read: [Permission.CurrentUser],
|
|
72
|
+
update: [],
|
|
73
|
+
})
|
|
74
|
+
@Index()
|
|
75
|
+
@TableColumn({
|
|
76
|
+
type: TableColumnType.ObjectID,
|
|
77
|
+
required: true,
|
|
78
|
+
canReadOnRelationQuery: true,
|
|
79
|
+
title: "Project ID",
|
|
80
|
+
description: "ID of your OneUptime Project in which this object belongs",
|
|
81
|
+
})
|
|
82
|
+
@Column({
|
|
83
|
+
type: ColumnType.ObjectID,
|
|
84
|
+
nullable: false,
|
|
85
|
+
transformer: ObjectID.getDatabaseTransformer(),
|
|
86
|
+
})
|
|
87
|
+
public projectId?: ObjectID = undefined;
|
|
88
|
+
|
|
89
|
+
@ColumnAccessControl({
|
|
90
|
+
create: [Permission.CurrentUser],
|
|
91
|
+
read: [Permission.CurrentUser],
|
|
92
|
+
update: [Permission.CurrentUser],
|
|
93
|
+
})
|
|
94
|
+
@TableColumn({
|
|
95
|
+
title: "Telegram Handle",
|
|
96
|
+
required: false,
|
|
97
|
+
unique: false,
|
|
98
|
+
type: TableColumnType.ShortText,
|
|
99
|
+
canReadOnRelationQuery: true,
|
|
100
|
+
description:
|
|
101
|
+
"Optional Telegram username / handle (e.g. @alice) for your own reference.",
|
|
102
|
+
})
|
|
103
|
+
@Column({
|
|
104
|
+
type: ColumnType.ShortText,
|
|
105
|
+
length: ColumnLength.ShortText,
|
|
106
|
+
unique: false,
|
|
107
|
+
nullable: true,
|
|
108
|
+
})
|
|
109
|
+
public telegramUserHandle?: string = undefined;
|
|
110
|
+
|
|
111
|
+
@ColumnAccessControl({
|
|
112
|
+
create: [],
|
|
113
|
+
read: [Permission.CurrentUser],
|
|
114
|
+
update: [],
|
|
115
|
+
})
|
|
116
|
+
@Index()
|
|
117
|
+
@TableColumn({
|
|
118
|
+
title: "Telegram Chat ID",
|
|
119
|
+
required: false,
|
|
120
|
+
unique: false,
|
|
121
|
+
type: TableColumnType.ShortText,
|
|
122
|
+
canReadOnRelationQuery: false,
|
|
123
|
+
description:
|
|
124
|
+
"Telegram chat ID captured from the OneUptime bot after verification. Populated automatically.",
|
|
125
|
+
})
|
|
126
|
+
@Column({
|
|
127
|
+
type: ColumnType.ShortText,
|
|
128
|
+
length: ColumnLength.ShortText,
|
|
129
|
+
unique: false,
|
|
130
|
+
nullable: true,
|
|
131
|
+
})
|
|
132
|
+
public telegramChatId?: string = undefined;
|
|
133
|
+
|
|
134
|
+
@ColumnAccessControl({
|
|
135
|
+
create: [Permission.CurrentUser],
|
|
136
|
+
read: [Permission.CurrentUser],
|
|
137
|
+
update: [],
|
|
138
|
+
})
|
|
139
|
+
@TableColumn({
|
|
140
|
+
manyToOneRelationColumn: "user",
|
|
141
|
+
type: TableColumnType.Entity,
|
|
142
|
+
modelType: User,
|
|
143
|
+
title: "User",
|
|
144
|
+
description: "Relation to User who this Telegram account belongs to",
|
|
145
|
+
})
|
|
146
|
+
@ManyToOne(
|
|
147
|
+
() => {
|
|
148
|
+
return User;
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
eager: false,
|
|
152
|
+
nullable: true,
|
|
153
|
+
onDelete: "CASCADE",
|
|
154
|
+
orphanedRowAction: "nullify",
|
|
155
|
+
},
|
|
156
|
+
)
|
|
157
|
+
@JoinColumn({ name: "userId" })
|
|
158
|
+
public user?: User = undefined;
|
|
159
|
+
|
|
160
|
+
@ColumnAccessControl({
|
|
161
|
+
create: [Permission.CurrentUser],
|
|
162
|
+
read: [Permission.CurrentUser],
|
|
163
|
+
update: [],
|
|
164
|
+
})
|
|
165
|
+
@TableColumn({
|
|
166
|
+
type: TableColumnType.ObjectID,
|
|
167
|
+
title: "User ID",
|
|
168
|
+
description: "User ID who this Telegram account belongs to",
|
|
169
|
+
})
|
|
170
|
+
@Column({
|
|
171
|
+
type: ColumnType.ObjectID,
|
|
172
|
+
nullable: true,
|
|
173
|
+
transformer: ObjectID.getDatabaseTransformer(),
|
|
174
|
+
})
|
|
175
|
+
@Index()
|
|
176
|
+
public userId?: ObjectID = undefined;
|
|
177
|
+
|
|
178
|
+
@ColumnAccessControl({
|
|
179
|
+
create: [Permission.CurrentUser],
|
|
180
|
+
read: [Permission.CurrentUser],
|
|
181
|
+
update: [],
|
|
182
|
+
})
|
|
183
|
+
@TableColumn({
|
|
184
|
+
manyToOneRelationColumn: "createdByUserId",
|
|
185
|
+
type: TableColumnType.Entity,
|
|
186
|
+
modelType: User,
|
|
187
|
+
title: "Created by User",
|
|
188
|
+
description:
|
|
189
|
+
"Relation to User who created this object (if this object was created by a User)",
|
|
190
|
+
})
|
|
191
|
+
@ManyToOne(
|
|
192
|
+
() => {
|
|
193
|
+
return User;
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
eager: false,
|
|
197
|
+
nullable: true,
|
|
198
|
+
onDelete: "SET NULL",
|
|
199
|
+
orphanedRowAction: "nullify",
|
|
200
|
+
},
|
|
201
|
+
)
|
|
202
|
+
@JoinColumn({ name: "createdByUserId" })
|
|
203
|
+
public createdByUser?: User = undefined;
|
|
204
|
+
|
|
205
|
+
@ColumnAccessControl({
|
|
206
|
+
create: [Permission.CurrentUser],
|
|
207
|
+
read: [Permission.CurrentUser],
|
|
208
|
+
update: [],
|
|
209
|
+
})
|
|
210
|
+
@TableColumn({
|
|
211
|
+
type: TableColumnType.ObjectID,
|
|
212
|
+
title: "Created by User ID",
|
|
213
|
+
description:
|
|
214
|
+
"User ID who created this object (if this object was created by a User)",
|
|
215
|
+
})
|
|
216
|
+
@Column({
|
|
217
|
+
type: ColumnType.ObjectID,
|
|
218
|
+
nullable: true,
|
|
219
|
+
transformer: ObjectID.getDatabaseTransformer(),
|
|
220
|
+
})
|
|
221
|
+
public createdByUserId?: ObjectID = undefined;
|
|
222
|
+
|
|
223
|
+
@ColumnAccessControl({
|
|
224
|
+
create: [],
|
|
225
|
+
read: [],
|
|
226
|
+
update: [],
|
|
227
|
+
})
|
|
228
|
+
@TableColumn({
|
|
229
|
+
manyToOneRelationColumn: "deletedByUserId",
|
|
230
|
+
type: TableColumnType.Entity,
|
|
231
|
+
title: "Deleted by User",
|
|
232
|
+
modelType: User,
|
|
233
|
+
description:
|
|
234
|
+
"Relation to User who deleted this object (if this object was deleted by a User)",
|
|
235
|
+
})
|
|
236
|
+
@ManyToOne(
|
|
237
|
+
() => {
|
|
238
|
+
return User;
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
cascade: false,
|
|
242
|
+
eager: false,
|
|
243
|
+
nullable: true,
|
|
244
|
+
onDelete: "SET NULL",
|
|
245
|
+
orphanedRowAction: "nullify",
|
|
246
|
+
},
|
|
247
|
+
)
|
|
248
|
+
@JoinColumn({ name: "deletedByUserId" })
|
|
249
|
+
public deletedByUser?: User = undefined;
|
|
250
|
+
|
|
251
|
+
@ColumnAccessControl({
|
|
252
|
+
create: [],
|
|
253
|
+
read: [],
|
|
254
|
+
update: [],
|
|
255
|
+
})
|
|
256
|
+
@TableColumn({
|
|
257
|
+
type: TableColumnType.ObjectID,
|
|
258
|
+
title: "Deleted by User ID",
|
|
259
|
+
description:
|
|
260
|
+
"User ID who deleted this object (if this object was deleted by a User)",
|
|
261
|
+
})
|
|
262
|
+
@Column({
|
|
263
|
+
type: ColumnType.ObjectID,
|
|
264
|
+
nullable: true,
|
|
265
|
+
transformer: ObjectID.getDatabaseTransformer(),
|
|
266
|
+
})
|
|
267
|
+
public deletedByUserId?: ObjectID = undefined;
|
|
268
|
+
|
|
269
|
+
@ColumnAccessControl({
|
|
270
|
+
create: [],
|
|
271
|
+
read: [Permission.CurrentUser],
|
|
272
|
+
update: [],
|
|
273
|
+
})
|
|
274
|
+
@TableColumn({
|
|
275
|
+
title: "Is Verified",
|
|
276
|
+
description: "Is this Telegram account verified?",
|
|
277
|
+
isDefaultValueColumn: true,
|
|
278
|
+
type: TableColumnType.Boolean,
|
|
279
|
+
defaultValue: false,
|
|
280
|
+
})
|
|
281
|
+
@Column({
|
|
282
|
+
type: ColumnType.Boolean,
|
|
283
|
+
default: false,
|
|
284
|
+
})
|
|
285
|
+
public isVerified?: boolean = undefined;
|
|
286
|
+
|
|
287
|
+
@ColumnAccessControl({
|
|
288
|
+
create: [],
|
|
289
|
+
read: [Permission.CurrentUser],
|
|
290
|
+
update: [],
|
|
291
|
+
})
|
|
292
|
+
@TableColumn({
|
|
293
|
+
title: "Verification Code",
|
|
294
|
+
description:
|
|
295
|
+
"Temporary Verification Code. The user sends /start <code> to the OneUptime bot to verify.",
|
|
296
|
+
isDefaultValueColumn: true,
|
|
297
|
+
computed: true,
|
|
298
|
+
required: true,
|
|
299
|
+
type: TableColumnType.ShortText,
|
|
300
|
+
forceGetDefaultValueOnCreate: () => {
|
|
301
|
+
return Text.generateRandomNumber(6);
|
|
302
|
+
},
|
|
303
|
+
})
|
|
304
|
+
@Column({
|
|
305
|
+
type: ColumnType.ShortText,
|
|
306
|
+
nullable: false,
|
|
307
|
+
length: ColumnLength.ShortText,
|
|
308
|
+
})
|
|
309
|
+
public verificationCode?: string = undefined;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export default UserTelegram;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import UserMiddleware from "../Middleware/UserAuthorization";
|
|
2
|
+
import GlobalConfigService from "../Services/GlobalConfigService";
|
|
3
|
+
import UserTelegramService, {
|
|
4
|
+
Service as UserTelegramServiceType,
|
|
5
|
+
} from "../Services/UserTelegramService";
|
|
6
|
+
import {
|
|
7
|
+
ExpressRequest,
|
|
8
|
+
ExpressResponse,
|
|
9
|
+
NextFunction,
|
|
10
|
+
OneUptimeRequest,
|
|
11
|
+
} from "../Utils/Express";
|
|
12
|
+
import Response from "../Utils/Response";
|
|
13
|
+
import BaseAPI from "./BaseAPI";
|
|
14
|
+
import BadDataException from "../../Types/Exception/BadDataException";
|
|
15
|
+
import ObjectID from "../../Types/ObjectID";
|
|
16
|
+
import UserTelegram from "../../Models/DatabaseModels/UserTelegram";
|
|
17
|
+
import GlobalConfig from "../../Models/DatabaseModels/GlobalConfig";
|
|
18
|
+
|
|
19
|
+
export default class UserTelegramAPI extends BaseAPI<
|
|
20
|
+
UserTelegram,
|
|
21
|
+
UserTelegramServiceType
|
|
22
|
+
> {
|
|
23
|
+
public constructor() {
|
|
24
|
+
super(UserTelegram, UserTelegramService);
|
|
25
|
+
|
|
26
|
+
this.router.post(
|
|
27
|
+
`${new this.entityType().getCrudApiPath()?.toString()}/verification-info`,
|
|
28
|
+
UserMiddleware.getUserMiddleware,
|
|
29
|
+
async (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
|
|
30
|
+
try {
|
|
31
|
+
req = req as OneUptimeRequest;
|
|
32
|
+
|
|
33
|
+
if (!req.body.itemId) {
|
|
34
|
+
return Response.sendErrorResponse(
|
|
35
|
+
req,
|
|
36
|
+
res,
|
|
37
|
+
new BadDataException("Invalid item ID"),
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const item: UserTelegram | null = await this.service.findOneById({
|
|
42
|
+
id: req.body["itemId"],
|
|
43
|
+
props: {
|
|
44
|
+
isRoot: true,
|
|
45
|
+
},
|
|
46
|
+
select: {
|
|
47
|
+
userId: true,
|
|
48
|
+
projectId: true,
|
|
49
|
+
verificationCode: true,
|
|
50
|
+
isVerified: true,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
if (!item) {
|
|
55
|
+
return Response.sendErrorResponse(
|
|
56
|
+
req,
|
|
57
|
+
res,
|
|
58
|
+
new BadDataException("Item not found"),
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (
|
|
63
|
+
item.userId?.toString() !==
|
|
64
|
+
(req as OneUptimeRequest)?.userAuthorization?.userId?.toString()
|
|
65
|
+
) {
|
|
66
|
+
return Response.sendErrorResponse(
|
|
67
|
+
req,
|
|
68
|
+
res,
|
|
69
|
+
new BadDataException("Invalid user ID"),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const globalConfig: GlobalConfig | null =
|
|
74
|
+
await GlobalConfigService.findOneBy({
|
|
75
|
+
query: {
|
|
76
|
+
_id: ObjectID.getZeroObjectID().toString(),
|
|
77
|
+
},
|
|
78
|
+
props: {
|
|
79
|
+
isRoot: true,
|
|
80
|
+
},
|
|
81
|
+
select: {
|
|
82
|
+
telegramBotUsername: true,
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const botUsername: string | undefined =
|
|
87
|
+
globalConfig?.telegramBotUsername?.trim() || undefined;
|
|
88
|
+
|
|
89
|
+
if (!botUsername) {
|
|
90
|
+
return Response.sendErrorResponse(
|
|
91
|
+
req,
|
|
92
|
+
res,
|
|
93
|
+
new BadDataException(
|
|
94
|
+
"Telegram bot is not configured. Please contact your OneUptime administrator.",
|
|
95
|
+
),
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return Response.sendJsonObjectResponse(req, res, {
|
|
100
|
+
verificationCode: item.verificationCode as string,
|
|
101
|
+
telegramBotUsername: botUsername,
|
|
102
|
+
isVerified: Boolean(item.isVerified),
|
|
103
|
+
deepLinkUrl: `https://t.me/${botUsername}?start=${item.verificationCode}`,
|
|
104
|
+
startCommand: `/start ${item.verificationCode}`,
|
|
105
|
+
});
|
|
106
|
+
} catch (err) {
|
|
107
|
+
return next(err);
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
this.router.post(
|
|
113
|
+
`${new this.entityType()
|
|
114
|
+
.getCrudApiPath()
|
|
115
|
+
?.toString()}/resend-verification-code`,
|
|
116
|
+
UserMiddleware.getUserMiddleware,
|
|
117
|
+
async (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
|
|
118
|
+
try {
|
|
119
|
+
req = req as OneUptimeRequest;
|
|
120
|
+
|
|
121
|
+
if (!req.body.itemId) {
|
|
122
|
+
return Response.sendErrorResponse(
|
|
123
|
+
req,
|
|
124
|
+
res,
|
|
125
|
+
new BadDataException("Invalid item ID"),
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const item: UserTelegram | null = await this.service.findOneById({
|
|
130
|
+
id: req.body["itemId"],
|
|
131
|
+
props: {
|
|
132
|
+
isRoot: true,
|
|
133
|
+
},
|
|
134
|
+
select: {
|
|
135
|
+
userId: true,
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
if (!item) {
|
|
140
|
+
return Response.sendErrorResponse(
|
|
141
|
+
req,
|
|
142
|
+
res,
|
|
143
|
+
new BadDataException("Item not found"),
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (
|
|
148
|
+
item.userId?.toString() !==
|
|
149
|
+
(req as OneUptimeRequest)?.userAuthorization?.userId?.toString()
|
|
150
|
+
) {
|
|
151
|
+
return Response.sendErrorResponse(
|
|
152
|
+
req,
|
|
153
|
+
res,
|
|
154
|
+
new BadDataException("Invalid user ID"),
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
await this.service.regenerateVerificationCode(req.body.itemId);
|
|
159
|
+
|
|
160
|
+
return Response.sendEmptySuccessResponse(req, res);
|
|
161
|
+
} catch (err) {
|
|
162
|
+
return next(err);
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
}
|