Skip to content

Commit

Permalink
Bot API 7.0: Link Preview Customization (#130)
Browse files Browse the repository at this point in the history
* Bot API 7.0: Link Preview Customization

* Bot API 7.0: Multiple Message Actions (#131)

* Bot API 7.0: Multiple Message Actions

* Bot API 7.0: Request for multiple users (#132)

* Bot API 7.0: Request for multiple users

* Bot API 7.0: Chat Boost (#133)

* Bot API 7.0: Chat Boost

* Bot API 7.0: Giveaway (#134)

* Bot API 7.0: Giveaway

* Bot API 7.0: Other changes (#135)
  • Loading branch information
ayrat555 authored Jan 6, 2024
1 parent da14c54 commit 2ff9ac7
Show file tree
Hide file tree
Showing 4 changed files with 298 additions and 40 deletions.
84 changes: 75 additions & 9 deletions src/api_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use crate::objects::{
InlineQueryResultCachedVoice, InlineQueryResultContact, InlineQueryResultDocument,
InlineQueryResultGame, InlineQueryResultGif, InlineQueryResultLocation,
InlineQueryResultMpeg4Gif, InlineQueryResultPhoto, InlineQueryResultVenue,
InlineQueryResultVideo, InlineQueryResultVoice, InputSticker, LabeledPrice, MaskPosition,
MenuButton, MessageEntity, PassportElementErrorDataField, PassportElementErrorFile,
PassportElementErrorFiles, PassportElementErrorFrontSide, PassportElementErrorReverseSide,
PassportElementErrorSelfie, PassportElementErrorTranslationFile,
PassportElementErrorTranslationFiles, PassportElementErrorUnspecified, PollType, ReactionType,
ReplyKeyboardMarkup, ReplyKeyboardRemove, ShippingOption, StickerFormat, StickerType,
WebAppInfo,
InlineQueryResultVideo, InlineQueryResultVoice, InputSticker, LabeledPrice, LinkPreviewOptions,
MaskPosition, MenuButton, MessageEntity, PassportElementErrorDataField,
PassportElementErrorFile, PassportElementErrorFiles, PassportElementErrorFrontSide,
PassportElementErrorReverseSide, PassportElementErrorSelfie,
PassportElementErrorTranslationFile, PassportElementErrorTranslationFiles,
PassportElementErrorUnspecified, PollType, ReactionType, ReplyKeyboardMarkup,
ReplyKeyboardRemove, ShippingOption, StickerFormat, StickerType, WebAppInfo,
};
use crate::{AllowedUpdate, ParseMode};
use serde::Deserialize;
Expand Down Expand Up @@ -298,7 +298,7 @@ pub struct SendMessageParams {

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

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
Expand Down Expand Up @@ -340,6 +340,29 @@ pub struct ForwardMessageParams {
pub message_id: i32,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct ForwardMessagesParams {
#[builder(setter(into))]
pub chat_id: ChatId,

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

#[builder(setter(into))]
pub from_chat_id: ChatId,

pub message_ids: Vec<i32>,

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

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

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct CopyMessageParams {
#[builder(setter(into))]
Expand Down Expand Up @@ -383,6 +406,33 @@ pub struct CopyMessageParams {
pub reply_markup: Option<ReplyMarkup>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct CopyMessagesParams {
#[builder(setter(into))]
pub chat_id: ChatId,

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

#[builder(setter(into))]
pub from_chat_id: ChatId,

pub message_ids: Vec<i32>,

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

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

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

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SendPhotoParams {
#[builder(setter(into))]
Expand Down Expand Up @@ -1572,6 +1622,14 @@ pub struct AnswerCallbackQueryParams {
pub cache_time: Option<u32>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct GetUserChatBoostsParams {
#[builder(setter(into))]
pub chat_id: ChatId,

pub user_id: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SetMyCommandsParams {
pub commands: Vec<BotCommand>,
Expand Down Expand Up @@ -1688,7 +1746,7 @@ pub struct EditMessageTextParams {

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

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
Expand Down Expand Up @@ -1787,6 +1845,14 @@ pub struct DeleteMessageParams {
pub message_id: i32,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct DeleteMessagesParams {
#[builder(setter(into))]
pub chat_id: ChatId,

pub message_ids: Vec<i32>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SendStickerParams {
#[builder(setter(into))]
Expand Down
33 changes: 33 additions & 0 deletions src/api_traits/async_telegram_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::api_params::BanChatSenderChatParams;
use crate::api_params::CloseForumTopicParams;
use crate::api_params::CloseGeneralForumTopicParams;
use crate::api_params::CopyMessageParams;
use crate::api_params::CopyMessagesParams;
use crate::api_params::CreateChatInviteLinkParams;
use crate::api_params::CreateForumTopicParams;
use crate::api_params::CreateInvoiceLinkParams;
Expand All @@ -21,6 +22,7 @@ use crate::api_params::DeleteChatPhotoParams;
use crate::api_params::DeleteChatStickerSetParams;
use crate::api_params::DeleteForumTopicParams;
use crate::api_params::DeleteMessageParams;
use crate::api_params::DeleteMessagesParams;
use crate::api_params::DeleteMyCommandsParams;
use crate::api_params::DeleteStickerFromSetParams;
use crate::api_params::DeleteStickerSetParams;
Expand All @@ -36,6 +38,7 @@ use crate::api_params::EditMessageTextParams;
use crate::api_params::ExportChatInviteLinkParams;
use crate::api_params::FileUpload;
use crate::api_params::ForwardMessageParams;
use crate::api_params::ForwardMessagesParams;
use crate::api_params::GetChatAdministratorsParams;
use crate::api_params::GetChatMemberCountParams;
use crate::api_params::GetChatMemberParams;
Expand All @@ -51,6 +54,7 @@ use crate::api_params::GetMyNameParams;
use crate::api_params::GetMyShortDescriptionParams;
use crate::api_params::GetStickerSetParams;
use crate::api_params::GetUpdatesParams;
use crate::api_params::GetUserChatBoostsParams;
use crate::api_params::GetUserProfilePhotosParams;
use crate::api_params::HideGeneralForumTopicParams;
use crate::api_params::InputMedia;
Expand Down Expand Up @@ -131,6 +135,7 @@ use crate::objects::SentWebAppMessage;
use crate::objects::StickerSet;
use crate::objects::Update;
use crate::objects::User;
use crate::objects::UserChatBoosts;
use crate::objects::UserProfilePhotos;
use crate::objects::WebhookInfo;
use crate::Sticker;
Expand Down Expand Up @@ -193,13 +198,27 @@ pub trait AsyncTelegramApi {
self.request("forwardMessage", Some(params)).await
}

async fn forward_messages(
&self,
params: &ForwardMessagesParams,
) -> Result<MethodResponse<Vec<MessageId>>, Self::Error> {
self.request("forwardMessages", Some(params)).await
}

async fn copy_message(
&self,
params: &CopyMessageParams,
) -> Result<MethodResponse<MessageId>, Self::Error> {
self.request("copyMessage", Some(params)).await
}

async fn copy_messages(
&self,
params: &CopyMessagesParams,
) -> Result<MethodResponse<Vec<MessageId>>, Self::Error> {
self.request("copyMessages", Some(params)).await
}

async fn send_photo(
&self,
params: &SendPhotoParams,
Expand Down Expand Up @@ -798,6 +817,13 @@ pub trait AsyncTelegramApi {
self.request("answerCallbackQuery", Some(params)).await
}

async fn get_user_chat_boosts(
&self,
params: &GetUserChatBoostsParams,
) -> Result<MethodResponse<UserChatBoosts>, Self::Error> {
self.request("getUserChatBoosts", Some(params)).await
}

async fn get_my_commands(
&self,
params: &GetMyCommandsParams,
Expand Down Expand Up @@ -1031,6 +1057,13 @@ pub trait AsyncTelegramApi {
self.request("deleteMessage", Some(params)).await
}

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

async fn send_sticker(
&self,
params: &SendStickerParams,
Expand Down
33 changes: 33 additions & 0 deletions src/api_traits/telegram_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::api_params::BanChatSenderChatParams;
use crate::api_params::CloseForumTopicParams;
use crate::api_params::CloseGeneralForumTopicParams;
use crate::api_params::CopyMessageParams;
use crate::api_params::CopyMessagesParams;
use crate::api_params::CreateChatInviteLinkParams;
use crate::api_params::CreateForumTopicParams;
use crate::api_params::CreateInvoiceLinkParams;
Expand All @@ -21,6 +22,7 @@ use crate::api_params::DeleteChatPhotoParams;
use crate::api_params::DeleteChatStickerSetParams;
use crate::api_params::DeleteForumTopicParams;
use crate::api_params::DeleteMessageParams;
use crate::api_params::DeleteMessagesParams;
use crate::api_params::DeleteMyCommandsParams;
use crate::api_params::DeleteStickerFromSetParams;
use crate::api_params::DeleteStickerSetParams;
Expand All @@ -36,6 +38,7 @@ use crate::api_params::EditMessageTextParams;
use crate::api_params::ExportChatInviteLinkParams;
use crate::api_params::FileUpload;
use crate::api_params::ForwardMessageParams;
use crate::api_params::ForwardMessagesParams;
use crate::api_params::GetChatAdministratorsParams;
use crate::api_params::GetChatMemberCountParams;
use crate::api_params::GetChatMemberParams;
Expand All @@ -50,6 +53,7 @@ use crate::api_params::GetMyNameParams;
use crate::api_params::GetMyShortDescriptionParams;
use crate::api_params::GetStickerSetParams;
use crate::api_params::GetUpdatesParams;
use crate::api_params::GetUserChatBoostsParams;
use crate::api_params::GetUserProfilePhotosParams;
use crate::api_params::HideGeneralForumTopicParams;
use crate::api_params::InputMedia;
Expand Down Expand Up @@ -130,6 +134,7 @@ use crate::objects::SentWebAppMessage;
use crate::objects::StickerSet;
use crate::objects::Update;
use crate::objects::User;
use crate::objects::UserChatBoosts;
use crate::objects::UserProfilePhotos;
use crate::objects::WebhookInfo;
use crate::GetCustomEmojiStickersParams;
Expand Down Expand Up @@ -188,13 +193,27 @@ pub trait TelegramApi {
self.request("forwardMessage", Some(params))
}

fn forward_messages(
&self,
params: &ForwardMessagesParams,
) -> Result<MethodResponse<Vec<MessageId>>, Self::Error> {
self.request("forwardMessages", Some(params))
}

fn copy_message(
&self,
params: &CopyMessageParams,
) -> Result<MethodResponse<MessageId>, Self::Error> {
self.request("copyMessage", Some(params))
}

fn copy_messages(
&self,
params: &CopyMessagesParams,
) -> Result<MethodResponse<Vec<MessageId>>, Self::Error> {
self.request("copyMessages", Some(params))
}

fn send_photo(&self, params: &SendPhotoParams) -> Result<MethodResponse<Message>, Self::Error> {
let method_name = "sendPhoto";
let mut files: Vec<(&str, PathBuf)> = vec![];
Expand Down Expand Up @@ -753,6 +772,13 @@ pub trait TelegramApi {
self.request("answerCallbackQuery", Some(params))
}

fn get_user_chat_boosts(
&self,
params: &GetUserChatBoostsParams,
) -> Result<MethodResponse<UserChatBoosts>, Self::Error> {
self.request("getUserChatBoosts", Some(params))
}

fn get_my_commands(
&self,
params: &GetMyCommandsParams,
Expand Down Expand Up @@ -979,6 +1005,13 @@ pub trait TelegramApi {
self.request("deleteMessage", Some(params))
}

fn delete_messages(
&self,
params: &DeleteMessagesParams,
) -> Result<MethodResponse<bool>, Self::Error> {
self.request("deleteMessages", Some(params))
}

fn send_sticker(
&self,
params: &SendStickerParams,
Expand Down
Loading

0 comments on commit 2ff9ac7

Please sign in to comment.