@oneuptime/common 7.0.3717 → 7.0.3786

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.
Files changed (203) hide show
  1. package/Models/DatabaseModels/Alert.ts +3 -2
  2. package/Models/DatabaseModels/Incident.ts +3 -2
  3. package/Models/DatabaseModels/Index.ts +3 -0
  4. package/Models/DatabaseModels/ProjectUser.ts +335 -0
  5. package/Models/DatabaseModels/ScheduledMaintenance.ts +3 -2
  6. package/Server/API/SlackAPI.ts +65 -97
  7. package/Server/API/UserOnCallLogTimelineAPI.ts +2 -9
  8. package/Server/Infrastructure/Postgres/SchemaMigrations/1740597525803-MigrationName.ts +17 -0
  9. package/Server/Infrastructure/Postgres/SchemaMigrations/1740598793630-MigrationName.ts +17 -0
  10. package/Server/Infrastructure/Postgres/SchemaMigrations/1741031019972-MigrationName.ts +17 -0
  11. package/Server/Infrastructure/Postgres/SchemaMigrations/1741209339971-MigrationName.ts +101 -0
  12. package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +8 -0
  13. package/Server/Middleware/SlackAuthorization.ts +11 -2
  14. package/Server/Services/AlertFeedService.ts +2 -2
  15. package/Server/Services/AlertInternalNoteService.ts +2 -2
  16. package/Server/Services/AlertOwnerTeamService.ts +4 -4
  17. package/Server/Services/AlertOwnerUserService.ts +3 -3
  18. package/Server/Services/AlertService.ts +62 -20
  19. package/Server/Services/AlertStateTimelineService.ts +8 -18
  20. package/Server/Services/IncidentFeedService.ts +101 -2
  21. package/Server/Services/IncidentInternalNoteService.ts +47 -4
  22. package/Server/Services/IncidentOwnerTeamService.ts +57 -4
  23. package/Server/Services/IncidentOwnerUserService.ts +59 -15
  24. package/Server/Services/IncidentPublicNoteService.ts +41 -4
  25. package/Server/Services/IncidentService.ts +279 -193
  26. package/Server/Services/IncidentStateService.ts +25 -0
  27. package/Server/Services/IncidentStateTimelineService.ts +37 -19
  28. package/Server/Services/MonitorStatusTimelineService.ts +7 -17
  29. package/Server/Services/OnCallDutyPolicyEscalationRuleService.ts +2 -0
  30. package/Server/Services/OnCallDutyPolicyExecutionLogService.ts +74 -7
  31. package/Server/Services/OnCallDutyPolicyExecutionLogTimelineService.ts +63 -4
  32. package/Server/Services/OnCallDutyPolicyService.ts +13 -0
  33. package/Server/Services/ProjectUserService.ts +130 -0
  34. package/Server/Services/ScheduledMaintenanceFeedService.ts +2 -2
  35. package/Server/Services/ScheduledMaintenanceInternalNoteService.ts +12 -10
  36. package/Server/Services/ScheduledMaintenanceOwnerTeamService.ts +22 -18
  37. package/Server/Services/ScheduledMaintenanceOwnerUserService.ts +28 -30
  38. package/Server/Services/ScheduledMaintenancePublicNoteService.ts +12 -10
  39. package/Server/Services/ScheduledMaintenanceService.ts +16 -10
  40. package/Server/Services/ScheduledMaintenanceStateTimelineService.ts +1 -1
  41. package/Server/Services/StatusPageSubscriberService.ts +3 -0
  42. package/Server/Services/TeamMemberService.ts +20 -0
  43. package/Server/Services/UserNotificationRuleService.ts +74 -0
  44. package/Server/Services/UserOnCallLogService.ts +1 -1
  45. package/Server/Services/UserService.ts +35 -0
  46. package/Server/Services/WorkspaceNotificationRuleService.ts +508 -149
  47. package/Server/Services/WorkspaceUserAuthTokenService.ts +23 -0
  48. package/Server/Utils/Express.ts +1 -1
  49. package/Server/Utils/StartServer.ts +6 -1
  50. package/Server/Utils/Workspace/MicrosoftTeams/Messages/Incident.ts +195 -0
  51. package/Server/Utils/Workspace/Slack/Actions/ActionTypes.ts +20 -0
  52. package/Server/Utils/Workspace/Slack/Actions/Auth.ts +266 -0
  53. package/Server/Utils/Workspace/Slack/Actions/Incident.ts +1117 -0
  54. package/Server/Utils/Workspace/Slack/Messages/Incident.ts +116 -0
  55. package/Server/Utils/Workspace/Slack/Slack.ts +555 -18
  56. package/Server/Utils/Workspace/Slack/app-manifest.json +18 -10
  57. package/Server/Utils/Workspace/Workspace.ts +194 -1
  58. package/Server/Utils/Workspace/WorkspaceBase.ts +145 -19
  59. package/Server/Utils/Workspace/WorkspaceMessages/Incident.ts +68 -0
  60. package/Types/Icon/IconProp.ts +1 -0
  61. package/Types/Workspace/NotificationRules/NotificationRuleCondition.ts +2 -1
  62. package/Types/Workspace/NotificationRules/NotificationRuleUtil.ts +251 -121
  63. package/Types/Workspace/NotificationRules/NotificationRuleWorkspaceChannel.ts +6 -0
  64. package/Types/Workspace/WorkspaceMessagePayload.ts +71 -2
  65. package/UI/Components/ComingSoon/ComingSoon.tsx +13 -3
  66. package/UI/Components/Forms/Fields/FormField.tsx +2 -2
  67. package/UI/Components/Icon/Icon.tsx +39 -2
  68. package/UI/Components/ModelTable/BaseModelTable.tsx +16 -0
  69. package/UI/Components/Radio/Radio.tsx +11 -2
  70. package/UI/Components/Table/TableCard.tsx +2 -2
  71. package/build/dist/Models/DatabaseModels/Alert.js.map +1 -1
  72. package/build/dist/Models/DatabaseModels/Incident.js.map +1 -1
  73. package/build/dist/Models/DatabaseModels/Index.js +2 -0
  74. package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
  75. package/build/dist/Models/DatabaseModels/ProjectUser.js +340 -0
  76. package/build/dist/Models/DatabaseModels/ProjectUser.js.map +1 -0
  77. package/build/dist/Models/DatabaseModels/ScheduledMaintenance.js.map +1 -1
  78. package/build/dist/Server/API/SlackAPI.js +39 -79
  79. package/build/dist/Server/API/SlackAPI.js.map +1 -1
  80. package/build/dist/Server/API/UserOnCallLogTimelineAPI.js.map +1 -1
  81. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1740597525803-MigrationName.js +12 -0
  82. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1740597525803-MigrationName.js.map +1 -0
  83. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1740598793630-MigrationName.js +12 -0
  84. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1740598793630-MigrationName.js.map +1 -0
  85. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1741031019972-MigrationName.js +12 -0
  86. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1741031019972-MigrationName.js.map +1 -0
  87. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1741209339971-MigrationName.js +42 -0
  88. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1741209339971-MigrationName.js.map +1 -0
  89. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +8 -0
  90. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
  91. package/build/dist/Server/Middleware/SlackAuthorization.js +8 -2
  92. package/build/dist/Server/Middleware/SlackAuthorization.js.map +1 -1
  93. package/build/dist/Server/Services/AlertFeedService.js +2 -2
  94. package/build/dist/Server/Services/AlertFeedService.js.map +1 -1
  95. package/build/dist/Server/Services/AlertInternalNoteService.js +2 -2
  96. package/build/dist/Server/Services/AlertInternalNoteService.js.map +1 -1
  97. package/build/dist/Server/Services/AlertOwnerTeamService.js +4 -4
  98. package/build/dist/Server/Services/AlertOwnerTeamService.js.map +1 -1
  99. package/build/dist/Server/Services/AlertOwnerUserService.js +3 -3
  100. package/build/dist/Server/Services/AlertOwnerUserService.js.map +1 -1
  101. package/build/dist/Server/Services/AlertService.js +44 -19
  102. package/build/dist/Server/Services/AlertService.js.map +1 -1
  103. package/build/dist/Server/Services/AlertStateTimelineService.js +6 -16
  104. package/build/dist/Server/Services/AlertStateTimelineService.js.map +1 -1
  105. package/build/dist/Server/Services/IncidentFeedService.js +62 -2
  106. package/build/dist/Server/Services/IncidentFeedService.js.map +1 -1
  107. package/build/dist/Server/Services/IncidentInternalNoteService.js +35 -4
  108. package/build/dist/Server/Services/IncidentInternalNoteService.js.map +1 -1
  109. package/build/dist/Server/Services/IncidentOwnerTeamService.js +42 -4
  110. package/build/dist/Server/Services/IncidentOwnerTeamService.js.map +1 -1
  111. package/build/dist/Server/Services/IncidentOwnerUserService.js +43 -15
  112. package/build/dist/Server/Services/IncidentOwnerUserService.js.map +1 -1
  113. package/build/dist/Server/Services/IncidentPublicNoteService.js +32 -4
  114. package/build/dist/Server/Services/IncidentPublicNoteService.js.map +1 -1
  115. package/build/dist/Server/Services/IncidentService.js +221 -170
  116. package/build/dist/Server/Services/IncidentService.js.map +1 -1
  117. package/build/dist/Server/Services/IncidentStateService.js +14 -0
  118. package/build/dist/Server/Services/IncidentStateService.js.map +1 -1
  119. package/build/dist/Server/Services/IncidentStateTimelineService.js +31 -17
  120. package/build/dist/Server/Services/IncidentStateTimelineService.js.map +1 -1
  121. package/build/dist/Server/Services/MonitorStatusTimelineService.js +5 -15
  122. package/build/dist/Server/Services/MonitorStatusTimelineService.js.map +1 -1
  123. package/build/dist/Server/Services/OnCallDutyPolicyEscalationRuleService.js +1 -0
  124. package/build/dist/Server/Services/OnCallDutyPolicyEscalationRuleService.js.map +1 -1
  125. package/build/dist/Server/Services/OnCallDutyPolicyExecutionLogService.js +62 -7
  126. package/build/dist/Server/Services/OnCallDutyPolicyExecutionLogService.js.map +1 -1
  127. package/build/dist/Server/Services/OnCallDutyPolicyExecutionLogTimelineService.js +51 -5
  128. package/build/dist/Server/Services/OnCallDutyPolicyExecutionLogTimelineService.js.map +1 -1
  129. package/build/dist/Server/Services/OnCallDutyPolicyService.js +6 -0
  130. package/build/dist/Server/Services/OnCallDutyPolicyService.js.map +1 -1
  131. package/build/dist/Server/Services/ProjectUserService.js +106 -0
  132. package/build/dist/Server/Services/ProjectUserService.js.map +1 -0
  133. package/build/dist/Server/Services/ScheduledMaintenanceFeedService.js +2 -2
  134. package/build/dist/Server/Services/ScheduledMaintenanceFeedService.js.map +1 -1
  135. package/build/dist/Server/Services/ScheduledMaintenanceInternalNoteService.js +2 -2
  136. package/build/dist/Server/Services/ScheduledMaintenanceInternalNoteService.js.map +1 -1
  137. package/build/dist/Server/Services/ScheduledMaintenanceOwnerTeamService.js +4 -4
  138. package/build/dist/Server/Services/ScheduledMaintenanceOwnerTeamService.js.map +1 -1
  139. package/build/dist/Server/Services/ScheduledMaintenanceOwnerUserService.js +8 -16
  140. package/build/dist/Server/Services/ScheduledMaintenanceOwnerUserService.js.map +1 -1
  141. package/build/dist/Server/Services/ScheduledMaintenancePublicNoteService.js +2 -2
  142. package/build/dist/Server/Services/ScheduledMaintenancePublicNoteService.js.map +1 -1
  143. package/build/dist/Server/Services/ScheduledMaintenanceService.js +5 -2
  144. package/build/dist/Server/Services/ScheduledMaintenanceService.js.map +1 -1
  145. package/build/dist/Server/Services/ScheduledMaintenanceStateTimelineService.js +1 -1
  146. package/build/dist/Server/Services/ScheduledMaintenanceStateTimelineService.js.map +1 -1
  147. package/build/dist/Server/Services/StatusPageSubscriberService.js +3 -0
  148. package/build/dist/Server/Services/StatusPageSubscriberService.js.map +1 -1
  149. package/build/dist/Server/Services/TeamMemberService.js +17 -0
  150. package/build/dist/Server/Services/TeamMemberService.js.map +1 -1
  151. package/build/dist/Server/Services/UserNotificationRuleService.js +52 -0
  152. package/build/dist/Server/Services/UserNotificationRuleService.js.map +1 -1
  153. package/build/dist/Server/Services/UserOnCallLogService.js +1 -1
  154. package/build/dist/Server/Services/UserOnCallLogService.js.map +1 -1
  155. package/build/dist/Server/Services/UserService.js +23 -0
  156. package/build/dist/Server/Services/UserService.js.map +1 -1
  157. package/build/dist/Server/Services/WorkspaceNotificationRuleService.js +306 -84
  158. package/build/dist/Server/Services/WorkspaceNotificationRuleService.js.map +1 -1
  159. package/build/dist/Server/Services/WorkspaceUserAuthTokenService.js +18 -0
  160. package/build/dist/Server/Services/WorkspaceUserAuthTokenService.js.map +1 -1
  161. package/build/dist/Server/Utils/StartServer.js +4 -0
  162. package/build/dist/Server/Utils/StartServer.js.map +1 -1
  163. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Messages/Incident.js +148 -0
  164. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Messages/Incident.js.map +1 -0
  165. package/build/dist/Server/Utils/Workspace/Slack/Actions/ActionTypes.js +19 -0
  166. package/build/dist/Server/Utils/Workspace/Slack/Actions/ActionTypes.js.map +1 -0
  167. package/build/dist/Server/Utils/Workspace/Slack/Actions/Auth.js +167 -0
  168. package/build/dist/Server/Utils/Workspace/Slack/Actions/Auth.js.map +1 -0
  169. package/build/dist/Server/Utils/Workspace/Slack/Actions/Incident.js +727 -0
  170. package/build/dist/Server/Utils/Workspace/Slack/Actions/Incident.js.map +1 -0
  171. package/build/dist/Server/Utils/Workspace/Slack/Messages/Incident.js +82 -0
  172. package/build/dist/Server/Utils/Workspace/Slack/Messages/Incident.js.map +1 -0
  173. package/build/dist/Server/Utils/Workspace/Slack/Slack.js +397 -14
  174. package/build/dist/Server/Utils/Workspace/Slack/Slack.js.map +1 -1
  175. package/build/dist/Server/Utils/Workspace/Slack/app-manifest.json +18 -10
  176. package/build/dist/Server/Utils/Workspace/Workspace.js +126 -0
  177. package/build/dist/Server/Utils/Workspace/Workspace.js.map +1 -1
  178. package/build/dist/Server/Utils/Workspace/WorkspaceBase.js +69 -11
  179. package/build/dist/Server/Utils/Workspace/WorkspaceBase.js.map +1 -1
  180. package/build/dist/Server/Utils/Workspace/WorkspaceMessages/Incident.js +47 -0
  181. package/build/dist/Server/Utils/Workspace/WorkspaceMessages/Incident.js.map +1 -0
  182. package/build/dist/Types/Icon/IconProp.js +1 -0
  183. package/build/dist/Types/Icon/IconProp.js.map +1 -1
  184. package/build/dist/Types/Workspace/NotificationRules/NotificationRuleCondition.js +2 -1
  185. package/build/dist/Types/Workspace/NotificationRules/NotificationRuleCondition.js.map +1 -1
  186. package/build/dist/Types/Workspace/NotificationRules/NotificationRuleUtil.js +214 -120
  187. package/build/dist/Types/Workspace/NotificationRules/NotificationRuleUtil.js.map +1 -1
  188. package/build/dist/Types/Workspace/NotificationRules/NotificationRuleWorkspaceChannel.js +2 -0
  189. package/build/dist/Types/Workspace/NotificationRules/NotificationRuleWorkspaceChannel.js.map +1 -0
  190. package/build/dist/UI/Components/ComingSoon/ComingSoon.js +3 -2
  191. package/build/dist/UI/Components/ComingSoon/ComingSoon.js.map +1 -1
  192. package/build/dist/UI/Components/Forms/Fields/FormField.js +2 -2
  193. package/build/dist/UI/Components/Forms/Fields/FormField.js.map +1 -1
  194. package/build/dist/UI/Components/Icon/Icon.js +19 -2
  195. package/build/dist/UI/Components/Icon/Icon.js.map +1 -1
  196. package/build/dist/UI/Components/ModelTable/BaseModelTable.js +11 -0
  197. package/build/dist/UI/Components/ModelTable/BaseModelTable.js.map +1 -1
  198. package/build/dist/UI/Components/Radio/Radio.js +5 -2
  199. package/build/dist/UI/Components/Radio/Radio.js.map +1 -1
  200. package/build/dist/UI/Components/Table/TableCard.js +2 -2
  201. package/build/dist/UI/Components/Table/TableCard.js.map +1 -1
  202. package/package.json +3 -2
  203. package/Server/Utils/Workspace/Slack/app-manifest.example.json +0 -198
@@ -19,29 +19,36 @@
19
19
  {
20
20
  "name": "Create Scheduled Event",
21
21
  "type": "global",
22
- "callback_id": "create-scheduled-maintenance",
22
+ "callback_id": "/maintenance",
23
23
  "description": "Create a new scheduled event in OneUptime"
24
24
  },
25
25
  {
26
26
  "name": "Create New Incident",
27
27
  "type": "global",
28
- "callback_id": "create-incident",
28
+ "callback_id": "/incident",
29
29
  "description": "Creates a new incident in OneUptime"
30
30
  }
31
31
  ],
32
32
  "slash_commands": [
33
33
  {
34
- "command": "/oneuptime",
35
- "url": "https://local.genosyn.com/api/slack/command",
36
- "description": "OneUptime command",
37
- "usage_hint": "incident, scheduled event.",
34
+ "command": "/incident",
35
+ "url": "{{SERVER_URL}}/api/slack/interactive",
36
+ "description": "Create a new Incident in OneUptime",
37
+ "usage_hint": "/incident [incident title]",
38
+ "should_escape": false
39
+ },
40
+ {
41
+ "command": "/maintenance",
42
+ "url": "{{SERVER_URL}}/api/slack/interactive",
43
+ "description": "Create a new Scheduled Maintenance in OneUptime",
44
+ "usage_hint": "/maintenance [maintenance title]",
38
45
  "should_escape": false
39
46
  }
40
47
  ]
