Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hawk.api",
"version": "1.2.23",
"version": "1.2.24",
"main": "index.ts",
"license": "BUSL-1.1",
"scripts": {
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions src/models/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ class Notify {
endpoint: 'slack',
minPeriod: 60,
},
loop: {
isEnabled: true,
endpoint: 'loop',
minPeriod: 60,
},
telegram: {
isEnabled: true,
endpoint: 'telegram',
Expand Down
9 changes: 9 additions & 0 deletions src/rabbitmq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export enum Queues {
Email = 'sender/email',
Telegram = 'notify/telegram',
Slack = 'notify/slack',
Loop = 'notify/loop',
Limiter = 'cron-tasks/limiter',
}

Expand Down Expand Up @@ -81,6 +82,14 @@ export const WorkerPaths: Record<string, WorkerPath> = {
queue: Queues.Slack,
},

/**
* Path to loop worker
*/
Loop: {
exchange: Exchanges.Notify,
queue: Queues.Loop,
},

/**
* Path to limiter worker
*/
Expand Down
5 changes: 5 additions & 0 deletions src/resolvers/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ module.exports = {
endpoint: '',
minPeriod: 60,
},
loop: {
isEnabled: false,
endpoint: '',
minPeriod: 60,
},
},
}, true);

Expand Down
6 changes: 6 additions & 0 deletions src/resolvers/projectNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
5 changes: 5 additions & 0 deletions src/typeDefs/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export default gql`
"""
slack: NotificationsChannelSettings

"""
Loop channel
"""
loop: NotificationsChannelSettings

"""
Webpush
"""
Expand Down
5 changes: 5 additions & 0 deletions src/typeDefs/notificationsInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export default gql`
"""
slack: NotificationsChannelSettingsInput

"""
Loop channel
"""
loop: NotificationsChannelSettingsInput

"""
Web push
"""
Expand Down
7 changes: 6 additions & 1 deletion src/types/notification-channels.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export interface NotificationsChannelsDBScheme {
*/
slack?: NotificationsChannelSettingsDBScheme;

/**
* Alerts through the Loop
*/
loop?: NotificationsChannelSettingsDBScheme;

/**
* Alerts through the Telegram
*/
Expand All @@ -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;

Expand Down
10 changes: 10 additions & 0 deletions src/utils/personalNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});
}
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Loading