From 075b92f231012e21ef777a42df9030c377c794fa Mon Sep 17 00:00:00 2001 From: xiaoski Date: Wed, 8 Apr 2026 08:42:56 +0800 Subject: [PATCH] fix: truncate long text content before sending to Feishu Feishu API rejects messages with content exceeding ~64KB with error 230001 "invalid message content". Added truncation at 60,000 characters to prevent this, with a notice appended to truncated content. --- src/channels/feishu.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/channels/feishu.rs b/src/channels/feishu.rs index 2d6daa1..99119dc 100644 --- a/src/channels/feishu.rs +++ b/src/channels/feishu.rs @@ -489,7 +489,16 @@ impl FeishuChannel { async fn send_message_to_feishu(&self, receive_id: &str, receive_id_type: &str, content: &str) -> Result<(), ChannelError> { let token = self.get_tenant_token().await?; - let text_content = serde_json::json!({ "text": content }).to_string(); + // Feishu text messages have content limits (~64KB). + // Truncate if content is too long to avoid API error 230001. + const MAX_TEXT_LENGTH: usize = 60_000; + let truncated = if content.len() > MAX_TEXT_LENGTH { + format!("{}...\n\n[Content truncated due to length limit]", &content[..MAX_TEXT_LENGTH]) + } else { + content.to_string() + }; + + let text_content = serde_json::json!({ "text": truncated }).to_string(); let resp = self.http_client .post(format!("{}/im/v1/messages?receive_id_type={}", FEISHU_API_BASE, receive_id_type)) @@ -906,11 +915,17 @@ impl Channel for FeishuChannel { // Build content with media references let mut content_parts = Vec::new(); - // Add text content if present + // Add text content if present (truncate if too long for Feishu) if !msg.content.is_empty() { + const MAX_TEXT_LENGTH: usize = 60_000; + let truncated_text = if msg.content.len() > MAX_TEXT_LENGTH { + format!("{}...\n\n[Content truncated due to length limit]", &msg.content[..MAX_TEXT_LENGTH]) + } else { + msg.content.clone() + }; content_parts.push(serde_json::json!({ "tag": "text", - "text": msg.content + "text": truncated_text })); }