Skip to content

Improve inline keyboard response #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,4 @@ impl Error {
.await?;
Ok(())
}

pub async fn report_to_user(
&self,
bot: &Bot,
chat_id: ChatId,
username: &str,
) -> Result<(), teloxide::RequestError> {
log::warn!("report error to chat {}: {:?}", chat_id, self);
bot.send_message(chat_id, format!("@{username} {self}"))
.await?;
Ok(())
}
}
33 changes: 12 additions & 21 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use repo::tasks::Task;
use serde::Deserialize;
use serde::Serialize;
use teloxide::dispatching::dialogue::GetChatId;
use teloxide::payloads;
use teloxide::prelude::*;
use teloxide::types::InlineKeyboardButton;
use teloxide::types::InlineKeyboardButtonKind;
Expand Down Expand Up @@ -139,27 +140,17 @@ async fn answer(bot: Bot, msg: Message, bc: BCommand) -> ResponseResult<()> {
}

async fn handle_callback_query(bot: Bot, query: CallbackQuery) -> ResponseResult<()> {
match handle_callback_query_command_result(&bot, &query).await {
Ok(msg) => match get_chat_id_and_username_from_query(&query) {
Ok((chat_id, username)) => {
bot.send_message(chat_id, format!("@{username} {msg}"))
.await?;
Ok(())
}
Err(e) => {
log::error!("callback query error: {e}");
Ok(())
}
},
Err(CommandError::Normal(e)) => match get_chat_id_and_username_from_query(&query) {
Ok((chat_id, username)) => e.report_to_user(&bot, chat_id, &username).await,
Err(_e) => {
log::error!("callback query error: {e}");
Ok(())
}
},
Err(CommandError::Teloxide(e)) => Err(e),
}
let result = handle_callback_query_command_result(&bot, &query).await;
let (message, alert) = match result {
Ok(msg) => (msg, false),
Err(CommandError::Normal(e)) => (format!("{e}"), true),
Err(CommandError::Teloxide(e)) => return Err(e),
};
let answer = payloads::AnswerCallbackQuery::new(query.id)
.text(message)
.show_alert(alert);
<Bot as Requester>::AnswerCallbackQuery::new(bot, answer).await?;
Ok(())
}

async fn handle_callback_query_command_result(
Expand Down