Nostr.Event.Comment (Nostr Lib v0.2.1) (event) (nip22)

View Source

Comment (Kind 1111)

Threading comments for any Nostr event or external content. This is different from NIP-10 replies to kind:1 notes - use Nostr.Event.Note.reply/3 for those.

Tag Scopes

Comments use uppercase tags for ROOT scope (the original item being commented on) and lowercase tags for PARENT scope (the direct parent in a thread).

Root Scope (uppercase):

  • E - Event ID reference
  • A - Addressable event reference (kind:pubkey:d-tag)
  • I - External content identifier (URL, ISBN, etc.)
  • K - Root item kind (integer for events, string like "web" for external)
  • P - Root author pubkey

Parent Scope (lowercase):

  • e, a, i - Same as above but for direct parent
  • k - Parent kind (e.g., "1111" for replies to comments)
  • p - Parent author pubkey

For top-level comments, root and parent reference the same item. For replies to comments, root stays the original item, parent is the comment.

Defined in NIP 22 https://github.com/nostr-protocol/nips/blob/master/22.md

Summary

Functions

Creates a top-level comment on an addressable event.

Creates a top-level comment on external content.

Parses a kind 1111 event into a Comment struct.

Creates a reply to another comment.

Types

author()

@type author() :: %{pubkey: binary(), relay: binary() | nil}

ref()

@type ref() :: %{
  type: :E | :A | :I | :e | :a | :i,
  id: binary(),
  relay: binary() | nil,
  pubkey: binary() | nil
}

t()

@type t() :: %Nostr.Event.Comment{
  content: binary(),
  event: Nostr.Event.t(),
  mentions: [author()],
  parent_author: author(),
  parent_kind: integer() | binary(),
  parent_ref: ref(),
  quotes: [ref()],
  root_author: author(),
  root_kind: integer() | binary(),
  root_ref: ref()
}

Functions

comment_on_address(content, address, event_kind, event_author, opts \\ [])

@spec comment_on_address(binary(), binary(), integer(), binary(), Keyword.t()) :: t()

Creates a top-level comment on an addressable event.

Arguments

  • content - Comment text
  • address - Address in format "kind:pubkey:d-tag"
  • event_kind - Kind of the addressable event
  • event_author - Pubkey of the event author
  • opts - Optional arguments (same as comment_on_event/5)

Example

Comment.comment_on_address(
  "Interesting perspective",
  "30023:pubkey123:my-article",
  30023,
  "pubkey123..."
)

comment_on_event(content, event_id, event_kind, event_author, opts \\ [])

@spec comment_on_event(binary(), binary(), integer(), binary(), Keyword.t()) :: t()

Creates a top-level comment on an event.

Arguments

  • content - Comment text
  • event_id - ID of the event being commented on
  • event_kind - Kind of the event being commented on
  • event_author - Pubkey of the event author
  • opts - Optional arguments

Options

  • :relay - Relay hint for the target event
  • :pubkey - Comment author pubkey
  • :created_at - Event timestamp
  • :quotes - List of quoted event tuples {event_id, relay, pubkey}
  • :mentions - List of mentioned pubkey tuples {pubkey, relay}

Example

Comment.comment_on_event(
  "Great article!",
  "abc123...",
  30023,
  "author_pubkey...",
  relay: "wss://relay.example.com"
)

comment_on_external(content, identifier, kind_type, opts \\ [])

@spec comment_on_external(binary(), binary(), binary(), Keyword.t()) :: t()

Creates a top-level comment on external content.

Arguments

  • content - Comment text
  • identifier - External identifier (URL, ISBN, podcast GUID, etc.)
  • kind_type - Type string (e.g., "web", "podcast:item:guid", "isbn")
  • opts - Optional arguments

Options

  • :hint - Hint for the identifier (e.g., URL for web content)
  • :pubkey - Comment author pubkey
  • :created_at - Event timestamp
  • :quotes - List of quoted event tuples
  • :mentions - List of mentioned pubkey tuples

Example

Comment.comment_on_external(
  "This is a great resource!",
  "https://example.com/article",
  "web"
)

parse(event)

@spec parse(Nostr.Event.t()) :: t()

Parses a kind 1111 event into a Comment struct.

reply(content, parent, opts \\ [])

@spec reply(binary(), t(), Keyword.t()) :: t()

Creates a reply to another comment.

The root scope is inherited from the parent comment, while parent scope references the comment being replied to.

Arguments

  • content - Reply text
  • parent - The Comment struct being replied to
  • opts - Optional arguments

Options

  • :relay - Relay hint for the parent comment
  • :pubkey - Reply author pubkey
  • :created_at - Event timestamp
  • :quotes - List of quoted event tuples
  • :mentions - List of mentioned pubkey tuples

Example

Comment.reply("I agree!", parent_comment, relay: "wss://relay.example.com")