fix: send text posts as HTML

This commit is contained in:
2026-09-24 20:29:04 +08:00
parent 6a2ba6a50a
commit 5e7a87c0dd
3 changed files with 45 additions and 8 deletions
+26
View File
@@ -60,6 +60,14 @@ pub trait MediaSender: Send + Sync {
reply_markup: Option<InlineKeyboardMarkup>,
) -> BoxFuture<'_, Result<i64, RequestError>>;
/// Sends an HTML-formatted plain message.
fn send_html_message(
&self,
chat_id: ChatId,
text: String,
reply_to: Option<MessageId>,
) -> BoxFuture<'_, Result<i64, RequestError>>;
/// Answers an inline query with `results`, cached by Telegram for
/// `cache_time` seconds. An empty `results` answers *empty*, which is a
/// real answer: it stops the client spinning and lets Telegram serve a
@@ -201,6 +209,24 @@ impl MediaSender for Bot {
})
}
fn send_html_message(
&self,
chat_id: ChatId,
text: String,
reply_to: Option<MessageId>,
) -> BoxFuture<'_, Result<i64, RequestError>> {
Box::pin(async move {
crate::rate_limit::acquire_global(1.0).await;
let mut request =
<Bot as Requester>::send_message(self, chat_id, text).parse_mode(ParseMode::Html);
if let Some(reply_to) = reply_to {
request = request
.reply_parameters(ReplyParameters::new(reply_to).allow_sending_without_reply());
}
request.await.map(|message| message.id.0 as i64)
})
}
fn answer_inline_query(
&self,
id: InlineQueryId,
@@ -428,6 +428,22 @@ impl MediaSender for MockSender {
})
}
fn send_html_message(
&self,
_chat_id: ChatId,
text: String,
_reply_to: Option<MessageId>,
) -> BoxFuture<'_, Result<i64, RequestError>> {
Box::pin(async move {
self.messages.lock().push(text);
match self.next("send_html_message") {
Outcome::MessageOk => Ok(MockSender::SENT_ID),
Outcome::MessageErr => Err(self.error()),
other => panic!("unexpected outcome {other:?} for send_html_message"),
}
})
}
fn answer_inline_query(
&self,
_id: InlineQueryId,