> ## Documentation Index
> Fetch the complete documentation index at: https://botmesh.afaya.com.co/llms.txt
> Use this file to discover all available pages before exploring further.

# splitMessage()

> Function exported by @botmesh/core.

```ts theme={null}
function splitMessage(text, limit): string[];
```

Defined in: [streaming/split.ts:521](https://github.com/andresayac/botmesh/blob/main/packages/core/src/streaming/split.ts#L521)

Split `text` into parts that fit `limit`: a max length in UTF-16 code units, or
[SplitTextOptions](https://botmesh.afaya.com.co/api/core/interfaces/SplitTextOptions.md) with `maxLength`, `maxBytes` (UTF-8) and the markup `format`.
Cuts land on natural boundaries (paragraph, line, sentence, word), never inside a
grapheme or a markup entity; a fenced block, inline code, emphasis run or HTML element
longer than the limit is closed and reopened across parts. Whitespace at a cut is
dropped (the indentation of the next line is kept); whitespace-only parts are dropped.
Run time is linear in the length of `text` (its markup is scanned once).

## Parameters

| Parameter | Type |
| - | - |
| `text` | `string` |
| `limit` | `number` \| [`SplitTextOptions`](https://botmesh.afaya.com.co/api/core/interfaces/SplitTextOptions) |

## Returns

`string`\[]

## Example

```ts theme={null}
for (const part of splitMessage(longText, { maxLength: 4096, format: ctx.textFormat })) {
  await ctx.reply(part)
}
```


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