Skip to content

Commit

Permalink
feat(phoenix): use safe message char limit
Browse files Browse the repository at this point in the history
  • Loading branch information
alextes committed Sep 14, 2024
1 parent 7dd4d8c commit 40e1aca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/phoenix/alerts/telegram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion src/phoenix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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::<String>();
let escaped_err = telegram::escape_str(&shortned_err);
let formatted_message = formatdoc!(
"
Expand Down

0 comments on commit 40e1aca

Please sign in to comment.