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

Nostr dm notifications #3051

Merged
merged 15 commits into from
Jun 27, 2023
Merged

Conversation

zappityzap
Copy link
Contributor

⚠️⚠️⚠️ Since we do not accept all types of pull requests and do not want to waste your time. Please be sure that you have read pull request rules:
https://github.com/louislam/uptime-kuma/blob/master/CONTRIBUTING.md#can-i-create-a-pull-request-for-uptime-kuma

Tick the checkbox if you understand [x]:

  • I have read and understand the pull request rules.

Description

Adds notification provider for the nostr protocol: https://github.com/nostr-protocol/nostr

Notifications are sent as encrypted direct messages.

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist

  • My code follows the style guidelines of this project
  • I ran ESLint and other linters for modified files
  • I have performed a self-review of my own code and tested it
  • I have commented my code, particularly in hard-to-understand areas
    (including JSDoc for methods)
  • My changes generate no new warnings
  • My code needed automated testing. I have added them (this is optional task)

Screenshots (if any)

1-notification-setup
2-nostr-notifications
3-test-succeed
4-test-multiple-partial
5-test-multiple-succeed
6-test-failed
7-error-invalid-nsec
8-error-invalid-npub

Copy link
Collaborator

@CommanderStorm CommanderStorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this seems pretty dinished, despite being a draft.
Is this intentional?

I left some code style marks

server/notification-providers/nostr.js Outdated Show resolved Hide resolved
server/notification-providers/nostr.js Outdated Show resolved Hide resolved
server/notification-providers/nostr.js Outdated Show resolved Hide resolved
server/notification-providers/nostr.js Show resolved Hide resolved
server/notification-providers/nostr.js Outdated Show resolved Hide resolved
@@ -0,0 +1,108 @@
const NotificationProvider = require("./notification-provider");
global.crypto = require("crypto");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this line included?

Suggested change
global.crypto = require("crypto");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without it, on Node 18 there is an error from the nostr-tools module that crypto is not defined. Node 19+ doesn't need it. There is a closed issue for nostr-tools about it: nbd-wtf/nostr-tools#192

I see they have a better method for Node 18 compatibility now, but I'm not sure how to implement it:

// node.js 18 and earlier requires globalThis.crypto polyfill.
import { webcrypto } from 'node:crypto';
// @ts-ignore
if (!globalThis.crypto) globalThis.crypto = webcrypto;

Here is the error with Node 18:

ReferenceError: crypto is not defined
    at Object.encrypt (/home/ansible/uptime-kuma/node_modules/nostr-tools/lib/nostr.cjs.js:994:19)
    at Nostr.send (/home/ansible/uptime-kuma/server/notification-providers/nostr.js:34:44)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Socket.<anonymous> (/home/ansible/uptime-kuma/server/server.js:1209:27)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include a comment that this is a polyfill for node <= 18

nip04,
nip19
} = require("nostr-tools");
require("websocket-polyfill");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this included?
No other of the providers include this.

If you think this is needed, let's split this out of this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without it, on Node 18 there is an error from the nostr-tools module. Node 19+ doesn't need it.

TypeError: Cannot read properties of undefined (reading 'readyState')
    at Object.close (/home/ansible/uptime-kuma/node_modules/nostr-tools/lib/nostr.cjs.js:566:14)
    at Nostr.send (/home/ansible/uptime-kuma/server/notification-providers/nostr.js:66:23)
    at async Socket.<anonymous> (/home/ansible/uptime-kuma/server/server.js:1209:27)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include a comment that this is a polyfill for node <= 18

Copy link
Collaborator

@CommanderStorm CommanderStorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this seems pretty dinished, despite being a draft.
Is this intentional?

I left some code style marks

@zappityzap
Copy link
Contributor Author

Overall this seems pretty dinished, despite being a draft. Is this intentional?

I left some code style marks

Thank you for the review and feedback. I'm new to open source contributions and JavaScript. I wanted to learn more about the Nostr protocol so I implemented this for my own use. The project contribution guidelines said to mark it as a draft.

@CommanderStorm
Copy link
Collaborator

The project contribution guidelines said to mark it as a draft.

See https://github.com/louislam/uptime-kuma/blob/master/CONTRIBUTING.md#can-i-create-a-pull-request-for-uptime-kuma
Notification Providers are handled differently from general feautre/code changes.
Empty draft PRs are only for discussing significant changes (as they carry significant reviewer effort+may risk breaking things) like #128/#2129/#2693

@zappityzap zappityzap marked this pull request as ready for review May 31, 2023 17:50
@louislam louislam added this to the 1.23.0 milestone Jun 22, 2023
@louislam louislam merged commit b8bcb6f into louislam:master Jun 27, 2023
2 checks passed
louislam added a commit that referenced this pull request Jun 28, 2023
louislam added a commit that referenced this pull request Jun 28, 2023
@louislam
Copy link
Owner

I just realized that this pr is not working on arm v7, because there is no pre-built binary for the bufferutil dependency. So I reverted it.

Feel free to continue this by opening a new pr if you have found a solution.

https://github.com/louislam/uptime-kuma/blob/master/CONTRIBUTING.md#can-i-create-a-pull-request-for-uptime-kuma

Easy to install for non-Docker users, no native build dependency is needed (for x86_64/armv7/arm64), no extra config, no extra effort required to get it running

UptimeKumaBot pushed a commit to UptimeKumaBot/uptime-kuma that referenced this pull request Jun 29, 2023
* Add nostr DM notification provider

* require crypto for node 18 compatibility

* remove whitespace

* move closer to where it is used

* simplify success or failure logic

