> ## Documentation Index
> Fetch the complete documentation index at: https://learn.social.plus/llms.txt
> Use this file to discover all available pages before exploring further.

# Text Comment

> Create text comments and replies on posts, stories, or custom content.

Create a text comment by passing a reference target and text body to the comment repository. To create a reply, pass the parent comment ID with the same reference target.

## Parameters

| Parameter                      | Required | Description                                                      |
| ------------------------------ | -------- | ---------------------------------------------------------------- |
| `referenceId`                  | Yes      | ID of the post, story, or custom content item being commented on |
| `referenceType`                | Yes      | Use `post`, `story`, or `content`                                |
| `text`                         | Yes      | Text body of the comment                                         |
| `parentId`                     | No       | Existing comment ID when creating a reply                        |
| `metadata`                     | No       | Custom metadata attached to the comment                          |
| `mentionees` / mention builder | No       | User mention payloads                                            |
| `links`                        | No       | Link metadata on TypeScript, iOS, and Android                    |

<Info>
  The current Flutter public comment creation builder exposes `metadata(...)` and `mentionUsers(...)`, but it does not expose a `links(...)` method.
</Info>

## Create a Text Comment

Create a top-level text comment with the reference target and text body.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { CommentRepository } from "@amityco/ts-sdk";

  const { data: comment } = await CommentRepository.createComment({
    referenceId: postId,
    referenceType: "post",
    data: {
      text: "Hello world!",
    },
  });

  renderResults(comment);
  ```

  ```swift iOS theme={null}
  let options = AmityCommentCreateOptions(
      referenceId: "post-id",
      referenceType: .post,
      text: "Hello world!"
  )

  let comment = try await commentRepository.createComment(with: options)
  showSuccessMessage(comment.commentId)
  ```

  ```kotlin Android theme={null}
  AmitySocialClient.newCommentRepository()
      .createComment()
      .post(postId = postId)
      .with()
      .text(text = "Hello world!")
      .build()
      .send()
      .subscribe(
          { comment -> showSuccessMessage(comment.getCommentId()) },
          { error -> handleGeneralError(error) }
      )
  ```

  ```dart Flutter theme={null}
  final comment = await AmitySocialClient.newCommentRepository()
      .createComment()
      .post(postId)
      .create()
      .text('Hello world!')
      .send();

  final commentId = comment.commentId;
  ```
</CodeGroup>

## Reply to a Comment

Replies use the same creation API with `parentId` set to the comment being replied to.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { CommentRepository } from "@amityco/ts-sdk";

  const { data: reply } = await CommentRepository.createComment({
    referenceId: postId,
    referenceType: "post",
    parentId: commentId,
    data: {
      text: "Replying to this comment",
    },
  });

  renderResults(reply);
  ```

  ```swift iOS theme={null}
  let options = AmityCommentCreateOptions(
      referenceId: "post-id",
      referenceType: .post,
      text: "Replying to this comment",
      parentId: "parent-comment-id"
  )

  let reply = try await commentRepository.createComment(with: options)
  showSuccessMessage(reply.commentId)
  ```

  ```kotlin Android theme={null}
  AmitySocialClient.newCommentRepository()
      .createComment()
      .post(postId = postId)
      .parentId(parentId = commentId)
      .with()
      .text(text = "Replying to this comment")
      .build()
      .send()
      .subscribe(
          { reply -> showSuccessMessage(reply.getCommentId()) },
          { error -> handleGeneralError(error) }
      )
  ```

  ```dart Flutter theme={null}
  final reply = await AmitySocialClient.newCommentRepository()
      .createComment()
      .post(postId)
      .parentId(commentId)
      .create()
      .text('Replying to this comment')
      .send();

  final replyId = reply.commentId;
  ```
</CodeGroup>

## Notes

* Keep the same `referenceId` and `referenceType` as the thread you are replying in.
* Use query APIs or live collections to display creation and sync state in the UI.
* Validate your product's text limits and moderation rules before calling the SDK.
* Build mention payloads from the user IDs your mention picker returns.

## Related Topics

<CardGroup cols={2}>
  <Card title="Image Comment" icon="image" href="./image-comment">
    Create comments with uploaded image attachments.
  </Card>

  <Card title="Query Comments" icon="filter" href="../retrieval/query-comments">
    Query top-level comments and reply threads.
  </Card>
</CardGroup>
