{"id":"5c8e0851cab2887094fb6d20b030113abd8348b1c15a48cea20c0964ae9e2214","pubkey":"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c","created_at":1769805520,"kind":30817,"tags":[["d","new-event-hooks"],["title","Relay Hooks"],["k","30027"],["client","nostrhub.io"]],"content":"Relay Hooks\n===========\n\n`draft` `optional`\n\nThis NIP defines a way for users to register new event hooks with relays and forward them to an HTTP API. \n\nEach kind `30027` event registers a hook with the following structure: \n\n```yaml\n{\n  \"kind\": 30027,\n  \"tags\": [\n    [\"d\", \"<subscription_id>\"],\n    [\"relay\", \"<normalized relay url>\"], \n\n    [\"filter\", \"<stringified nostr filter>\"],\n    [\"ignore\", \"<stringified nostr filter>\"] // optional\n\n    [\"callback\", \"<callback URL to forward events to>\"], \n  ]\n  // other fields\n}\n```\n\nWhen a relay receives a new event, it MUST match it against all current registrations and POST the JSON-stringified event to the `callback` URL with `Content-Type: application/json`. \n\nTags `relay` and `callback` are required. \n\nAll tags MAY appear multiple times to represent a logical OR.\n\nSupporting relays MUST only activate the registration if the \"relay\" tag matches their own URL.\n\nSupporting relays MUST reply with custom OK messages: \n- `[\"OK\", \"b1a649ebe8...\", true, \"subscribed\"]` when the relay will fulfill the subscription\n- `[\"OK\", \"b1a649ebe8...\", false, \"<error_message>\"]` when the relay will not fulfill the subscription\n\nClients should check the \"subscribed\" return to see if the relay supports the type of hook the client is creating.\n\nIf the `callback` URL responds with a `404` status code, the relay SHOULD delete the subscription. Relays MAY delete subscriptions at their discretion (e.g., due to expiration, inactivity, callback `500` errors, etc).\n\n## Example\n\nIn this case, a hook for replies and reactions citing a user OR a hashtag the user is following, ignoring anything that tags `footstr`, are forwarded to Amethyst's Push server.\n\n```yaml\n{\n  kind: 30027,\n  tags: [\n    [\"d\", \"amethyst-push-notifications\"],\n    [\"relay\", \"wss://nos.lol/\"],\n    [\"filter\", \"{\\\"kinds\\\": [1, 7], \\\"#p\\\": [\\\"<user pubkey>\\\"]}\"],\n    [\"filter\", \"{\\\"kinds\\\": [1, 7], \\\"#t\\\": [\\\"<following hashtag>\\\"]}\"],\n    [\"ignore\", \"{\\\"#t\\\": [\\\"footstr\\\"]}\"],\n    [\"callback\", \"https://push.amethyst.social/\"]\n  ],\n}\n```","sig":"b210aa675e9036fcd2880de3a4f4f0b648651bac14c5e62dce658101a2493c1dfc817fb7c08af4b2674d075bc7933bf9ea0a394f4ada348c16a41c46c96f07a9"}