{"record":{"id":"f0d75a9c14f9bb95","repo":"RocketChat/Rocket.Chat","slug":"message-length-exceeds-character-limit","errorCode":null,"errorMessage":"message-length-exceeds-character-limit","messagePattern":"message-length-exceeds-character-limit","errorType":"exception","errorClass":"Error","httpStatus":400,"severity":"error","filePath":"apps/meteor/server/api/v1/omnichannel/message.ts","lineNumber":49,"sourceCode":"\t\t\tconst guest = await findGuest(token);\n\t\t\tif (!guest) {\n\t\t\t\tthrow new Error('invalid-token');\n\t\t\t}\n\n\t\t\tconst room = await findRoom(token, rid);\n\t\t\tif (!room) {\n\t\t\t\tthrow new Error('invalid-room');\n\t\t\t}\n\n\t\t\tif (!room.open) {\n\t\t\t\tthrow new Error('room-closed');\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tsettings.get('Livechat_enable_message_character_limit') &&\n\t\t\t\tmsg.length > parseInt(settings.get('Livechat_message_character_limit'))\n\t\t\t) {\n\t\t\t\tthrow new Error('message-length-exceeds-character-limit');\n\t\t\t}\n\n\t\t\tconst _id = this.bodyParams._id || Random.id();\n\n\t\t\tconst messageToSend = {\n\t\t\t\tguest,\n\t\t\t\tmessage: {\n\t\t\t\t\t_id,\n\t\t\t\t\trid,\n\t\t\t\t\tmsg,\n\t\t\t\t\ttoken,\n\t\t\t\t},\n\t\t\t\tagent,\n\t\t\t\troomInfo: {\n\t\t\t\t\tsource: {\n\t\t\t\t\t\ttype: isWidget(this.request.headers) ? OmnichannelSourceType.WIDGET : OmnichannelSourceType.API,\n\t\t\t\t\t},\n\t\t\t\t},","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/api/v1/omnichannel/message.ts#L31-L67","documentation":"POST /api/v1/livechat/message enforces the server setting pair Livechat_enable_message_character_limit / Livechat_message_character_limit: when the limit is enabled and msg.length exceeds parseInt(limit), the message is rejected with 'message-length-exceeds-character-limit'. The widget config exposes this as `limitTextLength` (falling back to Message_MaxAllowedSize) so clients can pre-validate.","triggerScenarios":"Visitor pastes a long text with the character limit enabled; admin lowers the limit after widgets already loaded; a custom integration sends oversized payloads without checking the configured limit.","commonSituations":"Pasted logs/stack traces in chat; per-workpace compliance limits set to a small value; integrations assuming the default Message_MaxAllowedSize instead of the livechat-specific limit.","solutions":["Enforce the limit client-side using limitTextLength from the livechat configuration the widget already receives, and disable the send button beyond it.","Split long content into multiple messages, each under the limit.","If the business requires longer messages, an admin can raise or disable Livechat_message_character_limit (Omnichannel settings)."],"exampleFix":"// before\nawait post('/api/v1/livechat/message', { token, rid, msg }); // long paste -> rejected\n\n// after\nconst { limitTextLength } = livechatConfig; // from livechat settings/config\nif (limitTextLength && msg.length > limitTextLength) {\n  msg = `${msg.slice(0, limitTextLength - 1)}\\u2026`; // or split into chunks\n}\nawait post('/api/v1/livechat/message', { token, rid, msg });","handlingStrategy":"validation","validationCode":"// Enforce the server-configured limit client-side before sending\nconst { limitTextLength } = livechatConfig; // from the livechat settings/config payload\nfunction fitsLimit(msg: string): boolean {\n  return !limitTextLength || msg.length <= limitTextLength;\n}\nfunction chunk(msg: string): string[] {\n  if (fitsLimit(msg)) return [msg];\n  const size = limitTextLength as number;\n  return msg.match(new RegExp(`.{1,${size}}`, 'g')) ?? [];\n}\nfor (const part of chunk(msg)) await post('/api/v1/livechat/message', { token, rid, msg: part });","typeGuard":"function isWithinLimit(msg: string, limit?: number): msg is string {\n  return !limit || msg.length <= limit;\n}","tryCatchPattern":"try { await postMessage(token, rid, msg); } catch (e) { if (e.message === 'message-length-exceeds-character-limit') { for (const part of chunk(msg, limitTextLength)) await postMessage(token, rid, part); } else throw e; }","preventionTips":["Read limitTextLength from the widget config on connect and re-read it when settings change.","Show a live character counter and disable send beyond the limit.","Prefer splitting long input over silently truncating user content."],"tags":["omnichannel","livechat","message","validation","settings","rest-api"],"backgroundTag":"payload-too-large","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}