# Text Message

## Send a Text Message

In a chat application, it's essential to send text messages to each other in real-time, allowing for quick and easy communication. Users can also view previous messages sent and received within the chat, allowing them to reference past conversations as needed.

The `sendTextMessage` function is a feature provided by the social.plus chat SDK that enables users to send plain text messages in a [subchannel](https://docs.social.plus/social-plus-sdk/chat/channels/subchannel "mention"). This function requires two parameters: `text` and `subchannelId`.

Here is a brief explanation of the function parameters:

* `text`: A string that contains the text message that the user wants to send. This parameter is mandatory as it contains the actual message content.
* `subchannelId`: An identifier for the subchannel where the message will be sent. Subchannels are subdivisions within a channel that represent individual topics or chat threads. Messages and interactions occur within subchannels, not the main channel itself.
* `metaData`: Additional properties to support custom fields.
* `tags` - Arbitrary strings that can be used for defining and querying the messages.

{% tabs %}
{% tab title="iOS" %}
**Version 6**

{% embed url="<https://gist.github.com/amythee/8caf4860ff3c6255b8c4b825e26cc089>" %}

**Version 5 (Maintained)**

{% embed url="<https://gist.github.com/amythee/3abe32253b20e25ee4b710942a4f806f>" %}
{% endtab %}

{% tab title="Android" %}
**Version 6**

{% embed url="<https://gist.github.com/amythee/284bdf467ea8fe7a136400d3b13287ea>" %}

**Version 5 (Maintained)**

{% embed url="<https://gist.github.com/amythee/6bc19f3db1e24e8a31af236f1823f961>" %}
{% endtab %}

{% tab title="JavaScript" %}

```javascript
import { MessageRepository } from '@amityco/js-sdk';

const liveObject = MessageRepository.createTextMessage({
  channelId: 'channel1',
  text: 'Hello World!',
});

liveObject.on('dataUpdate', message => {
  console.log('message is created', message);
});
```

When creating a message, we can also pass the `parentId` to make it appear under a parent.

```javascript
import { MessageRepository } from '@amityco/js-sdk';

const messageLiveObject = MessageRepository.createTextMessage({
  channelId: 'channel1',
  text: 'Hello World!',
  parentId: 'exampleParentMessageId,
  tags: ['tag1', 'tag2'],
  mentionees: [
    {
      "type": "user",
      "userIds": [
        "user1", “user2”
      ]
    }
  ]
});
```

{% endtab %}

{% tab title="TypeScript" %}
Version 6

{% embed url="<https://gist.github.com/amythee/59381404ca924023929f1042c315b5ae#file-createtextmessage-ts>" %}

Beta (v0.0.1)

{% embed url="<https://gist.github.com/f0ccc6a26f58792e70738a026bdfa8ad>" %}
{% endtab %}

{% tab title="Flutter" %}
{% embed url="<https://gist.github.com/amythee/cdfb7544aea37943da47bf688266ce6d#file-amitymessagetextcreate-dart>" %}
{% endtab %}
{% endtabs %}

{% hint style="warning" %}
The limit for sending text messages is 10,000 characters per text message. Messages exceeding that limit will return an error and will not be sent.
{% endhint %}
