Nostr. Event. Reaction
(Nostr Lib v0.2.1)
(event)
(nip25)
View Source
Post reaction (kind 7) and external content reaction (kind 17).
Defined in NIP-25: https://github.com/nostr-protocol/nips/blob/master/25.md
Reaction Content
+or empty string - interpreted as "like" or "upvote"-- interpreted as "dislike" or "downvote"- emoji or NIP-30 custom emoji - displayed as emoji reaction
Tags
Kind 7 (nostr event reactions):
etag (required) - event ID being reacted to, with optional relay hint and pubkey hintptag (recommended) - pubkey of event authoratag (for addressable events) - coordinates of the event (kind:pubkey:d-tag)ktag (optional) - kind number of the reacted eventemojitag (for custom emoji) - NIP-30 custom emoji definition
Kind 17 (external content reactions):
k+itags per NIP-73 for external content reference
Summary
Types
@type t() :: %Nostr.Event.Reaction{ address: binary() | nil, author: binary() | nil, emoji_url: binary() | nil, event: Nostr.Event.t(), kind: non_neg_integer() | nil, post: binary() | nil, reaction: String.t(), relay_hint: binary() | nil, user: binary() }
Functions
Creates a new reaction event (kind 7).
Arguments
event_id- the ID of the event being reacted toreaction- the reaction content (+,-, emoji, or:shortcode:)opts- keyword options::pubkey- pubkey of the reactor (required for unsigned events):author- pubkey of the event author (recommended):relay_hint- relay URL where the reacted event can be found:kind- kind number of the reacted event:address- for addressable events, thekind:pubkey:d-tagcoordinates:emoji_url- URL for custom emoji (when reaction is:shortcode:):tags- additional tags to include:created_at- timestamp (defaults to now)
Examples
# Simple like
Reaction.create("event_id", "+", author: "author_pubkey")
# Reaction with relay hint
Reaction.create("event_id", "+",
author: "author_pubkey",
relay_hint: "wss://relay.example.com",
kind: 1
)
# Custom emoji reaction
Reaction.create("event_id", ":soapbox:",
author: "author_pubkey",
emoji_url: "https://example.com/soapbox.png"
)
@spec parse(event :: Nostr.Event.t()) :: t() | {:error, String.t(), Nostr.Event.t()}
Parses a kind 7 event into a Reaction struct.
Per NIP-25, if multiple e or p tags exist, the last one is the target.