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.
This commit is contained in:
parent
02a7fa68c6
commit
075b92f231
@ -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
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user