Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ntfy provider #5341

Open
wants to merge 13 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/api/src/app/integrations/dtos/credentials.dto.ts
Expand Up @@ -202,6 +202,11 @@ export class CredentialsDto implements ICredentials {
@IsOptional()
externalLink?: string;

@ApiPropertyOptional()
@IsString()
@IsOptional()
topic?: string;

@ApiPropertyOptional()
@IsString()
@IsOptional()
Expand Down
7 changes: 7 additions & 0 deletions apps/web/public/static/images/providers/dark/ntfy.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions apps/web/public/static/images/providers/light/ntfy.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions apps/web/public/static/images/providers/light/square/ntfy.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -58,6 +58,7 @@ const integrationSchema = new Schema<IntegrationDBModel>(
state: Schema.Types.String,
externalLink: Schema.Types.String,
apiToken: Schema.Types.String,
topic: Schema.Types.String,
channelId: Schema.Types.String,
},
active: {
Expand Down
9 changes: 9 additions & 0 deletions libs/shared/src/consts/providers/channels/push.ts
Expand Up @@ -2,6 +2,7 @@ import {
apnsConfig,
expoConfig,
fcmConfig,
ntfyConfig,
oneSignalConfig,
pusherBeamsConfig,
pushpadConfig,
Expand Down Expand Up @@ -39,6 +40,14 @@ export const pushProviders: IProviderConfig[] = [
docReference: `https://docs.novu.co/channels-and-providers/push/fcm${UTM_CAMPAIGN_QUERY_PARAM}`,
logoFileName: { light: 'fcm.svg', dark: 'fcm.svg' },
},
{
id: PushProviderIdEnum.Ntfy,
displayName: 'Ntfy',
channel: ChannelTypeEnum.PUSH,
credentials: ntfyConfig,
docReference: `https://docs.novu.co/channels-and-providers/push/ntfy${UTM_CAMPAIGN_QUERY_PARAM}`,
logoFileName: { light: 'ntfy.svg', dark: 'ntfy.svg' },
},
{
id: PushProviderIdEnum.EXPO,
displayName: 'Expo Push',
Expand Down
Expand Up @@ -575,6 +575,23 @@ export const expoConfig: IConfigCredentials[] = [
...pushConfigBase,
];

export const ntfyConfig: IConfigCredentials[] = [
{
key: CredentialsKeyEnum.BaseUrl,
displayName: 'Base URL',
description: 'The base URL of the ntfy server, change it if you are self-hosting ntfy',
type: 'text',
required: false,
},
{
key: CredentialsKeyEnum.Topic,
displayName: 'Topic',
type: 'text',
required: true,
},
...pushConfigBase,
];

export const pushWebhookConfig: IConfigCredentials[] = [
{
key: CredentialsKeyEnum.WebhookUrl,
Expand Down
2 changes: 2 additions & 0 deletions libs/shared/src/consts/providers/provider.enum.ts
Expand Up @@ -44,6 +44,7 @@ export enum CredentialsKeyEnum {
imageUrl = 'imageUrl',
state = 'state',
externalLink = 'externalLink',
Topic = 'topic',
channelId = 'channelId',
}

Expand Down Expand Up @@ -120,6 +121,7 @@ export enum PushProviderIdEnum {
FCM = 'fcm',
APNS = 'apns',
EXPO = 'expo',
Ntfy = 'ntfy',
OneSignal = 'one-signal',
Pushpad = 'pushpad',
PushWebhook = 'push-webhook',
Expand Down
Expand Up @@ -42,5 +42,6 @@ export interface ICredentials {
imageUrl?: string;
state?: string;
externalLink?: string;
topic?: string;
channelId?: string;
}
1 change: 1 addition & 0 deletions packages/application-generic/package.json
Expand Up @@ -88,6 +88,7 @@
"@novu/ms-teams": "^0.24.1",
"@novu/netcore": "^0.24.1",
"@novu/nexmo": "^0.24.1",
"@novu/ntfy": "^0.24.1",
"@novu/nodemailer": "^0.24.1",
"@novu/one-signal": "^0.24.1",
"@novu/outlook365": "^0.24.1",
Expand Down
Expand Up @@ -5,3 +5,4 @@ export * from './one-signal.handler';
export * from './pushpad.handler';
export * from './push-webhook.handler';
export * from './pusher-beams.handler';
export * from './ntfy.handler';
@@ -0,0 +1,20 @@
import { ChannelTypeEnum, ICredentials } from '@novu/shared';
import { NtfyPushProvider } from '@novu/ntfy';
import { BasePushHandler } from './base.handler';

export class NtfyHandler extends BasePushHandler {
constructor() {
super('ntfy', ChannelTypeEnum.PUSH);
}

buildProvider(credentials: ICredentials) {
if (!credentials.topic) {
throw Error('Topic is required for ntfy');
}

this.provider = new NtfyPushProvider({
baseUrl: credentials.baseUrl,
topic: credentials.topic,
});
}
}
Expand Up @@ -3,6 +3,7 @@ import {
APNSHandler,
ExpoHandler,
FCMHandler,
NtfyHandler,
OneSignalHandler,
PusherBeamsHandler,
PushpadHandler,
Expand All @@ -19,6 +20,7 @@ export class PushFactory implements IPushFactory {
new PushpadHandler(),
new PushWebhookHandler(),
new PusherBeamsHandler(),
new NtfyHandler(),
];

getHandler(integration: IntegrationEntity): IPushHandler {
Expand Down
48 changes: 47 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions providers/ntfy/.czrc
@@ -0,0 +1,3 @@
{
"path": "cz-conventional-changelog"
}
3 changes: 3 additions & 0 deletions providers/ntfy/.eslintrc.json
@@ -0,0 +1,3 @@
{
"extends": "../../.eslintrc.js"
}
9 changes: 9 additions & 0 deletions providers/ntfy/.gitignore
@@ -0,0 +1,9 @@
.idea/*
.nyc_output
build
node_modules
test
src/**.js
coverage
*.log
package-lock.json
15 changes: 15 additions & 0 deletions providers/ntfy/README.md
@@ -0,0 +1,15 @@
# Novu Ntfy Provider

A Ntfy push provider library for [@novu/node](https://github.com/novuhq/novu)

## Usage

```javascript
import { NtfyPushProvider } from '@novu/ntfy';

const provider = new NtfyPushProvider({
topic: 'YOUR_TOPIC',
baseUrl: 'IGNORE_IF_NOT_SELF-HOSTING'
});
```

8 changes: 8 additions & 0 deletions providers/ntfy/jest.config.js
@@ -0,0 +1,8 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleNameMapper: {
axios: 'axios/dist/node/axios.cjs',
},
};
78 changes: 78 additions & 0 deletions providers/ntfy/package.json
@@ -0,0 +1,78 @@
{
"name": "@novu/ntfy",
"version": "0.24.1",
"description": "A ntfy wrapper for novu",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
"module": "build/module/index.js",
"private": false,
"repository": "https://github.com/novuhq/novu",
"license": "MIT",
"keywords": [],
"scripts": {
"prebuild": "rimraf build",
"build": "run-p build:*",
"build:main": "tsc -p tsconfig.json",
"build:module": "tsc -p tsconfig.module.json",
"fix": "run-s fix:*",
"fix:prettier": "prettier \"src/**/*.ts\" --write",
"fix:lint": "eslint src --ext .ts --fix",
"test": "run-s test:*",
"lint": "eslint src --ext .ts",
"test:unit": "jest src",
"watch:build": "tsc -p tsconfig.json -w",
"watch:test": "jest src --watch",
"reset-hard": "git clean -dfx && git reset --hard && yarn",
"prepare-release": "run-s reset-hard test"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@novu/stateless": "0.24.1",
"axios": "^1.6.0"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "~1.0.1",
"@types/jest": "~27.5.2",
"cspell": "~6.19.2",
"jest": "~27.5.1",
"npm-run-all": "^4.1.5",
"nyc": "~15.1.0",
"prettier": "~2.8.0",
"rimraf": "~3.0.2",
"ts-jest": "~27.1.5",
"ts-node": "~10.9.1",
"typescript": "4.9.5"
},
"files": [
"build/main",
"build/module",
"!**/*.spec.*",
"!**/*.json",
"CHANGELOG.md",
"LICENSE",
"README.md"
],
"ava": {
"failFast": true,
"timeout": "60s",
"typescript": {
"rewritePaths": {
"src/": "build/main/"
}
},
"files": [
"!build/module/**"
]
},
"prettier": {
"singleQuote": true
},
"nyc": {
"extends": "@istanbuljs/nyc-config-typescript",
"exclude": [
"**/*.spec.js"
]
}
}
1 change: 1 addition & 0 deletions providers/ntfy/src/index.ts
@@ -0,0 +1 @@
export * from './lib/ntfy.provider';