diff --git a/package.json b/package.json index 1600018a..b9979f18 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hawk.api", - "version": "1.2.23", + "version": "1.2.24", "main": "index.ts", "license": "BUSL-1.1", "scripts": { @@ -39,7 +39,7 @@ "@graphql-tools/schema": "^8.5.1", "@graphql-tools/utils": "^8.9.0", "@hawk.so/nodejs": "^3.1.1", - "@hawk.so/types": "^0.1.33", + "@hawk.so/types": "^0.1.37", "@n1ru4l/json-patch-plus": "^0.2.0", "@types/amqp-connection-manager": "^2.0.4", "@types/bson": "^4.0.5", diff --git a/src/models/notify.js b/src/models/notify.js index 78c8795e..729d6aef 100644 --- a/src/models/notify.js +++ b/src/models/notify.js @@ -90,6 +90,11 @@ class Notify { endpoint: 'slack', minPeriod: 60, }, + loop: { + isEnabled: true, + endpoint: 'loop', + minPeriod: 60, + }, telegram: { isEnabled: true, endpoint: 'telegram', diff --git a/src/rabbitmq.ts b/src/rabbitmq.ts index 1e614264..cb28ed67 100644 --- a/src/rabbitmq.ts +++ b/src/rabbitmq.ts @@ -27,6 +27,7 @@ export enum Queues { Email = 'sender/email', Telegram = 'notify/telegram', Slack = 'notify/slack', + Loop = 'notify/loop', Limiter = 'cron-tasks/limiter', } @@ -81,6 +82,14 @@ export const WorkerPaths: Record = { queue: Queues.Slack, }, + /** + * Path to loop worker + */ + Loop: { + exchange: Exchanges.Notify, + queue: Queues.Loop, + }, + /** * Path to limiter worker */ diff --git a/src/resolvers/project.js b/src/resolvers/project.js index 786aff11..f0993ef4 100644 --- a/src/resolvers/project.js +++ b/src/resolvers/project.js @@ -90,6 +90,11 @@ module.exports = { endpoint: '', minPeriod: 60, }, + loop: { + isEnabled: false, + endpoint: '', + minPeriod: 60, + }, }, }, true); diff --git a/src/resolvers/projectNotifications.ts b/src/resolvers/projectNotifications.ts index 456bdece..af8e0cec 100644 --- a/src/resolvers/projectNotifications.ts +++ b/src/resolvers/projectNotifications.ts @@ -114,6 +114,12 @@ function validateNotificationsRuleChannels(channels: NotificationsChannelsDBSche } } + if (channels.loop!.isEnabled) { + if (!/^https:\/\/.+\/hooks\/.+$/.test(channels.loop!.endpoint)) { + return 'Invalid loop endpoint passed'; + } + } + if (channels.telegram!.isEnabled) { if (!/^https:\/\/notify\.bot\.codex\.so\/u\/[A-Za-z0-9]+$/.test(channels.telegram!.endpoint)) { return 'Invalid telegram endpoint passed'; diff --git a/src/typeDefs/notifications.ts b/src/typeDefs/notifications.ts index c48fd48d..a923b26b 100644 --- a/src/typeDefs/notifications.ts +++ b/src/typeDefs/notifications.ts @@ -44,6 +44,11 @@ export default gql` """ slack: NotificationsChannelSettings + """ + Loop channel + """ + loop: NotificationsChannelSettings + """ Webpush """ diff --git a/src/typeDefs/notificationsInput.ts b/src/typeDefs/notificationsInput.ts index 71caeccf..fb9aa835 100644 --- a/src/typeDefs/notificationsInput.ts +++ b/src/typeDefs/notificationsInput.ts @@ -40,6 +40,11 @@ export default gql` """ slack: NotificationsChannelSettingsInput + """ + Loop channel + """ + loop: NotificationsChannelSettingsInput + """ Web push """ diff --git a/src/types/notification-channels.d.ts b/src/types/notification-channels.d.ts index e07dd46c..2e751e00 100644 --- a/src/types/notification-channels.d.ts +++ b/src/types/notification-channels.d.ts @@ -17,6 +17,11 @@ export interface NotificationsChannelsDBScheme { */ slack?: NotificationsChannelSettingsDBScheme; + /** + * Alerts through the Loop + */ + loop?: NotificationsChannelSettingsDBScheme; + /** * Alerts through the Telegram */ @@ -43,7 +48,7 @@ export interface NotificationsChannelSettingsDBScheme { isEnabled: boolean; /** - * Endpoint: email, slack webhook, telegram bot webhook, push subscription id, etc + * Endpoint: email, slack/loop webhook, telegram bot webhook, push subscription id, etc */ endpoint: string; diff --git a/src/utils/personalNotifications.ts b/src/utils/personalNotifications.ts index e5a3ce8f..9b3b7339 100644 --- a/src/utils/personalNotifications.ts +++ b/src/utils/personalNotifications.ts @@ -42,4 +42,14 @@ export default async function sendNotification(user: UserDBScheme, task: SenderW }, }); } + + if (user.notifications.channels.loop?.isEnabled) { + await enqueue(WorkerPaths.Loop, { + type: task.type, + payload: { + ...task.payload, + endpoint: user.notifications.channels.loop.endpoint, + }, + }); + } } diff --git a/yarn.lock b/yarn.lock index 44240cfb..239d0887 100644 --- a/yarn.lock +++ b/yarn.lock @@ -458,10 +458,10 @@ dependencies: "@types/mongodb" "^3.5.34" -"@hawk.so/types@^0.1.33": - version "0.1.33" - resolved "https://registry.yarnpkg.com/@hawk.so/types/-/types-0.1.33.tgz#feb077b699b3e0001552588a372e1efe6cd58f40" - integrity sha512-q3AdVxzQ8Qk8qyYiAcAacxNZXWTG/oLmVpjQlcLm2Eh5OJgpaZvH8hQCeRQ/ml1cqbYW8gUrRbMMCS2QOcwxEw== +"@hawk.so/types@^0.1.37": + version "0.1.37" + resolved "https://registry.yarnpkg.com/@hawk.so/types/-/types-0.1.37.tgz#e68d822957d86aac4fa1fdec7927a046ce0cf8c8" + integrity sha512-34C+TOWA5oJyOL3W+NXlSyY7u0OKkRu2+tIZ4jSJp0c1/5v+qpEPeo07FlOOHqDRRhMG4/2PAgQCronfF2qWPg== dependencies: "@types/mongodb" "^3.5.34"