Splitting and validation
Adapters own their platform text limits; the shared package provides the splitting helpers and the portable payload validators they all build on. See Channel core for the full utility map.
Splitting and platform limits
Each adapter owns its platform's text limit through splitMessage(). The package exports the two helpers adapters build on: splitChannelText() splits plain text, and splitChannelMessage() splits a complete portable message:
import { splitChannelMessage, splitChannelText } from '@anvia/channel'
const textParts = splitChannelText({ text: longReport, maximumLength: 2_000 })
const parts = splitChannelMessage({ message, maximumLength: 2_000 })Splitting behavior:
- Boundaries prefer readability: the last newline before the limit, then the last space, then a hard cut.
maximumLengthmust be a positive safe integer (TypeErrorotherwise); amaximumLengthtoo small to hold one Unicode character throws aRangeError.- Empty text throws a
TypeError; a media-only message (text: ''plus attachments) becomes a single part. replyToMessageIdis copied to every part.actionsandattachmentsare placed only on the final part.
Runtime validation
sendChannelMessage() validates actions and attachments up front, and every platform send() validates again before delivery. Call the validators yourself when you build UI constraints or accept user-supplied payloads:
import {
validateChannelActions,
validateChannelAttachments,
validateChannelMessage,
} from '@anvia/channel'
validateChannelMessage(message) // checks actions and attachments
validateChannelActions(message.actions)
validateChannelAttachments(message.attachments)The validators throw a TypeError for malformed values and a RangeError for limit violations. The portable limits:
- At most 5 actions per message (
MAX_CHANNEL_ACTIONS). - Action labels contain between 1 and 80 characters (
MAX_CHANNEL_ACTION_LABEL_LENGTH). - Action IDs are non-empty and unique within a message (
TypeErrorwhen empty or duplicated) and at most 64 UTF-8 bytes (RangeErrorwhen overlong;isChannelActionId()checks the shape). - Action
styleis'default','primary', or'danger'(default when omitted); anything else throws aTypeError. - At most 10 outbound attachments per logical message (
MAX_CHANNEL_ATTACHMENTS). - Attachment
urlsources must use HTTPS;datasources must be valid base64.mediaTypemust be non-empty,filenamenon-empty when present, andsizea non-negative safe integer when present. - When present,
actionsandattachmentsmust be non-empty arrays.
validateChannelMessage() checks only actions and attachments — it does not validate text length, which is the adapter's splitMessage() job. Use the exported MAX_CHANNEL_* constants when an application UI needs to enforce the same limits.
Continue with
- Send channel messages — how splitting applies during delivery.
- Capabilities and rate limits — gate optional operations and pace outbound calls.