class Attio::Comment

Comments are immutable once created
Represents a comment in an Attio thread

def self.create(content: nil, format: "plaintext", author: nil, thread_id: nil, created_at: nil, **opts)

Custom create implementation
def self.create(content: nil, format: "plaintext", author: nil, thread_id: nil, created_at: nil, **opts)
  raise ArgumentError, "Content is required" if content.nil? || content.to_s.empty?
  raise ArgumentError, "Thread ID is required" if thread_id.nil? || thread_id.to_s.empty?
  raise ArgumentError, "Author is required" if author.nil?
  request_params = {
    data: {
      format: format,
      content: content,
      author: author,
      thread_id: thread_id
    }
  }
  # Only add created_at if provided
  request_params[:data][:created_at] = created_at if created_at
  response = execute_request(:POST, resource_path, request_params, opts)
  new(response["data"] || response, opts)
end

def self.resource_path

Returns:
  • (String) - The API path
def self.resource_path
  "comments"
end

def destroy(**opts)

Override destroy to use the correct comment ID
def destroy(**opts)
  raise InvalidRequestError, "Cannot destroy a comment without an ID" unless persisted?
  comment_id = extract_comment_id
  self.class.send(:execute_request, :DELETE, "#{self.class.resource_path}/#{comment_id}", {}, opts)
  @attributes.clear
  @changed_attributes.clear
  @id = nil
  true
end

def extract_comment_id

def extract_comment_id
  case id
  when Hash
    id[:comment_id] || id["comment_id"]
  else
    id
  end
end

def immutable?

Comments are immutable
def immutable?
  true
end

def inspect

def inspect
  "#<#{self.class.name}:#{object_id} id=#{id.inspect} thread=#{thread_id} content=#{content_plaintext&.truncate(30).inspect}>"
end

def resolved_at

Parse resolved_at as Time
def resolved_at
  value = @attributes[:resolved_at]
  return nil if value.nil?
  case value
  when Time
    value
  when String
    Time.parse(value)
  else
    value
  end
end

def resource_path

def resource_path
  comment_id = extract_comment_id
  "#{self.class.resource_path}/#{comment_id}"
end

def save(**opts)

Override save to raise error since comments are immutable
def save(**opts)
  raise InvalidRequestError, "Comments are immutable and cannot be updated"
end

def to_h

def to_h
  {
    id: id,
    thread_id: thread_id,
    content_plaintext: content_plaintext,
    entry: entry,
    record: record,
    resolved_at: resolved_at&.iso8601,
    resolved_by: resolved_by,
    created_at: created_at&.iso8601,
    author: author
  }.compact
end