-
Notifications
You must be signed in to change notification settings - Fork 124
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
support callback button #279
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -388,6 +388,50 @@ impl Message { | |
self.raw.reply_markup.clone() | ||
} | ||
|
||
/// Collect all inline callback buttons. Those buttons often appeare in bot chat. | ||
/// Buttons could be clicked by [`click_callback_button`] | ||
pub fn callback_buttons(&self) -> Option<Vec<tl::types::KeyboardButtonCallback>> { | ||
let reply_markup = &self.raw.reply_markup?; | ||
|
||
let mut rtn = Vec::new(); | ||
if let tl::enums::ReplyMarkup::ReplyInlineMarkup(markup) = reply_markup { | ||
for row in markup.rows.iter() { | ||
let tl::enums::KeyboardButtonRow::Row(row) = row; | ||
for b in row.buttons.iter() { | ||
match b { | ||
tl::enums::KeyboardButton::Callback(callback_b) => { | ||
rtn.push(callback_b.clone()); | ||
} | ||
_ => (), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This means the position in the returned array will not match the one users see in the application. Which would be really confusing. |
||
} | ||
} | ||
} | ||
} | ||
|
||
Some(rtn) | ||
} | ||
|
||
pub async fn click_callback_button( | ||
&self, | ||
button: &tl::types::KeyboardButtonCallback, | ||
) -> Result<()> { | ||
if button.requires_password { | ||
unimplemented!() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't know how to deal with password. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it's a bit of a mess. I'd take the implementation from Telethon. |
||
} else { | ||
let rtn = self | ||
.client | ||
.invoke(&tl::functions::GetBotCallbackAnswer { | ||
game: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't know how to deal with game flag. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likewise. |
||
peer: self.chat().pack().to_input_peer(), | ||
msg_id: self.id(), | ||
data: Some(button.data.clone()), | ||
password: None, | ||
}) | ||
.await?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
/// The formatting entities used to format this message, such as bold, italic, with their | ||
/// offsets and lengths. | ||
pub fn fmt_entities(&self) -> Option<&Vec<tl::enums::MessageEntity>> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only handle KeyboardButtonCallback, other KeyboardButton types cannot handle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking more to return a custom type of buttons, so that
.click()
could be called directly on the one you need.By the way, might be good to call this "inline buttons". The term in your code is used by the API, but I believe the other term is more common in the applications? Not sure what the bot API calls it.