> ## Documentation Index
> Fetch the complete documentation index at: https://social-b97141fb-auto-generate-llmstxt.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Reply to a Message

> Create threaded chat replies by setting a parent message ID.

Use `parentId` to create a reply to an existing message. The reply still targets the same `subChannelId`; `parentId` links it to the parent message for threaded rendering and reply queries.

<Info>
  Replies are created with the same message-type APIs as top-level messages. Set `parentId` before sending the text, media, or custom message.
</Info>

## Parameters

| Parameter                   | Required | Description                                                                         |
| --------------------------- | -------- | ----------------------------------------------------------------------------------- |
| `subChannelId`              | Yes      | Target subchannel for the reply; use the same subchannel as the parent message.     |
| `parentId`                  | Yes      | Message ID of the parent message being replied to.                                  |
| Message type                | Yes      | Text, media, or custom message type selected with the platform-specific create API. |
| Message body or media input | Yes      | Text/custom payload or media file input for the reply.                              |
| `tags`                      | No       | App-defined tags for later filtering or grouping.                                   |
| `metadata`                  | No       | App-defined metadata stored with the reply.                                         |

## Reply With Text

Create a text reply by setting `parentId` to the message being replied to.

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

  const { data: reply } = await MessageRepository.createMessage({
    subChannelId,
    parentId: messageId,
    dataType: 'text',
    data: {
      text: 'Replying in thread',
    },
  });

  renderResults(reply);
  ```

  ```swift iOS theme={null}
  let options = AmityTextMessageCreateOptions(
      subChannelId: "sub-channel-id",
      text: "Replying in thread",
      parentId: "parent-message-id"
  )

  let reply = try await messageRepository.createTextMessage(options: options)
  showSuccessMessage(reply.messageId)
  ```

  ```kotlin Android theme={null}
  val disposable = AmityChatClient.newMessageRepository()
      .createTextMessage(
          subChannelId = subChannelId,
          text = "Replying in thread",
      )
      .parentId(messageId)
      .build()
      .send()
      .subscribe(
          { showSuccessMessage() },
          { error -> handleGeneralError(error) },
      )
  ```

  ```dart Flutter theme={null}
  final reply = await AmityChatClient.newMessageRepository()
      .createMessage(subChannelId)
      .parentId(messageId)
      .text('Replying in thread')
      .send();

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

## Reply With Media Or Custom Data

Use the same reply pattern with media or custom payloads when the reply is not plain text.

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

  const { data: imageReply } = await MessageRepository.createMessage({
    subChannelId,
    parentId: messageId,
    dataType: 'image',
    fileId,
  });
  ```

  ```kotlin Android theme={null}
  val disposable = AmityChatClient.newMessageRepository()
      .createImageMessage(
          subChannelId = subChannelId,
          attachment = AmityMessageAttachment.FILE_ID(fileId),
      )
      .parentId(messageId)
      .build()
      .send()
      .subscribe()
  ```
</CodeGroup>

## Query Reply Threads

After creating replies, query messages by `parentId` when you need to render a thread. See [Query & Filter Messages](../messages/query-and-filter-messages) for platform-specific query examples.

## Related Topics

<CardGroup cols={2}>
  <Card title="Text Message" href="./text-message" icon="message-square">
    Create text messages and text replies.
  </Card>

  <Card title="Query Messages" href="../messages/query-and-filter-messages" icon="list-filter">
    Query top-level messages and replies.
  </Card>
</CardGroup>
