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

# Text Posts

> Create text posts with the current social.plus SDKs, including optional structured links where supported.

Text posts publish written content to a user feed, a community feed, or the current user's own feed. Use them for plain updates, status messages, and posts that attach structured link metadata.

<Info>
  The text is the parent post content. The SDK creation fields below describe the SDK API; UIKit's product-tag UI is a separate surface and may support fewer post types. See [UIKit Product Tagging](/uikit/components/social/product-tagging) for the UI-specific coverage.
</Info>

<CardGroup cols={2}>
  <Card title="Flexible Targets" icon="users-viewfinder">
    Publish to user feeds, community feeds, or the current user's feed depending on the SDK target API.
  </Card>

  <Card title="Optional Enrichment" icon="link">
    TypeScript, Android, and iOS can attach structured links during text post creation.
  </Card>
</CardGroup>

## Parameters

| Parameter | Required | Platforms | Description |
| - | - | - | - |
| `text` | Yes | TypeScript, iOS, Android, Flutter | Text content for the post body. |
| `targetType` | Yes for explicit feed targets | TypeScript, iOS, Android, Flutter | Feed target, usually `community` or `user`. |
| `targetId` | Yes for explicit feed targets | TypeScript, iOS, Android, Flutter | Community ID or user ID for the target feed. |
| `metadata` | No | TypeScript, iOS, Android, Flutter | Custom metadata stored with the post where supported. |
| `mentionees` | No | TypeScript, iOS, Android, Flutter | User mention payload where supported by the platform builder. |
| `links` | No | TypeScript, Android, iOS | Structured link metadata supported by TypeScript, Android, and iOS. |
| `productTags` | No | TypeScript, Android, iOS | Products tagged in the post text. Text product tag types: `Amity.TextProductTag`, `AmityTextProductTag`, `AmityProductTag.Text`. |

<Note>
  **Product tags (SDK API).** `productTags` tags products mentioned in the post **text**. Each tag names a product and the character range it covers in that text. Media product tags do not apply to a text-only post. When a post also has media, the text remains on the parent and the media is a child; use the media page's `attachmentProductTags` for that child. See [Image Post](./image-post) or [Video Post](./video-post) for those fields. Flutter does not expose product tags on any post builder. For tagging limits and tap-through behavior, see [Product Tagging](/uikit/components/social/posts#product-tagging).
</Note>

## Create a Text Post

The examples below create a text post in a community. Use the equivalent user target method or target type when posting to a user feed.

<CodeGroup>
  ```swift iOS theme={null}
  let postRepository = AmityPostRepository()
  let builder = AmityTextPostBuilder()
  builder.setText("Hello community")

  let post = try await postRepository.createTextPost(
      builder,
      targetId: communityId,
      targetType: .community,
      metadata: nil,
      mentionees: nil
  )
  ```

  ```kotlin Android theme={null}
  postRepository.createTextPost(
      targetType = AmityPost.TargetType.COMMUNITY,
      targetId = communityId,
      text = "Hello community"
  )
      .subscribe({ post ->
          showSuccessMessage(post.getPostId())
      }, { error ->
          handleGeneralError(error)
      })
  ```

  ```typescript TypeScript theme={null}
  import { PostRepository } from "@amityco/ts-sdk";

  const { data: post } = await PostRepository.createPost({
    targetType: "community",
    targetId: communityId,
    data: {
      text: "Hello community",
    },
  });
  ```

  ```dart Flutter theme={null}
  final post = await AmitySocialClient.newPostRepository()
      .createPost()
      .targetCommunity(communityId)
      .text('Hello community')
      .createTextPost();
  ```
</CodeGroup>

## Add Structured Links

TypeScript, Android, and iOS expose a `links` field when creating a text post. Fetch preview metadata first if the post should render a preview card.

<Note>
  Flutter's current public post creation builder supports text, metadata, and user mentions, but it does not expose a structured `links` payload on the text post builder.
</Note>

