From 6e484382a9f422d600807f2231d631c85288cf99 Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Mon, 23 Sep 2024 02:46:09 +0300 Subject: [PATCH] Added sugar to buttons.rs example --- crates/teloxide/examples/buttons.rs | 9 +++++---- crates/teloxide/src/sugar/bot.rs | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/teloxide/examples/buttons.rs b/crates/teloxide/examples/buttons.rs index daa538c2..9f188915 100644 --- a/crates/teloxide/examples/buttons.rs +++ b/crates/teloxide/examples/buttons.rs @@ -2,6 +2,7 @@ use std::error::Error; use teloxide::{ payloads::SendMessageSetters, prelude::*, + sugar::bot::BotMessagesExt, types::{ InlineKeyboardButton, InlineKeyboardMarkup, InlineQueryResultArticle, InputMessageContent, InputMessageContentText, Me, @@ -107,17 +108,17 @@ async fn inline_query_handler( /// **IMPORTANT**: do not send privacy-sensitive data this way!!! /// Anyone can read data stored in the callback button. async fn callback_handler(bot: Bot, q: CallbackQuery) -> Result<(), Box> { - if let Some(version) = q.data { + if let Some(ref version) = q.data { let text = format!("You chose: {version}"); // Tell telegram that we've seen this query, to remove 🕑 icons from the // clients. You could also use `answer_callback_query`'s optional // parameters to tweak what happens on the client side. - bot.answer_callback_query(q.id).await?; + bot.answer_callback_query(&q.id).await?; // Edit text of the message to which the buttons were attached - if let Some(message) = q.message { - bot.edit_message_text(message.chat().id, message.id(), text).await?; + if let Some(message) = q.regular_message() { + bot.edit_text(message, text).await?; } else if let Some(id) = q.inline_message_id { bot.edit_message_text_inline(id, text).await?; } diff --git a/crates/teloxide/src/sugar/bot.rs b/crates/teloxide/src/sugar/bot.rs index bd0242f0..801cabe6 100644 --- a/crates/teloxide/src/sugar/bot.rs +++ b/crates/teloxide/src/sugar/bot.rs @@ -125,6 +125,7 @@ impl BotMessagesExt for Bot { { self.forward_message(to_chat_id, message.chat.id, message.id) } + fn edit_live_location( &self, message: &Message,