{"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":null,"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/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/server/api/v1/omnichannel/message.ts#L31-L67","documentation":"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' }.","triggerScenarios":"Posting a `msg` whose character count is greater than the configured `Livechat_message_character_limit` while the limit setting is enabled.","commonSituations":"User pastes long text; client does not enforce the limit; admin lowered the limit; the widget's limitTextLength config was not respected.","solutions":["Truncate or split the message client-side so it fits `Livechat_message_character_limit`.","Read the limit from the widget config (limitTextPath / limitTextLength) and enforce it before sending.","As admin, raise `Livechat_message_character_limit` or disable `Livechat_enable_message_character_limit`."],"exampleFix":"// before\nPOST /livechat/message { token, rid, msg: longText }\n\n// after\nconst limit = settings.get('Livechat_message_character_limit');\nconst safe = msg.length > limit ? msg.slice(0, limit) : msg;\nPOST /livechat/message { token, rid, msg: safe }","handlingStrategy":"validation","validationCode":"const enabled = settings.get('Livechat_enable_message_character_limit');\nconst limit = parseInt(`${settings.get('Livechat_message_character_limit')}`, 10);\nif (enabled && msg.length > limit) {\n  msg = msg.slice(0, limit); // or split into multiple messages\n}\n// safe to POST /livechat/message","typeGuard":"const fitsLimit = (msg: string, enabled: boolean, limit: number) =>\n  !enabled || msg.length <= limit;","tryCatchPattern":"try { await sendMessage({ token, rid, msg }); }\ncatch (e) { if (e instanceof Error && e.message === 'message-length-exceeds-character-limit') { /* truncate and retry */ } else throw e; }","preventionTips":["Read the limit from the widget config and cap input client-side.","Show a character counter when the limit is enabled.","Keep clients in sync with admin limit changes."],"tags":["livechat","omnichannel","validation","messaging","configuration"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}