Skip to content

Commit

Permalink
Bot API 6.7 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ayrat555 committed Apr 22, 2023
1 parent 5af0ec2 commit 357e83a
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 25 deletions.
33 changes: 31 additions & 2 deletions src/api_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::objects::{
PassportElementErrorSelfie, PassportElementErrorTranslationFile,
PassportElementErrorTranslationFiles, PassportElementErrorUnspecified, PollType,
ReplyKeyboardMarkup, ReplyKeyboardRemove, ShippingOption, StickerFormat, StickerType,
WebAppInfo,
};
use crate::{AllowedUpdate, ParseMode};
use serde::Deserialize;
Expand Down Expand Up @@ -1618,6 +1619,24 @@ pub struct SetMyCommandsParams {
pub language_code: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SetMyNameParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub name: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub language_code: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct GetMyNameParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub language_code: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SetMyDescriptionParams {
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -1993,11 +2012,21 @@ pub struct AnswerInlineQueryParams {

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub switch_pm_text: Option<String>,
pub button: Option<InlineQueryResultsButton>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct InlineQueryResultsButton {
#[builder(setter(into))]
pub text: String,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub web_app: Option<WebAppInfo>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub switch_pm_parameter: Option<String>,
pub start_parameter: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
Expand Down
39 changes: 28 additions & 11 deletions src/api_traits/async_telegram_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use crate::api_params::GetGameHighScoresParams;
use crate::api_params::GetMyCommandsParams;
use crate::api_params::GetMyDefaultAdministratorRightsParams;
use crate::api_params::GetMyDescriptionParams;
use crate::api_params::GetMyNameParams;
use crate::api_params::GetMyShortDescriptionParams;
use crate::api_params::GetStickerSetParams;
use crate::api_params::GetUpdatesParams;
Expand Down Expand Up @@ -91,6 +92,7 @@ use crate::api_params::SetGameScoreParams;
use crate::api_params::SetMyCommandsParams;
use crate::api_params::SetMyDefaultAdministratorRightsParams;
use crate::api_params::SetMyDescriptionParams;
use crate::api_params::SetMyNameParams;
use crate::api_params::SetMyShortDescriptionParams;
use crate::api_params::SetStickerEmojiListParams;
use crate::api_params::SetStickerKeywordsParams;
Expand All @@ -109,6 +111,7 @@ use crate::api_params::UnpinChatMessageParams;
use crate::api_params::UploadStickerFileParams;
use crate::objects::BotCommand;
use crate::objects::BotDescription;
use crate::objects::BotName;
use crate::objects::BotShortDescription;
use crate::objects::Chat;
use crate::objects::ChatAdministratorRights;
Expand Down Expand Up @@ -778,18 +781,39 @@ pub trait AsyncTelegramApi {
self.request("answerCallbackQuery", Some(params)).await
}

async fn get_my_commands(
&self,
params: &GetMyCommandsParams,
) -> Result<MethodResponse<Vec<BotCommand>>, Self::Error> {
self.request("getMyCommands", Some(params)).await
}

async fn set_my_commands(
&self,
params: &SetMyCommandsParams,
) -> Result<MethodResponse<bool>, Self::Error> {
self.request("setMyCommands", Some(params)).await
}

async fn get_my_commands(
async fn delete_my_commands(
&self,
params: &GetMyCommandsParams,
) -> Result<MethodResponse<Vec<BotCommand>>, Self::Error> {
self.request("getMyCommands", Some(params)).await
params: &DeleteMyCommandsParams,
) -> Result<MethodResponse<bool>, Self::Error> {
self.request("deleteMyCommands", Some(params)).await
}

async fn set_my_name(
&self,
params: &SetMyNameParams,
) -> Result<MethodResponse<bool>, Self::Error> {
self.request("setMyName", Some(params)).await
}

async fn get_my_name(
&self,
params: &GetMyNameParams,
) -> Result<MethodResponse<BotName>, Self::Error> {
self.request("getMyName", Some(params)).await
}

async fn set_my_description(
Expand Down Expand Up @@ -820,13 +844,6 @@ pub trait AsyncTelegramApi {
self.request("getMyShortDescription", Some(params)).await
}

async fn delete_my_commands(
&self,
params: &DeleteMyCommandsParams,
) -> Result<MethodResponse<bool>, Self::Error> {
self.request("deleteMyCommands", Some(params)).await
}

async fn answer_inline_query(
&self,
params: &AnswerInlineQueryParams,
Expand Down
36 changes: 25 additions & 11 deletions src/api_traits/telegram_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use crate::api_params::GetGameHighScoresParams;
use crate::api_params::GetMyCommandsParams;
use crate::api_params::GetMyDefaultAdministratorRightsParams;
use crate::api_params::GetMyDescriptionParams;
use crate::api_params::GetMyNameParams;
use crate::api_params::GetMyShortDescriptionParams;
use crate::api_params::GetStickerSetParams;
use crate::api_params::GetUpdatesParams;
Expand Down Expand Up @@ -90,6 +91,7 @@ use crate::api_params::SetGameScoreParams;
use crate::api_params::SetMyCommandsParams;
use crate::api_params::SetMyDefaultAdministratorRightsParams;
use crate::api_params::SetMyDescriptionParams;
use crate::api_params::SetMyNameParams;
use crate::api_params::SetMyShortDescriptionParams;
use crate::api_params::SetStickerEmojiListParams;
use crate::api_params::SetStickerKeywordsParams;
Expand All @@ -108,6 +110,7 @@ use crate::api_params::UnpinChatMessageParams;
use crate::api_params::UploadStickerFileParams;
use crate::objects::BotCommand;
use crate::objects::BotDescription;
use crate::objects::BotName;
use crate::objects::BotShortDescription;
use crate::objects::Chat;
use crate::objects::ChatAdministratorRights;
Expand Down Expand Up @@ -733,18 +736,36 @@ pub trait TelegramApi {
self.request("answerCallbackQuery", Some(params))
}

fn get_my_commands(
&self,
params: &GetMyCommandsParams,
) -> Result<MethodResponse<Vec<BotCommand>>, Self::Error> {
self.request("getMyCommands", Some(params))
}

fn set_my_commands(
&self,
params: &SetMyCommandsParams,
) -> Result<MethodResponse<bool>, Self::Error> {
self.request("setMyCommands", Some(params))
}

fn get_my_commands(
fn delete_my_commands(
&self,
params: &GetMyCommandsParams,
) -> Result<MethodResponse<Vec<BotCommand>>, Self::Error> {
self.request("getMyCommands", Some(params))
params: &DeleteMyCommandsParams,
) -> Result<MethodResponse<bool>, Self::Error> {
self.request("deleteMyCommands", Some(params))
}

fn set_my_name(&self, params: &SetMyNameParams) -> Result<MethodResponse<bool>, Self::Error> {
self.request("setMyName", Some(params))
}

fn get_my_name(
&self,
params: &GetMyNameParams,
) -> Result<MethodResponse<BotName>, Self::Error> {
self.request("getMyName", Some(params))
}

fn set_my_description(
Expand Down Expand Up @@ -775,13 +796,6 @@ pub trait TelegramApi {
self.request("getMyShortDescription", Some(params))
}

fn delete_my_commands(
&self,
params: &DeleteMyCommandsParams,
) -> Result<MethodResponse<bool>, Self::Error> {
self.request("deleteMyCommands", Some(params))
}

fn answer_inline_query(
&self,
params: &AnswerInlineQueryParams,
Expand Down
43 changes: 42 additions & 1 deletion src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ pub struct BotDescription {
pub description: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct BotName {
#[builder(setter(into))]
pub name: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct BotShortDescription {
#[builder(setter(into))]
Expand Down Expand Up @@ -1243,7 +1249,11 @@ pub struct ChatShared {
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct WriteAccessAllowed {}
pub struct WriteAccessAllowed {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub web_app_name: Option<String>,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct VideoChatEnded {
Expand Down Expand Up @@ -1431,6 +1441,10 @@ pub struct InlineKeyboardButton {
#[builder(setter(into, strip_option), default)]
pub switch_inline_query_current_chat: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub switch_inline_query_chosen_chat: Option<SwitchInlineQueryChosenChat>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub callback_game: Option<CallbackGame>,
Expand Down Expand Up @@ -1458,6 +1472,29 @@ pub struct LoginUrl {
pub request_write_access: Option<bool>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SwitchInlineQueryChosenChat {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub query: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub allow_user_chats: Option<bool>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub allow_bot_chats: Option<bool>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub allow_group_chats: Option<bool>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub allow_channel_chats: Option<bool>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct CallbackQuery {
#[builder(setter(into))]
Expand Down Expand Up @@ -1558,6 +1595,10 @@ pub struct ChatMemberUpdated {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub invite_link: Option<ChatInviteLink>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub via_chat_folder_invite_link: Option<bool>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
Expand Down

0 comments on commit 357e83a

Please sign in to comment.