<CodeGroup>
  ```swift iOS theme={null}
  let postRepository = AmityPostRepository()
  let builder = AmityTextPostBuilder()
  builder.setText("Check this out https://www.amity.co")

  let preview = try await client.getLinkPreviewMetadata(url: "https://www.amity.co")
  let links = [
      AmityLink(
          url: "https://www.amity.co",
          renderPreview: true,
          domain: preview.domain,
          title: preview.title,
          imageUrl: preview.imageUrl
      )
  ]

  let post = try await postRepository.createTextPost(
      builder,
      targetId: communityId,
      targetType: .community,
      metadata: nil,
      mentionees: nil,
      links: links
  )
  ```

  ```kotlin Android theme={null}
  AmityCoreClient.getLinkPreviewMetadata("https://www.amity.co")
      .flatMap { preview ->
          val links = listOf(
              AmityLink(
                  index = null,
                  length = null,
                  url = "https://www.amity.co",
                  renderPreview = true,
                  domain = preview.getDomain(),
                  title = preview.getTitle(),
                  imageUrl = preview.getImageUrl()
              )
          )

          postRepository.createTextPost(
              targetType = AmityPost.TargetType.COMMUNITY,
              targetId = communityId,
              text = "Check this out https://www.amity.co",
              links = links
          )
      }
      .subscribe({ post ->
          showSuccessMessage(post.getPostId())
      }, { error ->
          handleGeneralError(error)
      })
  ```

  ```typescript TypeScript theme={null}
  import { Client, PostRepository } from "@amityco/ts-sdk";

  const preview = await Client.getLinkPreviewMetadata("https://www.amity.co");

  const { data: post } = await PostRepository.createPost({
    targetType: "community",
    targetId: communityId,
    data: {
      text: "Check this out https://www.amity.co",
    },
    links: [
      {
        url: "https://www.amity.co",
        renderPreview: true,
        domain: preview.domain ?? undefined,
        title: preview.title ?? undefined,
        imageUrl: preview.imageUrl ?? undefined,
      },
    ],
  });
  ```
</CodeGroup>

## Tag Products in the Text

TypeScript, Android, and iOS accept a `productTags` array when creating a text post. Each tag names a product and the character range it covers in the post text, so UIKit can render that range as a tappable product mention.

<Note>
  Set `index` and `length` against the same string you pass as `text`. In the examples below, `featured product` starts at index 12 and is 16 characters long. iOS stores only the range. TypeScript and Android also carry the matched `text`.
</Note>

<CodeGroup>
  ```swift iOS theme={null}
  let postRepository = AmityPostRepository()
  let builder = AmityTextPostBuilder()
  builder.setText("Loving this featured product for my morning runs!")

  let post = try await postRepository.createTextPost(
      builder,
      targetId: communityId,
      targetType: .community,
      metadata: nil,
      mentionees: nil,
      productTags: [
          AmityTextProductTag(productId: "prod_001", index: 12, length: 12)
      ]
  )
  ```

  ```kotlin Android theme={null}
  postRepository.createTextPost(
      targetType = AmityPost.TargetType.COMMUNITY,
      targetId = communityId,
      text = "Loving this featured product for my morning runs!",
      productTags = listOf(
          AmityProductTag.Text(
              productId = "prod_001",
              text = "featured product",
              index = 12,
              length = 16
          )
      )
  )
      .subscribe({ post ->
          showSuccessMessage(post.getPostId())
      }, { error ->
          handleGeneralError(error)
      })
  ```

  ```typescript TypeScript theme={null}
  import { PostRepository } from "@amityco/ts-sdk";

  const { data: post } = await PostRepository.createPost({
    targetType: "community",
    targetId: communityId,
    data: {
      text: "Loving this featured product for my morning runs!",
    },
    productTags: [
      { productId: "prod_001", text: "featured product", index: 12, length: 16 },
    ],
  });
  ```
</CodeGroup>

## Query Text Posts

Post query APIs are SDK-specific. For TypeScript, `PostRepository.getPosts` returns a live collection through a callback instead of a promise, so do not call it with `await`.

For structure type values and filtering behavior, see [Posts Overview](../overview) and [Mixed Media Posts](./mixed-media-post).

## Related Topics

<CardGroup cols={3}>
  <Card title="Posts Overview" icon="newspaper" href="../overview">
    Review post concepts, retrieval, and moderation flows.
  </Card>

  <Card title="Query Posts" icon="list" href="../retrieval/query-posts">
    Load text posts back into feed and detail screens.
  </Card>

  <Card title="Mentions" icon="at-sign" href="/social-plus-sdk/core-concepts/content-handling/mentions">
    Add user mention payloads where the platform exposes them.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.