-
Notifications
You must be signed in to change notification settings - Fork 736
Add NIP 9a for push notifications #2194
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
base: master
Are you sure you want to change the base?
Changes from all commits
34624f7
0480065
72651fa
882b1e5
1339a9d
0b671d3
28538cd
635449e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| NIP-9a | ||
| ====== | ||
|
|
||
| Nostr Relay Push | ||
| ---------------- | ||
|
|
||
| `draft` `optional` | ||
|
|
||
| This NIP defines a way for users to ask relays to push events to other servers. | ||
|
|
||
| To register a push subscription, users may create a `kind 30390` event. This event defines the following tags: | ||
|
|
||
| - `d` - a random string | ||
| - `relay` - a nostr relay URL to monitor (may appear multiple times) | ||
| - `filter` - a nostr filter for matching events (may appear multiple times) | ||
| - `ignore` - an nostr filter for ignoring matched events (optional, may appear multiple times) | ||
| - `callback` - a URL indicating a callback url to forward events to | ||
| - `include_event` - if included, relays MUST agree to include the complete `event` data in the push payload or reject the subscription | ||
|
|
||
| If a relay does not intend to fulfill the subscription, it SHOULD respond with an `OK` message with `false` as the result and a human-readable message. | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add expiry information. If a relay accepts subscription they have to send expiry time of subscription. As currently it is unclear when client has to resync subscription with relay.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the relay should also delete the event when the subscription expires, then clients can check if the relay has the event if not send it again.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @prhasn how do you imagine this working? OK messages aren't good for structured data. The relay could publish a subscription status event, but that seems like overkill. Maybe we should require an expiration tag on the subscription event, and relays can reject it if it's too far out? |
||
| When a relay receives a new event, it SHOULD match it against all current registrations and forward the event to authorized users by sending a `POST` request to the `callback` URL with `Content-Type: application/json`. The payload should be as follows: | ||
|
|
||
| ```typescript | ||
| { | ||
| id: string // The event's id | ||
| relay: string // The normalized url of the relay sending the notification | ||
| event?: Event // The event itself, if the subscription specifies `include_event` | ||
| } | ||
| ``` | ||
|
|
||
| If the `callback` URL responds with a `404` status code, the relay SHOULD delete the subscription. | ||
|
|
||
| ## Miscellaneous recommendations | ||
|
|
||
| - Relays MAY delete subscriptions at their discretion (e.g. due to expiration, inactivity, callback `500` errors, etc). | ||
| - Clients MAY delete subscription events as specified in [NIP 09](09.md). | ||
| - Clients SHOULD re-sync subscription events periodically to ensure they continue receiving push notifications. | ||
| - If a relay receives a `kind 30390` event whose `relay` tag does not match the relay's own URL, the relay SHOULD discard it. | ||
| - Relays that implement this NIP MUST include `9a` in its [NIP 11](11.md) `supported_nips`. | ||
| - Relays MUST serve `kind 30390` events only to their author. | ||
| - Clients MUST NOT send `kind 30390` events to relays that do not advertise support for this NIP. | ||
|
|
||
| ## Example: Push Notifications | ||
|
|
||
| This NIP may be used to facilitate push notifications sent over FCM, APN, VAPID, or other types of server. To do so, a client developer can register device tokens with their own server, returning a `callback` to the client. The client can then construct `kind 30390` events signed by the user containing the `callback` to relays they want to get notifications from: | ||
|
|
||
| ```typescript | ||
| { | ||
| kind: 30390, | ||
| pubkey: "<user pubkey>", | ||
| content: "", | ||
| tags: [ | ||
| ["d", "<subscription id>"], | ||
| ["relay", "wss://relay.example.com/"], | ||
| ["filter", "{\"kinds\": [1], \"#p\": [\"<user pubkey>\"]}"], | ||
| ["ignore", "{\"#t\": [\"footstr\"]}"], | ||
| ["callback", "https://my-callback.example.com/<subscription-id>"] | ||
| ], | ||
| } | ||
| ``` | ||
|
|
||
| When the subscription is no longer needed, clients can delete subscription events or cancel the subscription with the push server directly, relying on the server to return a 404 to relays sending events. | ||
Uh oh!
There was an error while loading. Please reload this page.