@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.
Files changed (79) hide show
  1. package/Models/DatabaseModels/GlobalConfig.ts +56 -0
  2. package/Models/DatabaseModels/Index.ts +4 -0
  3. package/Models/DatabaseModels/Project.ts +30 -0
  4. package/Models/DatabaseModels/TelegramLog.ts +1025 -0
  5. package/Models/DatabaseModels/UserNotificationRule.ts +49 -0
  6. package/Models/DatabaseModels/UserNotificationSetting.ts +17 -0
  7. package/Models/DatabaseModels/UserOnCallLogTimeline.ts +48 -0
  8. package/Models/DatabaseModels/UserTelegram.ts +312 -0
  9. package/Server/API/UserTelegramAPI.ts +167 -0
  10. package/Server/Infrastructure/Postgres/SchemaMigrations/1776761171349-MigrationName.ts +325 -0
  11. package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +2 -0
  12. package/Server/Services/Index.ts +6 -0
  13. package/Server/Services/TelegramLogService.ts +15 -0
  14. package/Server/Services/TelegramService.ts +139 -0
  15. package/Server/Services/UserNotificationRuleService.ts +350 -1
  16. package/Server/Services/UserNotificationSettingService.ts +114 -0
  17. package/Server/Services/UserTelegramService.ts +140 -0
  18. package/Server/Utils/Monitor/MonitorResource.ts +29 -15
  19. package/Server/Utils/Monitor/MonitorTemplateUtil.ts +29 -16
  20. package/Tests/Types/Date.test.ts +158 -0
  21. package/Types/Date.ts +12 -3
  22. package/Types/Icon/IconProp.ts +1 -0
  23. package/Types/Permission.ts +11 -0
  24. package/Types/Telegram/TelegramMessage.ts +9 -0
  25. package/Types/TelegramStatus.ts +14 -0
  26. package/UI/Components/Icon/Icon.tsx +15 -0
  27. package/build/dist/Models/DatabaseModels/GlobalConfig.js +59 -0
  28. package/build/dist/Models/DatabaseModels/GlobalConfig.js.map +1 -1
  29. package/build/dist/Models/DatabaseModels/Index.js +4 -0
  30. package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
  31. package/build/dist/Models/DatabaseModels/Project.js +32 -0
  32. package/build/dist/Models/DatabaseModels/Project.js.map +1 -1
  33. package/build/dist/Models/DatabaseModels/TelegramLog.js +1056 -0
  34. package/build/dist/Models/DatabaseModels/TelegramLog.js.map +1 -0
  35. package/build/dist/Models/DatabaseModels/UserNotificationRule.js +49 -0
  36. package/build/dist/Models/DatabaseModels/UserNotificationRule.js.map +1 -1
  37. package/build/dist/Models/DatabaseModels/UserNotificationSetting.js +19 -0
  38. package/build/dist/Models/DatabaseModels/UserNotificationSetting.js.map +1 -1
  39. package/build/dist/Models/DatabaseModels/UserOnCallLogTimeline.js +48 -0
  40. package/build/dist/Models/DatabaseModels/UserOnCallLogTimeline.js.map +1 -1
  41. package/build/dist/Models/DatabaseModels/UserTelegram.js +331 -0
  42. package/build/dist/Models/DatabaseModels/UserTelegram.js.map +1 -0
  43. package/build/dist/Server/API/UserTelegramAPI.js +99 -0
  44. package/build/dist/Server/API/UserTelegramAPI.js.map +1 -0
  45. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1776761171349-MigrationName.js +116 -0
  46. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1776761171349-MigrationName.js.map +1 -0
  47. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +2 -0
  48. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
  49. package/build/dist/Server/Services/Index.js +6 -0
  50. package/build/dist/Server/Services/Index.js.map +1 -1
  51. package/build/dist/Server/Services/TelegramLogService.js +13 -0
  52. package/build/dist/Server/Services/TelegramLogService.js.map +1 -0
  53. package/build/dist/Server/Services/TelegramService.js +100 -0
  54. package/build/dist/Server/Services/TelegramService.js.map +1 -0
  55. package/build/dist/Server/Services/UserNotificationRuleService.js +272 -21
  56. package/build/dist/Server/Services/UserNotificationRuleService.js.map +1 -1
  57. package/build/dist/Server/Services/UserNotificationSettingService.js +94 -0
  58. package/build/dist/Server/Services/UserNotificationSettingService.js.map +1 -1
  59. package/build/dist/Server/Services/UserTelegramService.js +133 -0
  60. package/build/dist/Server/Services/UserTelegramService.js.map +1 -0
  61. package/build/dist/Server/Utils/Monitor/MonitorResource.js +25 -12
  62. package/build/dist/Server/Utils/Monitor/MonitorResource.js.map +1 -1
  63. package/build/dist/Server/Utils/Monitor/MonitorTemplateUtil.js +24 -12
  64. package/build/dist/Server/Utils/Monitor/MonitorTemplateUtil.js.map +1 -1
  65. package/build/dist/Tests/Types/Date.test.js +96 -0
  66. package/build/dist/Tests/Types/Date.test.js.map +1 -1
  67. package/build/dist/Types/Date.js +9 -3
  68. package/build/dist/Types/Date.js.map +1 -1
  69. package/build/dist/Types/Icon/IconProp.js +1 -0
  70. package/build/dist/Types/Icon/IconProp.js.map +1 -1
  71. package/build/dist/Types/Permission.js +10 -0
  72. package/build/dist/Types/Permission.js.map +1 -1
  73. package/build/dist/Types/Telegram/TelegramMessage.js +2 -0
  74. package/build/dist/Types/Telegram/TelegramMessage.js.map +1 -0
  75. package/build/dist/Types/TelegramStatus.js +15 -0
  76. package/build/dist/Types/TelegramStatus.js.map +1 -0
  77. package/build/dist/UI/Components/Icon/Icon.js +5 -0
  78. package/build/dist/UI/Components/Icon/Icon.js.map +1 -1
  79. package/package.json +2 -2