* don't clobber the non-alert msg

* Update server/notification-providers/nostr.js

* polyfills required for node <= 18

* resolve linter warnings

* missing comma

---------

Co-authored-by: Frank Elsinga <frank@elsinga.de>
Co-authored-by: zappityzap <128872140+zappityzap@users.noreply.github.com>
UptimeKumaBot pushed a commit to UptimeKumaBot/uptime-kuma that referenced this pull request Jun 29, 2023
This reverts commit b8bcb6f.

Co-authored-by: Louis Lam <louislam@users.noreply.github.com>
UptimeKumaBot pushed a commit to UptimeKumaBot/uptime-kuma that referenced this pull request Jun 30, 2023
* Add nostr DM notification provider

* require crypto for node 18 compatibility

* remove whitespace

* move closer to where it is used

* simplify success or failure logic

* don't clobber the non-alert msg

* Update server/notification-providers/nostr.js

* polyfills required for node <= 18

* resolve linter warnings

* missing comma

---------

Co-authored-by: Frank Elsinga <frank@elsinga.de>
Co-authored-by: zappityzap <128872140+zappityzap@users.noreply.github.com>
UptimeKumaBot pushed a commit to UptimeKumaBot/uptime-kuma that referenced this pull request Jun 30, 2023
This reverts commit b8bcb6f.

Co-authored-by: Louis Lam <louislam@users.noreply.github.com>
UptimeKumaBot pushed a commit to UptimeKumaBot/uptime-kuma that referenced this pull request Jul 4, 2023
* Add nostr DM notification provider

* require crypto for node 18 compatibility

* remove whitespace

* move closer to where it is used

* simplify success or failure logic

* don't clobber the non-alert msg

* Update server/notification-providers/nostr.js

* polyfills required for node <= 18

* resolve linter warnings

* missing comma

---------

Co-authored-by: Frank Elsinga <frank@elsinga.de>
Co-authored-by: zappityzap <128872140+zappityzap@users.noreply.github.com>
UptimeKumaBot pushed a commit to UptimeKumaBot/uptime-kuma that referenced this pull request Jul 4, 2023
This reverts commit b8bcb6f.

Co-authored-by: Louis Lam <louislam@users.noreply.github.com>
louislam added a commit that referenced this pull request Jul 13, 2023
* ✨ feat: json-query monitor added

Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev>

* 🐛 fix: import warning error

Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev>

* 🐛 fix: br tag and remove comment

Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev>

* 🐛 fix: supporting compare string with other types

Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev>

* 🐛 fix: switch to a better lib for json query

Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev>

* 🐛 fix: better description on json query and using `v-html` in jsonQueryDescription element to fix `a` tags

Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev>

* 🐛 fix: result variable in error message

Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev>

* 🐛 fix: typos in json query description

Co-authored-by: Frank Elsinga <frank@elsinga.de>

* 📝 docs: `HTTP(s) Json Query` added to monitor list in `README.md`

Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev>

* 🐛 fix: needed white space in `README.md`

Co-authored-by: Frank Elsinga <frank@elsinga.de>

* Nostr dm notifications (#3051)

* Add nostr DM notification provider

* require crypto for node 18 compatibility

* remove whitespace

Co-authored-by: Frank Elsinga <frank@elsinga.de>

* move closer to where it is used

* simplify success or failure logic

* don't clobber the non-alert msg

* Update server/notification-providers/nostr.js

Co-authored-by: Frank Elsinga <frank@elsinga.de>

* polyfills required for node <= 18

* resolve linter warnings

* missing comma

---------

Co-authored-by: Frank Elsinga <frank@elsinga.de>

* Drop nostr

* Rebuild package-lock.json

* Lint

---------

Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev>
Co-authored-by: Frank Elsinga <frank@elsinga.de>
Co-authored-by: zappityzap <128872140+zappityzap@users.noreply.github.com>
Co-authored-by: Louis Lam <louislam@users.noreply.github.com>
louislam added a commit that referenced this pull request Jul 17, 2023
* ✨ feat: added kafka producer

Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev>

* 🐛 fix: eslint warn

Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev>

* 🐛 fix: typings and auth problems

Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev>

* 🐛 fix: better variable name to trrack disconnection

Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev>

* 🐛 fix: grouping Kafka Producer special settings into one template

Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev>

* ✨ feat: add kafka producer translations into `en.json`

Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev>

* 🐛 fix: disable close-on-select on kafka broker picker

Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev>

* 🐛 fix: `en.json` invalid json (conflict resolve)

Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev>

* Nostr dm notifications (#3051)

* Add nostr DM notification provider

* require crypto for node 18 compatibility

* remove whitespace

Co-authored-by: Frank Elsinga <frank@elsinga.de>

* move closer to where it is used

* simplify success or failure logic

* don't clobber the non-alert msg

* Update server/notification-providers/nostr.js

Co-authored-by: Frank Elsinga <frank@elsinga.de>

* polyfills required for node <= 18

* resolve linter warnings

* missing comma

---------

Co-authored-by: Frank Elsinga <frank@elsinga.de>

* Drop nostr

* Minor

* Fix a bug of clone

---------

Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev>
Co-authored-by: Frank Elsinga <frank@elsinga.de>
Co-authored-by: Louis Lam <louislam@users.noreply.github.com>
@zappityzap zappityzap mentioned this pull request Jul 23, 2023
7 tasks
mhkarimi1383 added a commit to mhkarimi1383/uptime-kuma that referenced this pull request Apr 29, 2024
mhkarimi1383 added a commit to mhkarimi1383/uptime-kuma that referenced this pull request Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants