RocketChat/Rocket.Chat · error · Error

message-length-exceeds-character-limit

Error message

message-length-exceeds-character-limit

What it means

Thrown by POST /livechat/message (message.ts:45-50) when the setting `Livechat_enable_message_character_limit` is true and msg.length exceeds parseInt(`Livechat_message_character_limit`). This is a configurable server-side cap on visitor message length. Returns HTTP 400 { success:false, error:'message-length-exceeds-character-limit' }.

Source

Thrown at apps/meteor/server/api/v1/omnichannel/message.ts:49

			const guest = await findGuest(token);
			if (!guest) {
				throw new Error('invalid-token');
			}

			const room = await findRoom(token, rid);
			if (!room) {
				throw new Error('invalid-room');
			}

			if (!room.open) {
				throw new Error('room-closed');
			}

			if (
				settings.get('Livechat_enable_message_character_limit') &&
				msg.length > parseInt(settings.get('Livechat_message_character_limit'))
			) {
				throw new Error('message-length-exceeds-character-limit');
			}

			const _id = this.bodyParams._id || Random.id();

			const messageToSend = {
				guest,
				message: {
					_id,
					rid,
					msg,
					token,
				},
				agent,
				roomInfo: {
					source: {
						type: isWidget(this.request.headers) ? OmnichannelSourceType.WIDGET : OmnichannelSourceType.API,
					},
				},

View on GitHub (pinned to f9d3ec372b)

Solutions

  1. Truncate or split the message client-side so it fits `Livechat_message_character_limit`.
  2. Read the limit from the widget config (limitTextPath / limitTextLength) and enforce it before sending.
  3. As admin, raise `Livechat_message_character_limit` or disable `Livechat_enable_message_character_limit`.

Example fix

// before
POST /livechat/message { token, rid, msg: longText }

// after
const limit = settings.get('Livechat_message_character_limit');
const safe = msg.length > limit ? msg.slice(0, limit) : msg;
POST /livechat/message { token, rid, msg: safe }
Defensive patterns

Strategy: validation

Validate before calling

const enabled = settings.get('Livechat_enable_message_character_limit');
const limit = parseInt(`${settings.get('Livechat_message_character_limit')}`, 10);
if (enabled && msg.length > limit) {
  msg = msg.slice(0, limit); // or split into multiple messages
}
// safe to POST /livechat/message

Type guard

const fitsLimit = (msg: string, enabled: boolean, limit: number) =>
  !enabled || msg.length <= limit;

Try / catch

try { await sendMessage({ token, rid, msg }); }
catch (e) { if (e instanceof Error && e.message === 'message-length-exceeds-character-limit') { /* truncate and retry */ } else throw e; }

Prevention

When it happens

Trigger: Posting a `msg` whose character count is greater than the configured `Livechat_message_character_limit` while the limit setting is enabled.

Common situations: User pastes long text; client does not enforce the limit; admin lowered the limit; the widget's limitTextLength config was not respected.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@f9d3ec372b (2026-08-12). Data as JSON: /api/errors/f0d75a9c14f9bb95. Report an issue: GitHub.