@@ -16,6 +16,7 @@ import IncidentSeverityService from "./IncidentSeverityService";
16
16
  import MailService from "./MailService";
17
17
  import ShortLinkService from "./ShortLinkService";
18
18
  import SmsService from "./SmsService";
19
+ import TelegramService from "./TelegramService";
19
20
  import WhatsAppService from "./WhatsAppService";
20
21
  import UserEmailService from "./UserEmailService";
21
22
  import UserOnCallLogService from "./UserOnCallLogService";
@@ -60,7 +61,7 @@ export class Service extends DatabaseService {
60
61
  }
61
62
  async executeNotificationRuleItem(userNotificationRuleId, options) {
62
63
  // get user notification log and see if this rule has already been executed. If so then skip.
63
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21;
64
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24;
64
65
  const userOnCallLog = await UserOnCallLogService.findOneById({
65
66
  id: options.userNotificationLogId,
66
67
  props: {
@@ -110,6 +111,11 @@ export class Service extends DatabaseService {
110
111
  phone: true,
111
112
  isVerified: true,
112
113
  },
114
+ userTelegram: {
115
+ telegramChatId: true,
116
+ telegramUserHandle: true,
117
+ isVerified: true,
118
+ },
113
119
  userEmail: {
114
120
  email: true,
115
121
  isVerified: true,
@@ -672,16 +678,155 @@ export class Service extends DatabaseService {
672
678
  },
673
679
  });
674
680
  }
681
+ // send Telegram.
682
+ if (((_3 = notificationRuleItem.userTelegram) === null || _3 === void 0 ? void 0 : _3.telegramChatId) &&
683
+ ((_4 = notificationRuleItem.userTelegram) === null || _4 === void 0 ? void 0 : _4.isVerified)) {
684
+ if (options.userNotificationEventType ===
685
+ UserNotificationEventType.AlertCreated &&
686
+ alert) {
687
+ logTimelineItem.status = UserNotificationStatus.Sending;
688
+ logTimelineItem.statusMessage = `Sending Telegram message.`;
689
+ logTimelineItem.userTelegramId = notificationRuleItem.userTelegram.id;
690
+ const updatedLog = await UserOnCallLogTimelineService.create({
691
+ data: logTimelineItem,
692
+ props: {
693
+ isRoot: true,
694
+ },
695
+ });
696
+ const telegramMessage = {
697
+ to: notificationRuleItem.userTelegram.telegramChatId,
698
+ body: await this.generateTelegramBodyForAlertCreated(alert, updatedLog.id),
699
+ parseMode: "HTML",
700
+ disableWebPagePreview: true,
701
+ };
702
+ TelegramService.sendTelegramMessage(telegramMessage, {
703
+ projectId: alert.projectId,
704
+ alertId: alert.id,
705
+ userOnCallLogTimelineId: updatedLog.id,
706
+ userId: notificationRuleItem.userId,
707
+ onCallPolicyId: options.onCallPolicyId,
708
+ onCallPolicyEscalationRuleId: options.onCallPolicyEscalationRuleId,
709
+ teamId: options.userBelongsToTeamId,
710
+ onCallDutyPolicyExecutionLogTimelineId: options.onCallDutyPolicyExecutionLogTimelineId,
711
+ onCallScheduleId: options.onCallScheduleId,
712
+ }).catch(async (err) => {
713
+ await UserOnCallLogTimelineService.updateOneById({
714
+ id: updatedLog.id,
715
+ data: {
716
+ status: UserNotificationStatus.Error,
717
+ statusMessage: err.message || "Error sending Telegram message.",
718
+ },
719
+ props: {
720
+ isRoot: true,
721
+ },
722
+ });
723
+ });
724
+ }
725
+ if (options.userNotificationEventType ===
726
+ UserNotificationEventType.IncidentCreated &&
727
+ incident) {
728
+ logTimelineItem.status = UserNotificationStatus.Sending;
729
+ logTimelineItem.statusMessage = `Sending Telegram message.`;
730
+ logTimelineItem.userTelegramId = notificationRuleItem.userTelegram.id;
731
+ const updatedLog = await UserOnCallLogTimelineService.create({
732
+ data: logTimelineItem,
733
+ props: {
734
+ isRoot: true,
735
+ },
736
+ });
737
+ const telegramMessage = {
738
+ to: notificationRuleItem.userTelegram.telegramChatId,
739
+ body: await this.generateTelegramBodyForIncidentCreated(incident, updatedLog.id),
740
+ parseMode: "HTML",
741
+ disableWebPagePreview: true,
742
+ };
743
+ TelegramService.sendTelegramMessage(telegramMessage, {
744
+ projectId: incident.projectId,
745
+ incidentId: incident.id,
746
+ userOnCallLogTimelineId: updatedLog.id,
747
+ userId: notificationRuleItem.userId,
748
+ onCallPolicyId: options.onCallPolicyId,
749
+ onCallPolicyEscalationRuleId: options.onCallPolicyEscalationRuleId,
750
+ teamId: options.userBelongsToTeamId,
751
+ onCallDutyPolicyExecutionLogTimelineId: options.onCallDutyPolicyExecutionLogTimelineId,
752
+ onCallScheduleId: options.onCallScheduleId,
753
+ }).catch(async (err) => {
754
+ await UserOnCallLogTimelineService.updateOneById({
755
+ id: updatedLog.id,
756
+ data: {
757
+ status: UserNotificationStatus.Error,
758
+ statusMessage: err.message || "Error sending Telegram message.",
759
+ },
760
+ props: {
761
+ isRoot: true,
762
+ },
763
+ });
764
+ });
765
+ }
766
+ if (options.userNotificationEventType ===
767
+ UserNotificationEventType.AlertEpisodeCreated &&
768
+ alertEpisode) {
769
+ logTimelineItem.status = UserNotificationStatus.Sending;
770
+ logTimelineItem.statusMessage = `Sending Telegram message.`;
771
+ logTimelineItem.userTelegramId = notificationRuleItem.userTelegram.id;
772
+ const updatedLog = await UserOnCallLogTimelineService.create({
773
+ data: logTimelineItem,
774
+ props: {
775
+ isRoot: true,
776
+ },
777
+ });
778
+ const telegramMessage = {
779
+ to: notificationRuleItem.userTelegram.telegramChatId,
780
+ body: await this.generateTelegramBodyForAlertEpisodeCreated(alertEpisode, updatedLog.id),
781
+ parseMode: "HTML",
782
+ disableWebPagePreview: true,
783
+ };
784
+ TelegramService.sendTelegramMessage(telegramMessage, {
785
+ projectId: alertEpisode.projectId,
786
+ alertEpisodeId: alertEpisode.id,
787
+ userOnCallLogTimelineId: updatedLog.id,
788
+ userId: notificationRuleItem.userId,
789
+ onCallPolicyId: options.onCallPolicyId,
790
+ onCallPolicyEscalationRuleId: options.onCallPolicyEscalationRuleId,
791
+ teamId: options.userBelongsToTeamId,
792
+ onCallDutyPolicyExecutionLogTimelineId: options.onCallDutyPolicyExecutionLogTimelineId,
793
+ onCallScheduleId: options.onCallScheduleId,
794
+ }).catch(async (err) => {
795
+ await UserOnCallLogTimelineService.updateOneById({
796
+ id: updatedLog.id,
797
+ data: {
798
+ status: UserNotificationStatus.Error,
799
+ statusMessage: err.message || "Error sending Telegram message.",
800
+ },
801
+ props: {
802
+ isRoot: true,
803
+ },
804
+ });
805
+ });
806
+ }
807
+ }
808
+ if (notificationRuleItem.userTelegram &&
809
+ !((_5 = notificationRuleItem.userTelegram) === null || _5 === void 0 ? void 0 : _5.isVerified)) {
810
+ logTimelineItem.status = UserNotificationStatus.Error;
811
+ logTimelineItem.statusMessage = `Telegram message not sent because the Telegram account is not verified.`;
812
+ logTimelineItem.userTelegramId = notificationRuleItem.userTelegram.id;
813
+ await UserOnCallLogTimelineService.create({
814
+ data: logTimelineItem,
815
+ props: {
816
+ isRoot: true,
817
+ },
818
+ });
819
+ }
675
820
  // send call.
676
- if (((_3 = notificationRuleItem.userCall) === null || _3 === void 0 ? void 0 : _3.phone) &&
677
- ((_4 = notificationRuleItem.userCall) === null || _4 === void 0 ? void 0 : _4.isVerified)) {
821
+ if (((_6 = notificationRuleItem.userCall) === null || _6 === void 0 ? void 0 : _6.phone) &&
822
+ ((_7 = notificationRuleItem.userCall) === null || _7 === void 0 ? void 0 : _7.isVerified)) {
678
823
  // send call for alert
679
824
  if (options.userNotificationEventType ===
680
825
  UserNotificationEventType.AlertCreated &&
681
826
  alert) {
682
827
  // create an error log.
683
828
  logTimelineItem.status = UserNotificationStatus.Sending;
684
- logTimelineItem.statusMessage = `Making a call to ${(_5 = notificationRuleItem.userCall) === null || _5 === void 0 ? void 0 : _5.phone.toString()}.`;
829
+ logTimelineItem.statusMessage = `Making a call to ${(_8 = notificationRuleItem.userCall) === null || _8 === void 0 ? void 0 : _8.phone.toString()}.`;
685
830
  logTimelineItem.userCallId = notificationRuleItem.userCall.id;
686
831
  const updatedLog = await UserOnCallLogTimelineService.create({
687
832
  data: logTimelineItem,
@@ -689,7 +834,7 @@ export class Service extends DatabaseService {
689
834
  isRoot: true,
690
835
  },
691
836
  });
692
- const callRequest = await this.generateCallTemplateForAlertCreated((_6 = notificationRuleItem.userCall) === null || _6 === void 0 ? void 0 : _6.phone, alert, updatedLog.id);
837
+ const callRequest = await this.generateCallTemplateForAlertCreated((_9 = notificationRuleItem.userCall) === null || _9 === void 0 ? void 0 : _9.phone, alert, updatedLog.id);
693
838
  // send call.
694
839
  CallService.makeCall(callRequest, {
695
840
  projectId: alert.projectId,
@@ -719,7 +864,7 @@ export class Service extends DatabaseService {
719
864
  incident) {
720
865
  // send call for incident
721
866
  logTimelineItem.status = UserNotificationStatus.Sending;
722
- logTimelineItem.statusMessage = `Making a call to ${(_7 = notificationRuleItem.userCall) === null || _7 === void 0 ? void 0 : _7.phone.toString()}.`;
867
+ logTimelineItem.statusMessage = `Making a call to ${(_10 = notificationRuleItem.userCall) === null || _10 === void 0 ? void 0 : _10.phone.toString()}.`;
723
868
  logTimelineItem.userCallId = notificationRuleItem.userCall.id;
724
869
  const updatedLog = await UserOnCallLogTimelineService.create({
725
870
  data: logTimelineItem,
@@ -727,7 +872,7 @@ export class Service extends DatabaseService {
727
872
  isRoot: true,
728
873
  },
729
874
  });
730
- const callRequest = await this.generateCallTemplateForIncidentCreated((_8 = notificationRuleItem.userCall) === null || _8 === void 0 ? void 0 : _8.phone, incident, updatedLog.id);
875
+ const callRequest = await this.generateCallTemplateForIncidentCreated((_11 = notificationRuleItem.userCall) === null || _11 === void 0 ? void 0 : _11.phone, incident, updatedLog.id);
731
876
  // send call.
732
877
  CallService.makeCall(callRequest, {
733
878
  projectId: incident.projectId,
@@ -757,7 +902,7 @@ export class Service extends DatabaseService {
757
902
  UserNotificationEventType.AlertEpisodeCreated &&
758
903
  alertEpisode) {
759
904
  logTimelineItem.status = UserNotificationStatus.Sending;
760
- logTimelineItem.statusMessage = `Making a call to ${(_9 = notificationRuleItem.userCall) === null || _9 === void 0 ? void 0 : _9.phone.toString()}.`;
905
+ logTimelineItem.statusMessage = `Making a call to ${(_12 = notificationRuleItem.userCall) === null || _12 === void 0 ? void 0 : _12.phone.toString()}.`;
761
906
  logTimelineItem.userCallId = notificationRuleItem.userCall.id;
762
907
  const updatedLog = await UserOnCallLogTimelineService.create({
763
908
  data: logTimelineItem,
@@ -765,7 +910,7 @@ export class Service extends DatabaseService {
765
910
  isRoot: true,
766
911
  },
767
912
  });
768
- const callRequest = await this.generateCallTemplateForAlertEpisodeCreated((_10 = notificationRuleItem.userCall) === null || _10 === void 0 ? void 0 : _10.phone, alertEpisode, updatedLog.id);
913
+ const callRequest = await this.generateCallTemplateForAlertEpisodeCreated((_13 = notificationRuleItem.userCall) === null || _13 === void 0 ? void 0 : _13.phone, alertEpisode, updatedLog.id);
769
914
  CallService.makeCall(callRequest, {
770
915
  projectId: alertEpisode.projectId,
771
916
  userOnCallLogTimelineId: updatedLog.id,
@@ -790,11 +935,11 @@ export class Service extends DatabaseService {
790
935
  });
791
936
  }
792
937
  }
793
- if (((_11 = notificationRuleItem.userCall) === null || _11 === void 0 ? void 0 : _11.phone) &&
794
- !((_12 = notificationRuleItem.userCall) === null || _12 === void 0 ? void 0 : _12.isVerified)) {
938
+ if (((_14 = notificationRuleItem.userCall) === null || _14 === void 0 ? void 0 : _14.phone) &&
939
+ !((_15 = notificationRuleItem.userCall) === null || _15 === void 0 ? void 0 : _15.isVerified)) {
795
940
  // create a log.
796
941
  logTimelineItem.status = UserNotificationStatus.Error;
797
- logTimelineItem.statusMessage = `Call not sent because phone ${(_13 = notificationRuleItem.userCall) === null || _13 === void 0 ? void 0 : _13.phone.toString()} is not verified.`;
942
+ logTimelineItem.statusMessage = `Call not sent because phone ${(_16 = notificationRuleItem.userCall) === null || _16 === void 0 ? void 0 : _16.phone.toString()} is not verified.`;
798
943
  await UserOnCallLogTimelineService.create({
799
944
  data: logTimelineItem,
800
945
  props: {
@@ -803,8 +948,8 @@ export class Service extends DatabaseService {
803
948
  });
804
949
  }
805
950
  // send push notification.
806
- if (((_14 = notificationRuleItem.userPush) === null || _14 === void 0 ? void 0 : _14.deviceToken) &&
807
- ((_15 = notificationRuleItem.userPush) === null || _15 === void 0 ? void 0 : _15.isVerified)) {
951
+ if (((_17 = notificationRuleItem.userPush) === null || _17 === void 0 ? void 0 : _17.deviceToken) &&
952
+ ((_18 = notificationRuleItem.userPush) === null || _18 === void 0 ? void 0 : _18.isVerified)) {
808
953
  // send push notification for alert
809
954
  if (options.userNotificationEventType ===
810
955
  UserNotificationEventType.AlertCreated &&
@@ -819,7 +964,7 @@ export class Service extends DatabaseService {
819
964
  isRoot: true,
820
965
  },
821
966
  });
822
- const pushMessage = PushNotificationUtil.createAlertCreatedNotification(Object.assign(Object.assign(Object.assign({ alertTitle: alert.title, projectName: ((_16 = alert.project) === null || _16 === void 0 ? void 0 : _16.name) || "OneUptime", alertViewLink: (await AlertService.getAlertLinkInDashboard(alert.projectId, alert.id)).toString() }, (alert.alertNumber !== undefined && {
967
+ const pushMessage = PushNotificationUtil.createAlertCreatedNotification(Object.assign(Object.assign(Object.assign({ alertTitle: alert.title, projectName: ((_19 = alert.project) === null || _19 === void 0 ? void 0 : _19.name) || "OneUptime", alertViewLink: (await AlertService.getAlertLinkInDashboard(alert.projectId, alert.id)).toString() }, (alert.alertNumber !== undefined && {
823
968
  alertNumber: alert.alertNumber,
824
969
  })), (alert.alertNumberWithPrefix && {
825
970
  alertNumberWithPrefix: alert.alertNumberWithPrefix,
@@ -871,7 +1016,7 @@ export class Service extends DatabaseService {
871
1016
  isRoot: true,
872
1017
  },
873
1018
  });
874
- const pushMessage = PushNotificationUtil.createIncidentCreatedNotification(Object.assign(Object.assign(Object.assign({ incidentTitle: incident.title, projectName: ((_17 = incident.project) === null || _17 === void 0 ? void 0 : _17.name) || "OneUptime", incidentViewLink: (await IncidentService.getIncidentLinkInDashboard(incident.projectId, incident.id)).toString() }, (incident.incidentNumber !== undefined && {
1019
+ const pushMessage = PushNotificationUtil.createIncidentCreatedNotification(Object.assign(Object.assign(Object.assign({ incidentTitle: incident.title, projectName: ((_20 = incident.project) === null || _20 === void 0 ? void 0 : _20.name) || "OneUptime", incidentViewLink: (await IncidentService.getIncidentLinkInDashboard(incident.projectId, incident.id)).toString() }, (incident.incidentNumber !== undefined && {
875
1020
  incidentNumber: incident.incidentNumber,
876
1021
  })), (incident.incidentNumberWithPrefix && {
877
1022
  incidentNumberWithPrefix: incident.incidentNumberWithPrefix,
@@ -922,7 +1067,7 @@ export class Service extends DatabaseService {
922
1067
  isRoot: true,
923
1068
  },
924
1069
  });
925
- const pushMessage = PushNotificationUtil.createAlertEpisodeCreatedNotification(Object.assign(Object.assign(Object.assign({ alertEpisodeTitle: alertEpisode.title, projectName: ((_18 = alertEpisode.project) === null || _18 === void 0 ? void 0 : _18.name) || "OneUptime", alertEpisodeViewLink: (await AlertEpisodeService.getEpisodeLinkInDashboard(alertEpisode.projectId, alertEpisode.id)).toString() }, (alertEpisode.episodeNumber !== undefined && {
1070
+ const pushMessage = PushNotificationUtil.createAlertEpisodeCreatedNotification(Object.assign(Object.assign(Object.assign({ alertEpisodeTitle: alertEpisode.title, projectName: ((_21 = alertEpisode.project) === null || _21 === void 0 ? void 0 : _21.name) || "OneUptime", alertEpisodeViewLink: (await AlertEpisodeService.getEpisodeLinkInDashboard(alertEpisode.projectId, alertEpisode.id)).toString() }, (alertEpisode.episodeNumber !== undefined && {
926
1071
  episodeNumber: alertEpisode.episodeNumber,
927
1072
  })), (alertEpisode.episodeNumberWithPrefix && {
928
1073
  episodeNumberWithPrefix: alertEpisode.episodeNumberWithPrefix,
@@ -972,7 +1117,7 @@ export class Service extends DatabaseService {
972
1117
  isRoot: true,
973
1118
  },
974
1119
  });
975
- const pushMessage = PushNotificationUtil.createIncidentEpisodeCreatedNotification(Object.assign(Object.assign(Object.assign({ incidentEpisodeTitle: incidentEpisode.title, projectName: ((_19 = incidentEpisode.project) === null || _19 === void 0 ? void 0 : _19.name) || "OneUptime", incidentEpisodeViewLink: (await IncidentEpisodeService.getEpisodeLinkInDashboard(incidentEpisode.projectId, incidentEpisode.id)).toString() }, (incidentEpisode.episodeNumber !== undefined && {
1120
+ const pushMessage = PushNotificationUtil.createIncidentEpisodeCreatedNotification(Object.assign(Object.assign(Object.assign({ incidentEpisodeTitle: incidentEpisode.title, projectName: ((_22 = incidentEpisode.project) === null || _22 === void 0 ? void 0 : _22.name) || "OneUptime", incidentEpisodeViewLink: (await IncidentEpisodeService.getEpisodeLinkInDashboard(incidentEpisode.projectId, incidentEpisode.id)).toString() }, (incidentEpisode.episodeNumber !== undefined && {
976
1121
  episodeNumber: incidentEpisode.episodeNumber,
977
1122
  })), (incidentEpisode.episodeNumberWithPrefix && {
978
1123
  episodeNumberWithPrefix: incidentEpisode.episodeNumberWithPrefix,
@@ -1009,8 +1154,8 @@ export class Service extends DatabaseService {
1009
1154
  });
1010
1155
  }
1011
1156
  }
1012
- if (((_20 = notificationRuleItem.userPush) === null || _20 === void 0 ? void 0 : _20.deviceToken) &&
1013
- !((_21 = notificationRuleItem.userPush) === null || _21 === void 0 ? void 0 : _21.isVerified)) {
1157
+ if (((_23 = notificationRuleItem.userPush) === null || _23 === void 0 ? void 0 : _23.deviceToken) &&
1158
+ !((_24 = notificationRuleItem.userPush) === null || _24 === void 0 ? void 0 : _24.isVerified)) {
1014
1159
  // create a log.
1015
1160
  logTimelineItem.status = UserNotificationStatus.Error;
1016
1161
  logTimelineItem.statusMessage = `Push notification not sent because device is not verified.`;
@@ -1191,6 +1336,83 @@ export class Service extends DatabaseService {
1191
1336
  };
1192
1337
  return sms;
1193
1338
  }
1339
+ async buildOnCallAcknowledgeShortUrl(userOnCallLogTimelineId) {
1340
+ const host = await DatabaseConfig.getHost();
1341
+ const httpProtocol = await DatabaseConfig.getHttpProtocol();
1342
+ const shortUrl = await ShortLinkService.saveShortLinkFor(new URL(httpProtocol, host, new Route(AppApiRoute.toString())
1343
+ .addRoute(new UserOnCallLogTimeline().crudApiPath)
1344
+ .addRoute("/acknowledge-page/" + userOnCallLogTimelineId.toString())));
1345
+ return await ShortLinkService.getShortenedUrl(shortUrl);
1346
+ }
1347
+ /*
1348
+ * Telegram's HTML parse_mode supports <b>, <i>, <a>, <code>. Only <, >, and &
1349
+ * need escaping inside those tags' text content.
1350
+ */
1351
+ escapeTelegramHtml(value) {
1352
+ return value
1353
+ .replace(/&/g, "&amp;")
1354
+ .replace(/</g, "&lt;")
1355
+ .replace(/>/g, "&gt;");
1356
+ }
1357
+ async generateTelegramBodyForAlertCreated(alert, userOnCallLogTimelineId) {
1358
+ const ackUrl = await this.buildOnCallAcknowledgeShortUrl(userOnCallLogTimelineId);
1359
+ const alertIdentifier = alert.alertNumber !== undefined
1360
+ ? `${alert.alertNumberWithPrefix || "#" + alert.alertNumber} — ${alert.title || "Alert"}`
1361
+ : alert.title || "Alert";
1362
+ const lines = [
1363
+ "🚨 <b>New alert assigned to you</b>",
1364
+ "",
1365
+ `📋 <b>${this.escapeTelegramHtml(alertIdentifier)}</b>`,
1366
+ "",
1367
+ "👤 You're getting this because you're on call.",
1368
+ ];
1369
+ if (alert.projectId && alert.id) {
1370
+ const dashboardUrl = await AlertService.getAlertLinkInDashboard(alert.projectId, alert.id);
1371
+ lines.push("", `🔎 <a href="${this.escapeTelegramHtml(dashboardUrl.toString())}">View alert in OneUptime</a>`);
1372
+ }
1373
+ lines.push("", `✅ <a href="${this.escapeTelegramHtml(ackUrl.toString())}">Tap to acknowledge</a>`);
1374
+ return lines.join("\n");
1375
+ }
1376
+ async generateTelegramBodyForIncidentCreated(incident, userOnCallLogTimelineId) {
1377
+ const ackUrl = await this.buildOnCallAcknowledgeShortUrl(userOnCallLogTimelineId);
1378
+ const incidentIdentifier = incident.incidentNumber !== undefined
1379
+ ? `${incident.incidentNumberWithPrefix || "#" + incident.incidentNumber} — ${incident.title || "Incident"}`
1380
+ : incident.title || "Incident";
1381
+ const lines = [
1382
+ "🔥 <b>New incident assigned to you</b>",
1383
+ "",
1384
+ `📋 <b>${this.escapeTelegramHtml(incidentIdentifier)}</b>`,
1385
+ "",
1386
+ "👤 You're getting this because you're on call.",
1387
+ ];
1388
+ if (incident.projectId && incident.id) {
1389
+ const dashboardUrl = await IncidentService.getIncidentLinkInDashboard(incident.projectId, incident.id);
1390
+ lines.push("", `🔎 <a href="${this.escapeTelegramHtml(dashboardUrl.toString())}">View incident in OneUptime</a>`);
1391
+ }
1392
+ lines.push("", `✅ <a href="${this.escapeTelegramHtml(ackUrl.toString())}">Tap to acknowledge</a>`);
1393
+ return lines.join("\n");
1394
+ }
1395
+ async generateTelegramBodyForAlertEpisodeCreated(alertEpisode, userOnCallLogTimelineId) {
1396
+ const ackUrl = await this.buildOnCallAcknowledgeShortUrl(userOnCallLogTimelineId);
1397
+ const episodeIdentifier = alertEpisode.episodeNumberWithPrefix
1398
+ ? `${alertEpisode.episodeNumberWithPrefix} — ${alertEpisode.title || "Alert Episode"}`
1399
+ : alertEpisode.episodeNumber !== undefined
1400
+ ? `#${alertEpisode.episodeNumber} — ${alertEpisode.title || "Alert Episode"}`
1401
+ : alertEpisode.title || "Alert Episode";
1402
+ const lines = [
1403
+ "🔔 <b>New alert episode assigned to you</b>",
1404
+ "",
1405
+ `📋 <b>${this.escapeTelegramHtml(episodeIdentifier)}</b>`,
1406
+ "",
1407
+ "👤 You're getting this because you're on call.",
1408
+ ];
1409
+ if (alertEpisode.projectId && alertEpisode.id) {
1410
+ const dashboardUrl = await AlertEpisodeService.getEpisodeLinkInDashboard(alertEpisode.projectId, alertEpisode.id);
1411
+ lines.push("", `🔎 <a href="${this.escapeTelegramHtml(dashboardUrl.toString())}">View alert episode in OneUptime</a>`);
1412
+ }
1413
+ lines.push("", `✅ <a href="${this.escapeTelegramHtml(ackUrl.toString())}">Tap to acknowledge</a>`);
1414
+ return lines.join("\n");
1415
+ }
1194
1416
  async generateWhatsAppTemplateForAlertCreated(to, alert, userOnCallLogTimelineId) {
1195
1417
  var _a;
1196
1418
  const host = await DatabaseConfig.getHost();
@@ -1574,10 +1796,12 @@ export class Service extends DatabaseService {
1574
1796
  !createBy.data.userSmsId &&
1575
1797
  !createBy.data.userWhatsApp &&
1576
1798
  !createBy.data.userWhatsAppId &&
1799
+ !createBy.data.userTelegram &&
1800
+ !createBy.data.userTelegramId &&
1577
1801
  !createBy.data.userEmailId &&
1578
1802
  !createBy.data.userPushId &&
1579
1803
  !createBy.data.userPush) {
1580
- throw new BadDataException("Call, SMS, WhatsApp, Email, or Push notification is required");
1804
+ throw new BadDataException("Call, SMS, WhatsApp, Telegram, Email, or Push notification is required");
1581
1805
  }
1582
1806
  return {
1583
1807
  createBy,
@@ -1606,6 +1830,9 @@ export class Service extends DatabaseService {
1606
1830
  if (descriptor.userWhatsAppId) {
1607
1831
  rule.userWhatsAppId = descriptor.userWhatsAppId;
1608
1832
  }
1833
+ if (descriptor.userTelegramId) {
1834
+ rule.userTelegramId = descriptor.userTelegramId;
1835
+ }
1609
1836
  if (descriptor.userPushId) {
1610
1837
  rule.userPushId = descriptor.userPushId;
1611
1838
  }
@@ -1624,6 +1851,9 @@ export class Service extends DatabaseService {
1624
1851
  if (descriptor.userWhatsAppId) {
1625
1852
  query["userWhatsAppId"] = descriptor.userWhatsAppId;
1626
1853
  }
1854
+ if (descriptor.userTelegramId) {
1855
+ query["userTelegramId"] = descriptor.userTelegramId;
1856
+ }
1627
1857
  if (descriptor.userPushId) {
1628
1858
  query["userPushId"] = descriptor.userPushId;
1629
1859
  }
@@ -1820,6 +2050,27 @@ __decorate([
1820
2050
  ObjectID]),
1821
2051
  __metadata("design:returntype", Promise)
1822
2052
  ], Service.prototype, "generateSmsTemplateForAlertEpisodeCreated", null);
2053
+ __decorate([
2054
+ CaptureSpan(),
2055
+ __metadata("design:type", Function),
2056
+ __metadata("design:paramtypes", [Alert,
2057
+ ObjectID]),
2058
+ __metadata("design:returntype", Promise)
2059
+ ], Service.prototype, "generateTelegramBodyForAlertCreated", null);
2060
+ __decorate([
2061
+ CaptureSpan(),
2062
+ __metadata("design:type", Function),
2063
+ __metadata("design:paramtypes", [Incident,
2064
+ ObjectID]),
2065
+ __metadata("design:returntype", Promise)
2066
+ ], Service.prototype, "generateTelegramBodyForIncidentCreated", null);
2067
+ __decorate([
2068
+ CaptureSpan(),
2069
+ __metadata("design:type", Function),
2070
+ __metadata("design:paramtypes", [AlertEpisode,
2071
+ ObjectID]),
2072
+ __metadata("design:returntype", Promise)
2073
+ ], Service.prototype, "generateTelegramBodyForAlertEpisodeCreated", null);
1823
2074
  __decorate([
1824
2075
  CaptureSpan(),
1825
2076
  __metadata("design:type", Function),