fix(telegram): treat "message is not modified" as success in finalize_draft
Telegram returns 400 with "message is not modified" when editMessageText is called with content identical to the current message. This happens when streaming deltas have already updated the draft to the final text. Previously this triggered a fallback to sendMessage, producing a duplicate message. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
f426edfc17
commit
0027b4d746
1 changed files with 19 additions and 0 deletions
|
|
@ -1607,6 +1607,16 @@ impl Channel for TelegramChannel {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
// Check if edit failed because content is identical (Telegram returns 400
|
||||
// with "message is not modified" when the draft already has the final text).
|
||||
let status = resp.status();
|
||||
let resp_body = resp.text().await.unwrap_or_default();
|
||||
if status == reqwest::StatusCode::BAD_REQUEST
|
||||
&& resp_body.contains("message is not modified")
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Markdown failed — retry without parse_mode
|
||||
let plain_body = serde_json::json!({
|
||||
"chat_id": chat_id,
|
||||
|
|
@ -1625,6 +1635,15 @@ impl Channel for TelegramChannel {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
// Also check plain-text edit for "not modified"
|
||||
let status = resp.status();
|
||||
let resp_body = resp.text().await.unwrap_or_default();
|
||||
if status == reqwest::StatusCode::BAD_REQUEST
|
||||
&& resp_body.contains("message is not modified")
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Edit failed entirely — fall back to new message
|
||||
tracing::warn!("Telegram finalize_draft edit failed; falling back to sendMessage");
|
||||
self.send_text_chunks(text, &chat_id, thread_id.as_deref())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue