> ## 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.

# Send a Message

> Choose the right SDK create-message API for each chat message type.

Use message creation APIs after your app has resolved the target `subChannelId`. Text and custom messages send structured data directly. Media messages send an uploaded file ID, attachment object, or file URI depending on platform.

<CardGroup cols={2}>
  <Card title="Text" href="./text-message" icon="message-square">
    Send plain text with optional tags, metadata, mentions, and reply parent IDs.
  </Card>

  <Card title="Image" href="./image-message" icon="image">
    Send image messages with platform-specific file ID, attachment, or URI input.
  </Card>

  <Card title="File" href="./file-message" icon="file">
    Send generic file attachments.
  </Card>

  <Card title="Video" href="./video-message" icon="video">
    Send video attachments where the platform SDK supports video message creation.
  </Card>

  <Card title="Audio" href="./audio-message" icon="mic">
    Send audio attachments on TypeScript, iOS, and Android.
  </Card>

  <Card title="Custom" href="./custom-message" icon="braces">
    Send app-defined JSON-style message payloads.
  </Card>
</CardGroup>

## Parameters

| Parameter      | Required | Description                                                                                                       |
| -------------- | -------- | ----------------------------------------------------------------------------------------------------------------- |
| `subChannelId` | Yes      | Target subchannel where the message will be created.                                                              |
| Message type   | Yes      | SDK-specific message type selector, such as `dataType: 'text'`, `createTextMessage(...)`, or `.text(...)`.        |
| Message body   | Depends  | Required for text and custom messages; use text strings or JSON-serializable custom payloads.                     |
| Media input    | Depends  | Required for media messages; use a TypeScript file ID, native attachment, or Flutter `Uri` depending on platform. |
| `parentId`     | No       | Parent message ID when creating a reply instead of a top-level message.                                           |
| `tags`         | No       | App-defined tags for later filtering or grouping.                                                                 |
| `metadata`     | No       | App-defined JSON-style metadata stored with the message.                                                          |

## Send A Text Message

Create a text message after resolving the target `subChannelId`.

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

  const { data: message } = await MessageRepository.createMessage({
    subChannelId,
    dataType: 'text',
    data: {
      text: 'Hello from chat',
    },
  });

  renderResults(message);
  ```

  ```swift iOS theme={null}
  let options = AmityTextMessageCreateOptions(
      subChannelId: "sub-channel-id",
      text: "Hello from chat"
  )

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

  ```kotlin Android theme={null}
  val disposable = AmityChatClient.newMessageRepository()
      .createTextMessage(
          subChannelId = subChannelId,
          text = "Hello from chat",
      )
      .build()
      .send()
      .subscribe(
          { showSuccessMessage() },
          { error -> handleGeneralError(error) },
      )
  ```

  ```dart Flutter theme={null}
  final message = await AmityChatClient.newMessageRepository()
      .createMessage(subChannelId)
      .text('Hello from chat')
      .send();

  final messageId = message.messageId;
  ```
</CodeGroup>

## Return Shapes

| Platform   | Create call result                                                        |
| ---------- | ------------------------------------------------------------------------- |
| TypeScript | Resolves to `{ data: Amity.Message, cachedAt?: number }`                  |
| iOS        | Returns `AmityMessage` from the async repository call                     |
| Android    | Returns a `Completable`; observe the message list for the created message |
| Flutter    | Returns `Future<AmityMessage>`                                            |

## Related Topics

<CardGroup cols={2}>
  <Card title="Text Message" href="./text-message" icon="message-square">
    Add text, tags, metadata, mentions, and replies.
  </Card>

  <Card title="Reply to a Message" href="./reply-to-a-message" icon="reply">
    Use `parentId` to create message replies.
  </Card>

  <Card title="Query Messages" href="../messages/query-and-filter-messages" icon="list-filter">
    Observe sent messages in the target subchannel.
  </Card>

  <Card title="Message Flagging" href="../message-flagging" icon="flag">
    Add report actions to sent or received messages.
  </Card>
</CardGroup>
