Skip to content
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

Add some missing fields and variants #194

Closed
wants to merge 7 commits into from
Closed
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
16 changes: 8 additions & 8 deletions lib/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ impl Api {
tracing::trace!("response deserialized");
Ok(response)
}
.map(|result| {
if let Err(ref error) = result {
tracing::error!(error = %error);
}
result
})
.instrument(span)
.await
.map(|result| {
if let Err(ref error) = result {
tracing::error!(error = %error);
}
result
})
.instrument(span)
.await
}
}
43 changes: 42 additions & 1 deletion raw/src/requests/answer_inline_query.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
use std::ops::Not;

use crate::requests::*;
use crate::types::*;

#[derive(Serialize, Debug)]
pub struct AnswerInlineQuery {
inline_query_id: InlineQueryId,
results: Vec<InlineQueryResult>,
// TODO: Rest of the fields
#[serde(skip_serializing_if = "Option::is_none")]
cache_time: Option<Integer>,
#[serde(skip_serializing_if = "Not::not")]
is_personal: bool,
#[serde(skip_serializing_if = "Option::is_none")]
next_offset: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
switch_pm_text: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
switch_pm_parameter: Option<String>,
}

impl Request for AnswerInlineQuery {
Expand Down Expand Up @@ -38,10 +49,40 @@ impl AnswerInlineQuery {
AnswerInlineQuery {
inline_query_id,
results,
cache_time: None,
is_personal: false,
next_offset: None,
switch_pm_text: None,
switch_pm_parameter: None,
}
}

pub fn add_inline_result<T: Into<InlineQueryResult>>(&mut self, result: T) {
self.results.push(result.into());
}

pub fn cache_time(&mut self, cache_time: Integer) -> &mut Self {
self.cache_time = Some(cache_time);
self
}

pub fn is_personal(&mut self) -> &mut Self {
self.is_personal = true;
self
}

pub fn next_offset(&mut self, next_offset: String) -> &mut Self {
self.next_offset = Some(next_offset);
self
}

pub fn switch_pm_text(&mut self, switch_pm_text: String) -> &mut Self {
self.switch_pm_text = Some(switch_pm_text);
self
}

pub fn switch_pm_parameter(&mut self, switch_pm_parameter: String) -> &mut Self {
self.switch_pm_parameter = Some(switch_pm_parameter);
self
}
}
20 changes: 20 additions & 0 deletions raw/src/types/chosen_inline_result.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::types::*;