41
48
  },
42
49
  "oauth_config": {
43
50
  "redirect_urls": [
44
- "https://local.genosyn.com/api/slack/auth"
51
+ "{{SERVER_URL}}/api/slack/auth"
45
52
  ],
46
53
  "scopes": {
47
54
  "user": [
@@ -55,15 +62,16 @@
55
62
  "channels:read",
56
63
  "channels:write.invites",
57
64
  "channels:write.topic",
58
- "chat:write"
65
+ "chat:write",
66
+ "users:read"
59
67
  ]
60
68
  }
61
69
  },
62
70
  "settings": {
63
71
  "interactivity": {
64
72
  "is_enabled": true,
65
- "request_url": "https://local.genosyn.com/api/slack/interactive",
66
- "message_menu_options_url": "https://local.genosyn.com/api/slack/options-load"
73
+ "request_url": "{{SERVER_URL}}/api/slack/interactive",
74
+ "message_menu_options_url": "{{SERVER_URL}}/api/slack/options-load"
67
75
  },
68
76
  "org_deploy_enabled": true,
69
77
  "socket_mode_enabled": false,
@@ -1,10 +1,98 @@
1
1
  import WorkspaceType from "../../../Types/Workspace/WorkspaceType";
2
- import WorkspaceBase from "./WorkspaceBase";
2
+ import WorkspaceBase, { WorkspaceSendMessageResponse } from "./WorkspaceBase";
3
3
  import SlackWorkspace from "./Slack/Slack";
4
4
  import MicrosoftTeamsWorkspace from "./MicrosoftTeams/MicrosoftTeams";
5
5
  import BadDataException from "../../../Types/Exception/BadDataException";
6
+ import ObjectID from "../../../Types/ObjectID";
7
+ import WorkspaceMessagePayload, {
8
+ WorkspacePayloadMarkdown,
9
+ } from "../../../Types/Workspace/WorkspaceMessagePayload";
10
+ import logger from "../Logger";
11
+ import WorkspaceProjectAuthTokenService from "../../Services/WorkspaceProjectAuthTokenService";
12
+ import WorkspaceProjectAuthToken, {
13
+ SlackMiscData,
14
+ } from "../../../Models/DatabaseModels/WorkspaceProjectAuthToken";
15
+ import { MessageBlocksByWorkspaceType } from "../../Services/WorkspaceNotificationRuleService";
16
+ import WorkspaceUserAuthToken from "../../../Models/DatabaseModels/WorkspaceUserAuthToken";
17
+ import WorkspaceUserAuthTokenService from "../../Services/WorkspaceUserAuthTokenService";
18
+ import UserService from "../../Services/UserService";
6
19
 
7
20
  export default class WorkspaceUtil {
21
+ public static async getMessageBlocksByMarkdown(data: {
22
+ projectId: ObjectID;
23
+ // this is oneuptime user id.
24
+ userId: ObjectID | undefined;
25
+ markdown: string;
26
+ }): Promise<Array<MessageBlocksByWorkspaceType>> {
27
+ const workspaceTypes: Array<WorkspaceType> = this.getAllWorkspaceTypes();
28
+
29
+ const messageBlocksByWorkspaceType: Array<MessageBlocksByWorkspaceType> =
30
+ [];
31
+
32
+ for (const workspaceType of workspaceTypes) {
33
+ let userStringToAppend: string = "";
34
+
35
+ if (data.userId) {
36
+ const workspaceUserToken: WorkspaceUserAuthToken | null =
37
+ await WorkspaceUserAuthTokenService.getUserAuth({
38
+ userId: data.userId,
39
+ workspaceType: workspaceType,
40
+ projectId: data.projectId,
41
+ });
42
+
43
+ if (workspaceUserToken && workspaceUserToken.workspaceUserId) {
44
+ const projectAuthToken: WorkspaceProjectAuthToken | null =
45
+ await WorkspaceProjectAuthTokenService.getProjectAuth({
46
+ projectId: data.projectId,
47
+ workspaceType: workspaceType,
48
+ });
49
+
50
+ if (!projectAuthToken || !projectAuthToken.authToken) {
51
+ userStringToAppend = "";
52
+ } else {
53
+ const workspaceUsername: string =
54
+ await this.getUserNameFromWorkspace({
55
+ userId: workspaceUserToken.workspaceUserId,
56
+ workspaceType: workspaceType,
57
+ authToken: projectAuthToken.authToken,
58
+ });
59
+
60
+ userStringToAppend = `@${workspaceUsername} `;
61
+ }
62
+ } else {
63
+ const userstring: string = await UserService.getUserMarkdownString({
64
+ userId: data.userId,
65
+ projectId: data.projectId,
66
+ });
67
+
68
+ userStringToAppend = `${userstring} `;
69
+ }
70
+ }
71
+
72
+ messageBlocksByWorkspaceType.push({
73
+ workspaceType: workspaceType,
74
+ messageBlocks: [
75
+ {
76
+ _type: "WorkspacePayloadMarkdown",
77
+ text: userStringToAppend + data.markdown,
78
+ } as WorkspacePayloadMarkdown,
79
+ ],
80
+ });
81
+ }
82
+
83
+ return messageBlocksByWorkspaceType;
84
+ }
85
+
86
+ public static getAllWorkspaceTypes(): Array<WorkspaceType> {
87
+ const workspaceTypes: Array<WorkspaceType> = [];
88
+
89
+ for (const workspaceType in WorkspaceType) {
90
+ workspaceTypes.push(workspaceType as WorkspaceType);
91
+ }
92
+
93
+ return workspaceTypes;
94
+ }
95
+
8
96
  public static getWorkspaceTypeUtil(
9
97
  workspaceType: WorkspaceType,
10
98
  ): typeof WorkspaceBase {
@@ -20,4 +108,109 @@ export default class WorkspaceUtil {
20
108
  `Workspace type ${workspaceType} is not supported`,
21
109
  );
22
110
  }
111
+
112
+ public static async getUserNameFromWorkspace(data: {
113
+ userId: string;
114
+ workspaceType: WorkspaceType;
115
+ authToken: string;
116
+ }): Promise<string> {
117
+ const userName: string = await WorkspaceUtil.getWorkspaceTypeUtil(
118
+ data.workspaceType,
119
+ ).getUsernameFromUserId({
120
+ userId: data.userId,
121
+ authToken: data.authToken,
122
+ });
123
+
124
+ return userName;
125
+ }
126
+
127
+ public static async postMessageToAllWorkspaceChannelsAsBot(data: {
128
+ projectId: ObjectID;
129
+ messagePayloadsByWorkspace: Array<WorkspaceMessagePayload>;
130
+ }): Promise<Array<WorkspaceSendMessageResponse>> {
131
+ logger.debug("postToWorkspaceChannels called with data:");
132
+ logger.debug(data);
133
+
134
+ const responses: Array<WorkspaceSendMessageResponse> = [];
135
+
136
+ for (const messagePayloadByWorkspace of data.messagePayloadsByWorkspace) {
137
+ const projectAuthToken: WorkspaceProjectAuthToken | null =
138
+ await WorkspaceProjectAuthTokenService.getProjectAuth({
139
+ projectId: data.projectId,
140
+ workspaceType: messagePayloadByWorkspace.workspaceType,
141
+ });
142
+
143
+ if (!projectAuthToken) {
144
+ responses.push({
145
+ workspaceType: messagePayloadByWorkspace.workspaceType,
146
+ threads: [],
147
+ });
148
+
149
+ continue;
150
+ }
151
+
152
+ const workspaceType: WorkspaceType =
153
+ messagePayloadByWorkspace.workspaceType;
154
+
155
+ let botUserId: string | undefined = undefined;
156
+
157
+ if (workspaceType === WorkspaceType.Slack) {
158
+ botUserId = (projectAuthToken.miscData as SlackMiscData).botUserId;
159
+ }
160
+
161
+ if (!botUserId) {
162
+ responses.push({
163
+ workspaceType: workspaceType,
164
+ threads: [],
165
+ });
166
+ continue;
167
+ }
168
+
169
+ if (!projectAuthToken.authToken) {
170
+ responses.push({
171
+ workspaceType: workspaceType,
172
+ threads: [],
173
+ });
174
+ continue;
175
+ }
176
+
177
+ const result: WorkspaceSendMessageResponse =
178
+ await WorkspaceUtil.getWorkspaceTypeUtil(workspaceType).sendMessage({
179
+ userId: botUserId,
180
+ authToken: projectAuthToken.authToken,
181
+ workspaceMessagePayload: messagePayloadByWorkspace,
182
+ });
183
+
184
+ responses.push(result);
185
+ }
186
+
187
+ logger.debug("Message posted to workspace channels successfully");
188
+ logger.debug("Returning thread IDs");
189
+ logger.debug(responses);
190
+
191
+ return responses;
192
+ }
193
+
194
+ public static async postToWorkspaceChannels(data: {
195
+ workspaceUserId: string;
196
+ projectOrUserAuthTokenForWorkspace: string;
197
+ workspaceType: WorkspaceType;
198
+ workspaceMessagePayload: WorkspaceMessagePayload;
199
+ }): Promise<WorkspaceSendMessageResponse> {
200
+ logger.debug("postToWorkspaceChannels called with data:");
201
+ logger.debug(data);
202
+
203
+ const result: WorkspaceSendMessageResponse =
204
+ await WorkspaceUtil.getWorkspaceTypeUtil(data.workspaceType).sendMessage({
205
+ userId: data.workspaceUserId,
206
+ workspaceMessagePayload: data.workspaceMessagePayload,
207
+ authToken: data.projectOrUserAuthTokenForWorkspace,
208
+ });
209
+
210
+ logger.debug("Message posted to workspace channels successfully");
211
+ logger.debug("Returning thread IDs");
212
+ logger.debug(result);
213
+
214
+ return result;
215
+ }
23
216
  }
@@ -5,15 +5,32 @@ import NotImplementedException from "../../../Types/Exception/NotImplementedExce
5
5
  import { JSONObject } from "../../../Types/JSON";
6
6
  import WorkspaceChannelInvitationPayload from "../../../Types/Workspace/WorkspaceChannelInvitationPayload";
7
7
  import WorkspaceMessagePayload, {
8
+ WorkspaceCheckboxBlock,
9
+ WorkspaceDropdownBlock,
10
+ WorkspaceMessageBlock,
8
11
  WorkspaceMessagePayloadButton,
12
+ WorkspaceModalBlock,
9
13
  WorkspacePayloadButtons,
10
14
  WorkspacePayloadHeader,
15
+ WorkspacePayloadImage,
11
16
  WorkspacePayloadMarkdown,
17
+ WorkspaceTextAreaBlock,
18
+ WorkspaceTextBoxBlock,
12
19
  } from "../../../Types/Workspace/WorkspaceMessagePayload";
13
20
  import WorkspaceType from "../../../Types/Workspace/WorkspaceType";
14
21
  import logger from "../Logger";
15
22
  import URL from "Common/Types/API/URL";
16
23
 
24
+ export interface WorkspaceThread {
25
+ channel: WorkspaceChannel;
26
+ threadId: string;
27
+ }
28
+
29
+ export interface WorkspaceSendMessageResponse {
30
+ threads: Array<WorkspaceThread>;
31
+ workspaceType: WorkspaceType;
32
+ }
33
+
17
34
  export interface WorkspaceChannel {
18
35
  id: string;
19
36
  name: string;
@@ -21,6 +38,42 @@ export interface WorkspaceChannel {
21
38
  }
22
39
 
23
40
  export default class WorkspaceBase {
41
+ public static async isUserInDirectMessageChannel(_data: {
42
+ authToken: string;
43
+ userId: string;
44
+ directMessageChannelId: string;
45
+ }): Promise<boolean> {
46
+ throw new NotImplementedException();
47
+ }
48
+ public static async getUsernameFromUserId(_data: {
49
+ authToken: string;
50
+ userId: string;
51
+ }): Promise<string> {
52
+ throw new NotImplementedException();
53
+ }
54
+
55
+ public static async showModalToUser(_data: {
56
+ authToken: string;
57
+ triggerId: string;
58
+ modalBlock: WorkspaceModalBlock;
59
+ }): Promise<void> {
60
+ throw new NotImplementedException();
61
+ }
62
+
63
+ public static getCheckboxBlock(_data: {
64
+ payloadCheckboxBlock: WorkspaceCheckboxBlock;
65
+ }): JSONObject {
66
+ throw new NotImplementedException();
67
+ }
68
+
69
+ public static sendDirectMessageToUser(_data: {
70
+ authToken: string;
71
+ workspaceUserId: string;
72
+ messageBlocks: Array<WorkspaceMessageBlock>;
73
+ }): Promise<void> {
74
+ throw new NotImplementedException();
75
+ }
76
+
24
77
  public static async joinChannel(_data: {
25
78
  authToken: string;
26
79
  channelId: string;
@@ -30,9 +83,9 @@ export default class WorkspaceBase {
30
83
 
31
84
  public static async sendPayloadBlocksToChannel(_data: {
32
85
  authToken: string;
33
- channelId: string;
86
+ workspaceChannel: WorkspaceChannel;
34
87
  blocks: Array<JSONObject>;
35
- }): Promise<void> {
88
+ }): Promise<WorkspaceThread> {
36
89
  throw new NotImplementedException();
37
90
  }
38
91
 
@@ -97,7 +150,7 @@ export default class WorkspaceBase {
97
150
  workspaceMessagePayload: WorkspaceMessagePayload;
98
151
  authToken: string; // which auth token should we use to send.
99
152
  userId: string;
100
- }): Promise<void> {
153
+ }): Promise<WorkspaceSendMessageResponse> {
101
154
  throw new NotImplementedException();
102
155
  }
103
156
 
@@ -127,6 +180,10 @@ export default class WorkspaceBase {
127
180
  throw new NotImplementedException();
128
181
  }
129
182
 
183
+ public static getDividerBlock(): JSONObject {
184
+ throw new NotImplementedException();
185
+ }
186
+
130
187
  public static getMarkdownBlock(_data: {
131
188
  payloadMarkdownBlock: WorkspacePayloadMarkdown;
132
189
  }): JSONObject {
@@ -139,12 +196,13 @@ export default class WorkspaceBase {
139
196
  throw new NotImplementedException();
140
197
  }
141
198
 
142
- public static getBlocksFromWorkspaceMessagePayload(
143
- data: WorkspaceMessagePayload,
144
- ): Array<JSONObject> {
199
+ public static getBlocksFromWorkspaceMessagePayload(data: {
200
+ messageBlocks: Array<WorkspaceMessageBlock>;
201
+ }): Array<JSONObject> {
202
+ const { messageBlocks } = data;
203
+
145
204
  const blocks: Array<JSONObject> = [];
146
- const buttons: Array<JSONObject> = [];
147
- for (const block of data.messageBlocks) {
205
+ for (const block of messageBlocks) {
148
206
  switch (block._type) {
149
207
  case "WorkspacePayloadHeader":
150
208
  blocks.push(
@@ -160,18 +218,50 @@ export default class WorkspaceBase {
160
218
  }),
161
219
  );
162
220
  break;
221
+ case "WorkspacePayloadDivider":
222
+ blocks.push(this.getDividerBlock());
223
+ break;
163
224
  case "WorkspacePayloadButtons":
164
- for (const button of (block as WorkspacePayloadButtons).buttons) {
165
- buttons.push(
166
- this.getButtonBlock({
167
- payloadButtonBlock: button,
168
- }),
169
- );
170
- }
171
- blocks.push({
172
- type: "actions",
173
- elements: buttons,
174
- });
225
+ blocks.push(
226
+ this.getButtonsBlock({
227
+ payloadButtonsBlock: block as WorkspacePayloadButtons,
228
+ }),
229
+ );
230
+ break;
231
+ case "WorkspaceTextAreaBlock":
232
+ blocks.push(
233
+ this.getTextAreaBlock({
234
+ payloadTextAreaBlock: block as WorkspaceTextAreaBlock,
235
+ }),
236
+ );
237
+ break;
238
+ case "WorkspaceTextBoxBlock":
239
+ blocks.push(
240
+ this.getTextBoxBlock({
241
+ payloadTextBoxBlock: block as WorkspaceTextBoxBlock,
242
+ }),
243
+ );
244
+ break;
245
+ case "WorkspacePayloadImage":
246
+ blocks.push(
247
+ this.getImageBlock({
248
+ payloadImageBlock: block as WorkspacePayloadImage,
249
+ }),
250
+ );
251
+ break;
252
+ case "WorkspaceDropdownBlock":
253
+ blocks.push(
254
+ this.getDropdownBlock({
255
+ payloadDropdownBlock: block as WorkspaceDropdownBlock,
256
+ }),
257
+ );
258
+ break;
259
+ case "WorkspaceModalBlock":
260
+ blocks.push(
261
+ this.getModalBlock({
262
+ payloadModalBlock: block as WorkspaceModalBlock,
263
+ }),
264
+ );
175
265
  break;
176
266
  default:
177
267
  logger.error("Unknown block type: " + block._type);
@@ -181,6 +271,42 @@ export default class WorkspaceBase {
181
271
  return blocks;
182
272
  }
183
273
 
274
+ public static getTextAreaBlock(_data: {
275
+ payloadTextAreaBlock: WorkspaceTextAreaBlock;
276
+ }): JSONObject {
277
+ throw new NotImplementedException();
278
+ }
279
+
280
+ public static getTextBoxBlock(_data: {
281
+ payloadTextBoxBlock: WorkspaceTextBoxBlock;
282
+ }): JSONObject {
283
+ throw new NotImplementedException();
284
+ }
285
+
286
+ public static getImageBlock(_data: {
287
+ payloadImageBlock: WorkspacePayloadImage;
288
+ }): JSONObject {
289
+ throw new NotImplementedException();
290
+ }
291
+
292
+ public static getDropdownBlock(_data: {
293
+ payloadDropdownBlock: WorkspaceDropdownBlock;
294
+ }): JSONObject {
295
+ throw new NotImplementedException();
296
+ }
297
+
298
+ public static getModalBlock(_data: {
299
+ payloadModalBlock: WorkspaceModalBlock;
300
+ }): JSONObject {
301
+ throw new NotImplementedException();
302
+ }
303
+
304
+ public static getButtonsBlock(_data: {
305
+ payloadButtonsBlock: WorkspacePayloadButtons;
306
+ }): JSONObject {
307
+ throw new NotImplementedException();
308
+ }
309
+
184
310
  public static async sendMessageToChannelViaIncomingWebhook(_data: {
185
311
  url: URL;
186
312
  text: string;
@@ -0,0 +1,68 @@
1
+ import ObjectID from "../../../../Types/ObjectID";
2
+ import NotificationRuleEventType from "../../../../Types/Workspace/NotificationRules/EventType";
3
+ import NotificationRuleWorkspaceChannel from "../../../../Types/Workspace/NotificationRules/NotificationRuleWorkspaceChannel";
4
+ import { WorkspaceMessageBlock } from "../../../../Types/Workspace/WorkspaceMessagePayload";
5
+ import WorkspaceType from "../../../../Types/Workspace/WorkspaceType";
6
+ import WorkspaceNotificationRuleService, {
7
+ MessageBlocksByWorkspaceType,
8
+ } from "../../../Services/WorkspaceNotificationRuleService";
9
+ import logger from "../../Logger";
10
+ import SlackIncidentMessages from "../Slack/Messages/Incident";
11
+
12
+ export default class IncidentWorkspaceMessages {
13
+ public static async createChannelsAndInviteUsersToChannels(data: {
14
+ projectId: ObjectID;
15
+ incidentId: ObjectID;
16
+ incidentNumber: number;
17
+ }): Promise<{
18
+ channelsCreated: NotificationRuleWorkspaceChannel[];
19
+ } | null> {
20
+ try {
21
+ // we will notify the workspace about the incident creation with the bot tokken which is in WorkspaceProjectAuth Table.
22
+ return await WorkspaceNotificationRuleService.createChannelsAndInviteUsersToChannelsBasedOnRules(
23
+ {
24
+ projectId: data.projectId,
25
+ notificationFor: {
26
+ incidentId: data.incidentId,
27
+ },
28
+ notificationRuleEventType: NotificationRuleEventType.Incident,
29
+ channelNameSiffix: data.incidentNumber.toString(),
30
+ },
31
+ );
32
+ } catch (err) {
33
+ // log the error and continue.
34
+ logger.error(err);
35
+ return null;
36
+ }
37
+ }
38
+
39
+ public static async getIncidentCreateMessageBlocks(data: {
40
+ incidentId: ObjectID;
41
+ projectId: ObjectID;
42
+ }): Promise<Array<MessageBlocksByWorkspaceType>> {
43
+ const { incidentId, projectId } = data;
44
+
45
+ const slackBlocks: WorkspaceMessageBlock[] =
46
+ await SlackIncidentMessages.getIncidentCreateMessageBlocks({
47
+ incidentId: incidentId,
48
+ projectId: projectId!,
49
+ });
50
+
51
+ const microsoftTeamsBlocks: WorkspaceMessageBlock[] =
52
+ await SlackIncidentMessages.getIncidentCreateMessageBlocks({
53
+ incidentId: incidentId,
54
+ projectId: projectId!,
55
+ });
56
+
57
+ return [
58
+ {
59
+ workspaceType: WorkspaceType.Slack,
60
+ messageBlocks: slackBlocks,
61
+ },
62
+ {
63
+ workspaceType: WorkspaceType.MicrosoftTeams,
64
+ messageBlocks: microsoftTeamsBlocks,
65
+ },
66
+ ];
67
+ }
68
+ }
@@ -5,6 +5,7 @@ enum IconProp {
5
5
  Automation = "Automation",
6
6
  Workflow = "Workflow",
7
7
  TableCells = "TableCells",
8
+ MicrosoftTeams = "MicrosoftTeams",
8
9
  Layout = "Layout",
9
10
  Compass = "Compass",
10
11
  ShieldCheck = "ShieldCheck",
@@ -40,6 +40,7 @@ export enum ConditionType {
40
40
  LessThan = "Less Than",
41
41
  GreaterThanOrEqualTo = "Greater Than Or Equal To",
42
42
  LessThanOrEqualTo = "Less Than Or Equal To",
43
+ Contains = "Contains",
43
44
  ContainsAny = "Contains Any",
44
45
  NotContains = "Not Contains",
45
46
  StartsWith = "Starts With",
@@ -321,7 +322,7 @@ export class NotificationRuleConditionUtil {
321
322
  return [
322
323
  ConditionType.EqualTo,
323
324
  ConditionType.NotEqualTo,
324
- ConditionType.ContainsAny,
325
+ ConditionType.Contains,
325
326
  ConditionType.NotContains,
326
327
  ConditionType.StartsWith,
327
328
  ConditionType.EndsWith,