diff --git a/src/phoenix/alerts/telegram.rs b/src/phoenix/alerts/telegram.rs index 27c6d3b..ad90598 100644 --- a/src/phoenix/alerts/telegram.rs +++ b/src/phoenix/alerts/telegram.rs @@ -48,7 +48,7 @@ pub struct TelegramSafeAlert(String); const TELEGRAM_MAX_MESSAGE_LENGTH: usize = 4096; // Leave a little room for the escape characters and unknowns. -const TELEGRAM_SAFE_MESSAGE_LENGTH: usize = TELEGRAM_MAX_MESSAGE_LENGTH - 2048; +pub const TELEGRAM_SAFE_MESSAGE_LENGTH: usize = TELEGRAM_MAX_MESSAGE_LENGTH - 2048; impl TelegramSafeAlert { pub fn new(input: &str) -> Self { diff --git a/src/phoenix/mod.rs b/src/phoenix/mod.rs index ebd410d..7ad9cfe 100644 --- a/src/phoenix/mod.rs +++ b/src/phoenix/mod.rs @@ -17,6 +17,7 @@ use std::{ sync::{Arc, Mutex}, }; +use alerts::telegram::TELEGRAM_SAFE_MESSAGE_LENGTH; use anyhow::{anyhow, Result}; use async_trait::async_trait; use axum::{http::StatusCode, routing::get, Router}; @@ -347,7 +348,11 @@ async fn handle_unexpected_error( telegram_alerts: TelegramAlerts, err: anyhow::Error, ) -> Result<()> { - let shortned_err = err.to_string().split_off(3072); + let shortned_err = err + .to_string() + .chars() + .take(TELEGRAM_SAFE_MESSAGE_LENGTH) + .collect::(); let escaped_err = telegram::escape_str(&shortned_err); let formatted_message = formatdoc!( "