Added sugar to buttons.rs example

This commit is contained in:
LasterAlex 2024-09-23 02:46:09 +03:00
parent 3b618a7b5a
commit 6e484382a9
No known key found for this signature in database
2 changed files with 6 additions and 4 deletions

View file

@ -2,6 +2,7 @@ use std::error::Error;
use teloxide::{ use teloxide::{
payloads::SendMessageSetters, payloads::SendMessageSetters,
prelude::*, prelude::*,
sugar::bot::BotMessagesExt,
types::{ types::{
InlineKeyboardButton, InlineKeyboardMarkup, InlineQueryResultArticle, InputMessageContent, InlineKeyboardButton, InlineKeyboardMarkup, InlineQueryResultArticle, InputMessageContent,
InputMessageContentText, Me, InputMessageContentText, Me,
@ -107,17 +108,17 @@ async fn inline_query_handler(
/// **IMPORTANT**: do not send privacy-sensitive data this way!!! /// **IMPORTANT**: do not send privacy-sensitive data this way!!!
/// Anyone can read data stored in the callback button. /// Anyone can read data stored in the callback button.
async fn callback_handler(bot: Bot, q: CallbackQuery) -> Result<(), Box<dyn Error + Send + Sync>> { async fn callback_handler(bot: Bot, q: CallbackQuery) -> Result<(), Box<dyn Error + Send + Sync>> {
if let Some(version) = q.data { if let Some(ref version) = q.data {
let text = format!("You chose: {version}"); let text = format!("You chose: {version}");
// Tell telegram that we've seen this query, to remove 🕑 icons from the // Tell telegram that we've seen this query, to remove 🕑 icons from the
// clients. You could also use `answer_callback_query`'s optional // clients. You could also use `answer_callback_query`'s optional
// parameters to tweak what happens on the client side. // 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 // Edit text of the message to which the buttons were attached
if let Some(message) = q.message { if let Some(message) = q.regular_message() {
bot.edit_message_text(message.chat().id, message.id(), text).await?; bot.edit_text(message, text).await?;
} else if let Some(id) = q.inline_message_id { } else if let Some(id) = q.inline_message_id {
bot.edit_message_text_inline(id, text).await?; bot.edit_message_text_inline(id, text).await?;
} }

View file

@ -125,6 +125,7 @@ impl BotMessagesExt for Bot {
{ {
self.forward_message(to_chat_id, message.chat.id, message.id) self.forward_message(to_chat_id, message.chat.id, message.id)
} }
fn edit_live_location( fn edit_live_location(
&self, &self,
message: &Message, message: &Message,