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):

  • e tag (required) - event ID being reacted to, with optional relay hint and pubkey hint
  • p tag (recommended) - pubkey of event author
  • a tag (for addressable events) - coordinates of the event (kind:pubkey:d-tag)
  • k tag (optional) - kind number of the reacted event
  • emoji tag (for custom emoji) - NIP-30 custom emoji definition

Kind 17 (external content reactions):

  • k + i tags per NIP-73 for external content reference

Summary

Functions

Creates a new reaction event (kind 7).

Parses a kind 7 event into a Reaction struct.

Types

t()

@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

create(event_id, reaction \\ "+", opts \\ [])

@spec create(event_id :: binary(), reaction :: String.t(), opts :: Keyword.t()) :: t()

Creates a new reaction event (kind 7).

Arguments

  • event_id - the ID of the event being reacted to
  • reaction - 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, the kind:pubkey:d-tag coordinates
    • :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"
)

parse(event)

@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.