/// This object represents the result of an inline query that was chosen by a
/// user and sent to their chat partner. It is only sent if inline feedback is
/// enabled for the bot.
#[derive(Debug, Clone, PartialEq, PartialOrd, Deserialize)]
pub struct ChosenInlineResult {
/// Unique identifier for the result that was chosen
pub result_id: String,
/// The user that chose the result
pub from: User,
/// Sender location, only for bots that require user location
pub location: Option<Location>,
/// Identifier of the sent inline message. Available only if there is an
/// inline keyboard attached to the message. Will be also received in
/// callback queries and can be used to edit the message
pub inline_message_id: Option<String>,
/// The query that was used to obtain the result
pub query: String,
}
46 changes: 23 additions & 23 deletions raw/src/types/inline_query_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub struct InlineQueryResultArticle {
pub input_message_content: InputMessageContent,
/// Inline keyboard attached to the message
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
pub reply_markup: Option<InlineKeyboardMarkup>,
/// URL of the result
#[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<String>,
Expand Down Expand Up @@ -183,7 +183,7 @@ pub struct InlineQueryResultPhoto {
pub parse_mode: Option<ParseMode>,
/// Inline keyboard attached to the message
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
pub reply_markup: Option<InlineKeyboardMarkup>,
/// Content of the message to be sent
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
Expand Down Expand Up @@ -217,7 +217,7 @@ pub struct InlineQueryResultGif {
pub parse_mode: Option<ParseMode>,
/// Inline keyboard attached to the message
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
pub reply_markup: Option<InlineKeyboardMarkup>,
/// Content of the message to be sent
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
Expand Down Expand Up @@ -250,7 +250,7 @@ pub struct InlineQueryResultMpeg4Gif {
pub parse_mode: Option<ParseMode>,
/// Inline keyboard attached to the message
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
pub reply_markup: Option<InlineKeyboardMarkup>,
/// Content of the message to be sent
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
Expand Down Expand Up @@ -288,7 +288,7 @@ pub struct InlineQueryResultVideo {
pub description: Option<String>,
/// Inline keyboard attached to the message
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
pub reply_markup: Option<InlineKeyboardMarkup>,
/// Content of the message to be sent
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
Expand All @@ -315,7 +315,7 @@ pub struct InlineQueryResultAudio {
pub audio_duration: Option<Integer>,
/// Inline keyboard attached to the message
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
pub reply_markup: Option<InlineKeyboardMarkup>,
/// Content of the message to be sent
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
Expand All @@ -339,7 +339,7 @@ pub struct InlineQueryResultVoice {
pub audio_duration: Option<Integer>,
/// Inline keyboard attached to the message
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
pub reply_markup: Option<InlineKeyboardMarkup>,
/// Content of the message to be sent
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
Expand All @@ -366,7 +366,7 @@ pub struct InlineQueryResultDocument {
pub description: Option<String>,
/// Inline keyboard attached to the message
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
pub reply_markup: Option<InlineKeyboardMarkup>,
/// Content of the message to be sent
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
Expand Down Expand Up @@ -396,7 +396,7 @@ pub struct InlineQueryResultLocation {
pub live_period: Option<Integer>,
/// Inline keyboard attached to the message
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
pub reply_markup: Option<InlineKeyboardMarkup>,
/// Content of the message to be sent
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
Expand Down Expand Up @@ -432,7 +432,7 @@ pub struct InlineQueryResultVenue {
pub foursquare_type: Option<String>,
/// Inline keyboard attached to the message
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
pub reply_markup: Option<InlineKeyboardMarkup>,
/// Content of the message to be sent
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
Expand Down Expand Up @@ -461,7 +461,7 @@ pub struct InlineQueryResultContact {
pub vcard: String,
/// Inline keyboard attached to the message
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
pub reply_markup: Option<InlineKeyboardMarkup>,
/// Content of the message to be sent
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
Expand All @@ -484,7 +484,7 @@ pub struct InlineQueryResultGame {
pub game_short_name: String,
/// Inline keyboard attached to the message
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
pub reply_markup: Option<InlineKeyboardMarkup>,
}

#[derive(Serialize, Debug)]
Expand All @@ -507,7 +507,7 @@ pub struct InlineQueryResultCachedPhoto {
pub parse_mode: Option<ParseMode>,
/// Inline keyboard attached to the message
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
pub reply_markup: Option<InlineKeyboardMarkup>,
/// Content of the message to be sent
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
Expand All @@ -530,7 +530,7 @@ pub struct InlineQueryResultCachedGif {
pub parse_mode: Option<ParseMode>,
/// Inline keyboard attached to the message
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
pub reply_markup: Option<InlineKeyboardMarkup>,
/// Content of the message to be sent
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
Expand All @@ -553,7 +553,7 @@ pub struct InlineQueryResultCachedMpeg4Gif {
pub parse_mode: Option<ParseMode>,
/// Inline keyboard attached to the message
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
pub reply_markup: Option<InlineKeyboardMarkup>,
/// Content of the message to be sent
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
Expand All @@ -567,7 +567,7 @@ pub struct InlineQueryResultCachedSticker {
pub sticker_file_id: String,
/// Inline keyboard attached to the message
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
pub reply_markup: Option<InlineKeyboardMarkup>,
/// Content of the message to be sent
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
Expand All @@ -592,7 +592,7 @@ pub struct InlineQueryResultCachedDocument {
pub parse_mode: Option<ParseMode>,
/// Inline keyboard attached to the message
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
pub reply_markup: Option<InlineKeyboardMarkup>,
/// Content of the message to be sent
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
Expand All @@ -617,7 +617,7 @@ pub struct InlineQueryResultCachedVideo {
pub parse_mode: Option<ParseMode>,
/// Inline keyboard attached to the message
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
pub reply_markup: Option<InlineKeyboardMarkup>,
/// Content of the message to be sent
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
Expand All @@ -639,7 +639,7 @@ pub struct InlineQueryResultCachedVoice {
pub parse_mode: Option<ParseMode>,
/// Inline keyboard attached to the message
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
pub reply_markup: Option<InlineKeyboardMarkup>,
/// Content of the message to be sent
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
Expand All @@ -659,7 +659,7 @@ pub struct InlineQueryResultCachedAudio {
pub parse_mode: Option<ParseMode>,
/// Inline keyboard attached to the message
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
pub reply_markup: Option<InlineKeyboardMarkup>,
/// Content of the message to be sent
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
Expand All @@ -685,7 +685,7 @@ impl InlineQueryResultArticle {
}
}

pub fn reply_markup<T: Into<ReplyMarkup>>(&mut self, reply_markup: T) -> &mut Self {
pub fn reply_markup<T: Into<InlineKeyboardMarkup>>(&mut self, reply_markup: T) -> &mut Self {
self.reply_markup = Some(reply_markup.into());
self
}
Expand Down Expand Up @@ -874,11 +874,11 @@ pub struct InputVenueMessageContent {
pub address: String,
/// Foursquare identifier of the venue, if known
#[serde(skip_serializing_if = "Option::is_none")]
pub foursqure_id: Option<String>,
pub foursquare_id: Option<String>,
/// Foursquare type of the venue, if known. (For example, “arts_entertainment/default”,
/// “arts_entertainment/aquarium” or “food/icecream”.)
#[serde(skip_serializing_if = "Option::is_none")]
pub foursqure_type: Option<String>,
pub foursquare_type: Option<String>,
}

#[derive(Serialize, Debug)]
Expand Down
5 changes: 4 additions & 1 deletion raw/src/types/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,8 +875,10 @@ impl File {
/// See [documentation](https://core.telegram.org/bots/api#formatting-options) for details.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Serialize)]
pub enum ParseMode {
/// Use markdown formatting.
/// Use legacy markdown formatting.
Markdown,
/// Use MarkdownV2 formatting.
MarkdownV2,
/// Use HTML formatting.
#[serde(rename = "HTML")]
Html,
Expand All @@ -886,6 +888,7 @@ impl ::std::fmt::Display for ParseMode {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
match *self {
ParseMode::Markdown => write!(f, "Markdown"),
ParseMode::MarkdownV2 => write!(f, "MarkdownV2"),
ParseMode::Html => write!(f, "HTML"),
}
}
Expand Down
2 changes: 2 additions & 0 deletions raw/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod callback_query;
pub mod chat;
pub mod chat_member;
pub mod chosen_inline_result;
pub mod inline_query;
pub mod inline_query_result;
pub mod input_file;
Expand All @@ -15,6 +16,7 @@ pub mod update;
pub use self::callback_query::*;
pub use self::chat::*;
pub use self::chat_member::*;
pub use self::chosen_inline_result::*;
pub use self::inline_query::*;
pub use self::inline_query_result::*;
pub use self::input_file::*;
Expand Down
Loading