From 0012fa2c3573690390cd1c54f1e6bd770e1db005 Mon Sep 17 00:00:00 2001 From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Date: Tue, 31 Mar 2026 10:39:54 +0530 Subject: [PATCH] fix: align message trimming with configured maxLength (#13947) # Pull Request Template ## Description This PR fixes 1. Messages being trimmed to the default 1024 limit in `trimContent` method, instead of channel-specific limits for drafts and AI tasks. 2. Telegram messages are allowed up to 10,000 characters in config, but the API supports only 4096, causing failures for oversized messages. Fixes https://linear.app/chatwoot/issue/CW-6694/captain-ai-rewrite-tasks-truncate-draft-to-1024-chars-trimcontent https://github.com/chatwoot/chatwoot/issues/13919 ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) ## How Has This Been Tested? ### Loom video **Before** https://www.loom.com/share/00e9d6b4d19247febf35dffa99da3805 **After** https://www.loom.com/share/c4900e9effc345c79bcd8a5aa1ee277b ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --- .../components/widgets/conversation/ReplyBox.vue | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue b/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue index dd2e7a607..ef6fa03d6 100644 --- a/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue +++ b/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue @@ -253,6 +253,9 @@ export default { if (this.isAnInstagramChannel) { return MESSAGE_MAX_LENGTH.INSTAGRAM; } + if (this.isATelegramChannel) { + return MESSAGE_MAX_LENGTH.TELEGRAM; + } if (this.isATiktokChannel) { return MESSAGE_MAX_LENGTH.TIKTOK; } @@ -545,7 +548,10 @@ export default { }, setCopilotAcceptedMessage(message, replyType = this.replyType) { const key = this.getDraftKey(this.conversationIdByRoute, replyType); - this.copilotAcceptedMessages[key] = trimContent(message || ''); + this.copilotAcceptedMessages[key] = trimContent( + message || '', + this.maxLength + ); }, clearCopilotAcceptedMessage(replyType = this.replyType) { const key = this.getDraftKey(this.conversationIdByRoute, replyType); @@ -603,7 +609,7 @@ export default { saveDraft(conversationId, replyType) { if (this.message || this.message === '') { const key = this.getDraftKey(conversationId, replyType); - const draftToSave = trimContent(this.message || ''); + const draftToSave = trimContent(this.message || '', this.maxLength); this.$store.dispatch('draftMessages/set', { key,