Skip to content

Commit

Permalink
Bot API 7.0: Multiple Message Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ayrat555 committed Jan 2, 2024
1 parent 53b191b commit e30eb11
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/api_params.rs
Original file line number Diff line number Diff line change
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 @@ -1787,6 +1837,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
24 changes: 24 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 Down Expand Up @@ -193,13 +196,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 @@ -1031,6 +1048,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
24 changes: 24 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 Down Expand Up @@ -188,13 +191,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 @@ -979,6 +996,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

0 comments on commit e30eb11

Please sign in to comment.