From 13dd93cc63dca0f8fb0edddfd9a8019c14cf17fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=8B=D1=80=D1=86=D0=B5=D0=B2=20=D0=92=D0=B0=D0=B4?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=98=D0=B3=D0=BE=D1=80=D0=B5=D0=B2=D0=B8=D1=87?= Date: Mon, 15 Jul 2024 21:47:21 +0300 Subject: [PATCH] Add multiple message actions methods of TBA 7.0 --- crates/teloxide-core/schema.ron | 123 +++++++++++++++++- crates/teloxide-core/src/adaptors/cache_me.rs | 3 + crates/teloxide-core/src/adaptors/erased.rs | 52 ++++++++ .../teloxide-core/src/adaptors/parse_mode.rs | 3 + .../src/adaptors/throttle/requester_impl.rs | 3 + crates/teloxide-core/src/adaptors/trace.rs | 3 + crates/teloxide-core/src/bot/api.rs | 45 +++++++ crates/teloxide-core/src/local_macros.rs | 29 +++++ crates/teloxide-core/src/payloads.rs | 6 + .../src/payloads/copy_messages.rs | 36 +++++ .../src/payloads/delete_messages.rs | 20 +++ .../src/payloads/forward_messages.rs | 32 +++++ crates/teloxide-core/src/payloads/setters.rs | 25 ++-- .../teloxide-core/src/requests/requester.rs | 39 ++++++ 14 files changed, 406 insertions(+), 13 deletions(-) create mode 100644 crates/teloxide-core/src/payloads/copy_messages.rs create mode 100644 crates/teloxide-core/src/payloads/delete_messages.rs create mode 100644 crates/teloxide-core/src/payloads/forward_messages.rs diff --git a/crates/teloxide-core/schema.ron b/crates/teloxide-core/schema.ron index 75a3a639..a1f2b939 100644 --- a/crates/teloxide-core/schema.ron +++ b/crates/teloxide-core/schema.ron @@ -39,7 +39,7 @@ //! [github]: https://github.com/WaffleLapkin/tg-methods-schema Schema( - api_version: ApiVersion(ver: "6.9", date: "September 22, 2023"), + api_version: ApiVersion(ver: "7.0", date: "December 29, 2023"), methods: [ Method( names: ("getUpdates", "GetUpdates", "get_updates"), @@ -338,6 +338,51 @@ Schema( ), ], ), + Method( + names: ("forwardMessages", "ForwardMessages", "forward_messages"), + return_ty: ArrayOf(RawTy("MessageId")), + doc: Doc( + md: "Use this method to forward multiple messages of any kind. If some of the specified messages can't be found or forwarded, they are skipped. Service messages and messages with protected content can't be forwarded. Album grouping is kept for forwarded messages. On success, an array of [MessageId] of the sent messages is returned.", + md_links: {"MessageId": "https://core.telegram.org/bots/api#messageid"}, + ), + tg_doc: "https://core.telegram.org/bots/api#forwardmessages", + tg_category: "Available methods", + params: [ + Param( + name: "chat_id", + ty: RawTy("Recipient"), + descr: Doc(md: "Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)"), + ), + Param( + name: "message_thread_id", + ty: Option(RawTy("ThreadId")), + descr: Doc(md: "Unique identifier for the target message thread (topic) of the forum; for forum supergroups only"), + ), + Param( + name: "from_chat_id", + ty: RawTy("Recipient"), + descr: Doc(md: "Unique identifier for the chat where the original message was sent (or channel username in the format `@channelusername`)"), + ), + Param( + name: "message_ids", + ty: ArrayOf(RawTy("MessageId")), + descr: Doc(md: "A JSON-serialized list of 1-100 identifiers of messages in the chat _from\\_chat\\_id_ to forward. The identifiers must be specified in a strictly increasing order.") + ), + Param( + name: "disable_notification", + ty: Option(bool), + descr: Doc( + md: "Sends the message [silently]. Users will receive a notification with no sound.", + md_links: {"silently": "https://telegram.org/blog/channels-2-0#silent-messages"} + ) + ), + Param( + name: "protect_content", + ty: Option(bool), + descr: Doc(md: "Protects the contents of sent messages from forwarding and saving"), + ), + ], + ), Method( names: ("copyMessage", "CopyMessage", "copy_message"), return_ty: RawTy("MessageId"), @@ -422,6 +467,60 @@ Schema( ), ], ), + Method( + names: ("copyMessages", "CopyMessages", "copy_messages"), + return_ty: ArrayOf(RawTy("MessageId")), + doc: Doc( + md: "Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz [poll] can be copied only if the value of the field _correct\\_option\\_id_ is known to the bot. The method is analogous to the method [forwardMessages], but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. On success, an array of [MessageId] of the sent messages is returned.", + md_links: { + "poll": "https://core.telegram.org/bots/api#poll", + "forwardMessages": "https://core.telegram.org/bots/api#forwardmessages", + "MessageId": "https://core.telegram.org/bots/api#messageid" + }, + ), + tg_doc: "https://core.telegram.org/bots/api#copymessages", + tg_category: "Available methods", + params: [ + Param( + name: "chat_id", + ty: RawTy("Recipient"), + descr: Doc(md: "Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)"), + ), + Param( + name: "message_thread_id", + ty: Option(RawTy("ThreadId")), + descr: Doc(md: "Unique identifier for the target message thread (topic) of the forum; for forum supergroups only"), + ), + Param( + name: "from_chat_id", + ty: RawTy("Recipient"), + descr: Doc(md: "Unique identifier for the chat where the original message was sent (or channel username in the format `@channelusername`)"), + ), + Param( + name: "message_ids", + ty: ArrayOf(RawTy("MessageId")), + descr: Doc(md: "Identifiers of 1-100 messages in the chat _from\\_chat\\_id_ to copy. The identifiers must be specified in a strictly increasing order.") + ), + Param( + name: "disable_notification", + ty: Option(bool), + descr: Doc( + md: "Sends the message [silently]. Users will receive a notification with no sound.", + md_links: {"silently": "https://telegram.org/blog/channels-2-0#silent-messages"} + ) + ), + Param( + name: "protect_content", + ty: Option(bool), + descr: Doc(md: "Protects the contents of sent messages from forwarding and saving"), + ), + Param( + name: "remove_caption", + ty: Option(bool), + descr: Doc(md: "Pass _True_ to copy the messages without their captions") + ) + ], + ), Method( names: ("sendPhoto", "SendPhoto", "send_photo"), return_ty: RawTy("Message"), @@ -3529,6 +3628,28 @@ Schema( ), ], ), + Method( + names: ("deleteMessages", "DeleteMessages", "delete_messages"), + return_ty: True, + doc: Doc(md: "Use this method to delete multiple messages simultaneously. If some of the specified messages can't be found, they are skipped. Returns _True_ on success."), + tg_doc: "https://core.telegram.org/bots/api#delete_messages", + tg_category: "Updating messages", + params: [ + Param( + name: "chat_id", + ty: RawTy("Recipient"), + descr: Doc(md: "Unique identifier for the target chat or username of the target channel (in the format `@channelusername`).") + ), + Param( + name: "message_ids", + ty: ArrayOf(RawTy("MessageId")), + descr: Doc( + md: "Identifiers of 1-100 messages to delete. See [deleteMessage] for limitations on which messages can be deleted", + md_links: {"deleteMessage": "https://core.telegram.org/bots/api#delete_message"} + ) + ), + ], + ), Method( names: ("sendSticker", "SendSticker", "send_sticker"), return_ty: RawTy("Message"), diff --git a/crates/teloxide-core/src/adaptors/cache_me.rs b/crates/teloxide-core/src/adaptors/cache_me.rs index eecac8bc..caab3f87 100644 --- a/crates/teloxide-core/src/adaptors/cache_me.rs +++ b/crates/teloxide-core/src/adaptors/cache_me.rs @@ -94,7 +94,9 @@ where delete_webhook, get_webhook_info, forward_message, + forward_messages, copy_message, + copy_messages, send_message, send_photo, send_audio, @@ -183,6 +185,7 @@ where edit_message_reply_markup_inline, stop_poll, delete_message, + delete_messages, send_sticker, get_sticker_set, get_custom_emoji_stickers, diff --git a/crates/teloxide-core/src/adaptors/erased.rs b/crates/teloxide-core/src/adaptors/erased.rs index 7b56d648..1e3ca58b 100644 --- a/crates/teloxide-core/src/adaptors/erased.rs +++ b/crates/teloxide-core/src/adaptors/erased.rs @@ -170,6 +170,9 @@ macro_rules! fwd_erased { (@convert $m:ident, $arg:ident, emoji_list: $T:ty) => { $arg.into_iter().collect() }; + (@convert $m:ident, $arg:ident, message_ids: $T:ty) => { + $arg.into_iter().collect() + }; (@convert $m:ident, $arg:ident, $arg_:ident : $T:ty) => { $arg.into() }; @@ -190,7 +193,9 @@ where delete_webhook, get_webhook_info, forward_message, + forward_messages, copy_message, + copy_messages, send_message, send_photo, send_audio, @@ -279,6 +284,7 @@ where edit_message_reply_markup_inline, stop_poll, delete_message, + delete_messages, send_sticker, get_sticker_set, get_custom_emoji_stickers, @@ -341,6 +347,13 @@ trait ErasableRequester<'a> { message_id: MessageId, ) -> ErasedRequest<'a, ForwardMessage, Self::Err>; + fn forward_messages( + &self, + chat_id: Recipient, + from_chat_id: Recipient, + message_ids: Vec, + ) -> ErasedRequest<'a, ForwardMessages, Self::Err>; + fn copy_message( &self, chat_id: Recipient, @@ -348,6 +361,13 @@ trait ErasableRequester<'a> { message_id: MessageId, ) -> ErasedRequest<'a, CopyMessage, Self::Err>; + fn copy_messages( + &self, + chat_id: Recipient, + from_chat_id: Recipient, + message_ids: Vec, + ) -> ErasedRequest<'a, CopyMessages, Self::Err>; + fn send_photo( &self, chat_id: Recipient, @@ -816,6 +836,12 @@ trait ErasableRequester<'a> { message_id: MessageId, ) -> ErasedRequest<'a, DeleteMessage, Self::Err>; + fn delete_messages( + &self, + chat_id: Recipient, + message_ids: Vec, + ) -> ErasedRequest<'a, DeleteMessages, Self::Err>; + fn send_sticker( &self, chat_id: Recipient, @@ -1019,6 +1045,15 @@ where Requester::forward_message(self, chat_id, from_chat_id, message_id).erase() } + fn forward_messages( + &self, + chat_id: Recipient, + from_chat_id: Recipient, + message_ids: Vec, + ) -> ErasedRequest<'a, ForwardMessages, Self::Err> { + Requester::forward_messages(self, chat_id, from_chat_id, message_ids).erase() + } + fn copy_message( &self, chat_id: Recipient, @@ -1028,6 +1063,15 @@ where Requester::copy_message(self, chat_id, from_chat_id, message_id).erase() } + fn copy_messages( + &self, + chat_id: Recipient, + from_chat_id: Recipient, + message_ids: Vec, + ) -> ErasedRequest<'a, CopyMessages, Self::Err> { + Requester::copy_messages(self, chat_id, from_chat_id, message_ids).erase() + } + fn send_photo( &self, chat_id: Recipient, @@ -1676,6 +1720,14 @@ where Requester::delete_message(self, chat_id, message_id).erase() } + fn delete_messages( + &self, + chat_id: Recipient, + message_ids: Vec, + ) -> ErasedRequest<'a, DeleteMessages, Self::Err> { + Requester::delete_messages(self, chat_id, message_ids).erase() + } + fn send_sticker( &self, chat_id: Recipient, diff --git a/crates/teloxide-core/src/adaptors/parse_mode.rs b/crates/teloxide-core/src/adaptors/parse_mode.rs index 216893a4..f9458bca 100644 --- a/crates/teloxide-core/src/adaptors/parse_mode.rs +++ b/crates/teloxide-core/src/adaptors/parse_mode.rs @@ -185,6 +185,8 @@ where delete_webhook, get_webhook_info, forward_message, + forward_messages, + copy_messages, send_video_note, send_location, edit_message_live_location, @@ -256,6 +258,7 @@ where edit_message_reply_markup_inline, stop_poll, delete_message, + delete_messages, send_sticker, get_sticker_set, get_custom_emoji_stickers, diff --git a/crates/teloxide-core/src/adaptors/throttle/requester_impl.rs b/crates/teloxide-core/src/adaptors/throttle/requester_impl.rs index 28d82051..eb9cbb41 100644 --- a/crates/teloxide-core/src/adaptors/throttle/requester_impl.rs +++ b/crates/teloxide-core/src/adaptors/throttle/requester_impl.rs @@ -92,6 +92,8 @@ where set_webhook, delete_webhook, get_webhook_info, + forward_messages, + copy_messages, edit_message_live_location, edit_message_live_location_inline, stop_message_live_location, @@ -166,6 +168,7 @@ where edit_message_reply_markup_inline, stop_poll, delete_message, + delete_messages, get_sticker_set, get_custom_emoji_stickers, upload_sticker_file, diff --git a/crates/teloxide-core/src/adaptors/trace.rs b/crates/teloxide-core/src/adaptors/trace.rs index 46882c6b..cef5fa7e 100644 --- a/crates/teloxide-core/src/adaptors/trace.rs +++ b/crates/teloxide-core/src/adaptors/trace.rs @@ -123,7 +123,9 @@ where delete_webhook, get_webhook_info, forward_message, + forward_messages, copy_message, + copy_messages, send_message, send_photo, send_audio, @@ -212,6 +214,7 @@ where edit_message_reply_markup_inline, stop_poll, delete_message, + delete_messages, send_sticker, get_sticker_set, get_custom_emoji_stickers, diff --git a/crates/teloxide-core/src/bot/api.rs b/crates/teloxide-core/src/bot/api.rs index 380d41a4..7da6ee98 100644 --- a/crates/teloxide-core/src/bot/api.rs +++ b/crates/teloxide-core/src/bot/api.rs @@ -72,6 +72,24 @@ impl Requester for Bot { ) } + type ForwardMessages = JsonRequest; + fn forward_messages( + &self, + chat_id: C, + from_chat_id: F, + message_ids: M, + ) -> Self::ForwardMessages + where + C: Into, + F: Into, + M: IntoIterator, + { + Self::ForwardMessages::new( + self.clone(), + payloads::ForwardMessages::new(chat_id, from_chat_id, message_ids), + ) + } + type SendPhoto = MultipartRequest; fn send_photo(&self, chat_id: C, photo: InputFile) -> Self::SendPhoto @@ -1086,6 +1104,15 @@ impl Requester for Bot { Self::DeleteMessage::new(self.clone(), payloads::DeleteMessage::new(chat_id, message_id)) } + type DeleteMessages = JsonRequest; + fn delete_messages(&self, chat_id: C, message_ids: M) -> Self::DeleteMessages + where + C: Into, + M: IntoIterator, + { + Self::DeleteMessages::new(self.clone(), payloads::DeleteMessages::new(chat_id, message_ids)) + } + type SendSticker = MultipartRequest; fn send_sticker(&self, chat_id: C, sticker: InputFile) -> Self::SendSticker @@ -1465,6 +1492,24 @@ impl Requester for Bot { ) } + type CopyMessages = JsonRequest; + fn copy_messages( + &self, + chat_id: C, + from_chat_id: F, + message_ids: M, + ) -> Self::CopyMessages + where + C: Into, + F: Into, + M: IntoIterator, + { + Self::CopyMessages::new( + self.clone(), + payloads::CopyMessages::new(chat_id, from_chat_id, message_ids), + ) + } + type UnpinAllChatMessages = JsonRequest; fn unpin_all_chat_messages(&self, chat_id: C) -> Self::UnpinAllChatMessages diff --git a/crates/teloxide-core/src/local_macros.rs b/crates/teloxide-core/src/local_macros.rs index 93108978..41ae27a6 100644 --- a/crates/teloxide-core/src/local_macros.rs +++ b/crates/teloxide-core/src/local_macros.rs @@ -487,6 +487,16 @@ macro_rules! requester_forward { $body!(forward_message this (chat_id: C, from_chat_id: F, message_id: MessageId)) } }; + (@method forward_messages $body:ident $ty:ident) => { + type ForwardMessages = $ty![ForwardMessages]; + + fn forward_messages(&self, chat_id: C, from_chat_id: F, message_ids: M) -> Self::ForwardMessages where C: Into, + F: Into, + M: IntoIterator { + let this = self; + $body!(forward_messages this (chat_id: C, from_chat_id: F, message_ids: M)) + } + }; (@method copy_message $body:ident $ty:ident) => { type CopyMessage = $ty![CopyMessage]; @@ -496,6 +506,16 @@ macro_rules! requester_forward { $body!(copy_message this (chat_id: C, from_chat_id: F, message_id: MessageId)) } }; + (@method copy_messages $body:ident $ty:ident) => { + type CopyMessages = $ty![CopyMessages]; + + fn copy_messages(&self, chat_id: C, from_chat_id: F, message_ids: M) -> Self::CopyMessages where C: Into, + F: Into, + M: IntoIterator { + let this = self; + $body!(copy_messages this (chat_id: C, from_chat_id: F, message_ids: M)) + } + }; (@method send_photo $body:ident $ty:ident) => { type SendPhoto = $ty![SendPhoto]; @@ -1228,6 +1248,15 @@ macro_rules! requester_forward { $body!(delete_message this (chat_id: C, message_id: MessageId)) } }; + (@method delete_messages $body:ident $ty:ident) => { + type DeleteMessages = $ty![DeleteMessages]; + + fn delete_messages(&self, chat_id: C, message_ids: M) -> Self::DeleteMessages where C: Into, + M: IntoIterator { + let this = self; + $body!(delete_messages this (chat_id: C, message_ids: M)) + } + }; (@method send_sticker $body:ident $ty:ident) => { type SendSticker = $ty![SendSticker]; diff --git a/crates/teloxide-core/src/payloads.rs b/crates/teloxide-core/src/payloads.rs index 7f3cf308..ee3f845e 100644 --- a/crates/teloxide-core/src/payloads.rs +++ b/crates/teloxide-core/src/payloads.rs @@ -28,6 +28,7 @@ mod close; mod close_forum_topic; mod close_general_forum_topic; mod copy_message; +mod copy_messages; mod create_chat_invite_link; mod create_forum_topic; mod create_invoice_link; @@ -37,6 +38,7 @@ mod delete_chat_photo; mod delete_chat_sticker_set; mod delete_forum_topic; mod delete_message; +mod delete_messages; mod delete_my_commands; mod delete_sticker_from_set; mod delete_sticker_set; @@ -56,6 +58,7 @@ mod edit_message_text; mod edit_message_text_inline; mod export_chat_invite_link; mod forward_message; +mod forward_messages; mod get_chat; mod get_chat_administrators; mod get_chat_member; @@ -152,6 +155,7 @@ pub use close::{Close, CloseSetters}; pub use close_forum_topic::{CloseForumTopic, CloseForumTopicSetters}; pub use close_general_forum_topic::{CloseGeneralForumTopic, CloseGeneralForumTopicSetters}; pub use copy_message::{CopyMessage, CopyMessageSetters}; +pub use copy_messages::{CopyMessages, CopyMessagesSetters}; pub use create_chat_invite_link::{CreateChatInviteLink, CreateChatInviteLinkSetters}; pub use create_forum_topic::{CreateForumTopic, CreateForumTopicSetters}; pub use create_invoice_link::{CreateInvoiceLink, CreateInvoiceLinkSetters}; @@ -161,6 +165,7 @@ pub use delete_chat_photo::{DeleteChatPhoto, DeleteChatPhotoSetters}; pub use delete_chat_sticker_set::{DeleteChatStickerSet, DeleteChatStickerSetSetters}; pub use delete_forum_topic::{DeleteForumTopic, DeleteForumTopicSetters}; pub use delete_message::{DeleteMessage, DeleteMessageSetters}; +pub use delete_messages::{DeleteMessages, DeleteMessagesSetters}; pub use delete_my_commands::{DeleteMyCommands, DeleteMyCommandsSetters}; pub use delete_sticker_from_set::{DeleteStickerFromSet, DeleteStickerFromSetSetters}; pub use delete_sticker_set::{DeleteStickerSet, DeleteStickerSetSetters}; @@ -184,6 +189,7 @@ pub use edit_message_text::{EditMessageText, EditMessageTextSetters}; pub use edit_message_text_inline::{EditMessageTextInline, EditMessageTextInlineSetters}; pub use export_chat_invite_link::{ExportChatInviteLink, ExportChatInviteLinkSetters}; pub use forward_message::{ForwardMessage, ForwardMessageSetters}; +pub use forward_messages::{ForwardMessages, ForwardMessagesSetters}; pub use get_chat::{GetChat, GetChatSetters}; pub use get_chat_administrators::{GetChatAdministrators, GetChatAdministratorsSetters}; pub use get_chat_member::{GetChatMember, GetChatMemberSetters}; diff --git a/crates/teloxide-core/src/payloads/copy_messages.rs b/crates/teloxide-core/src/payloads/copy_messages.rs new file mode 100644 index 00000000..033a5c64 --- /dev/null +++ b/crates/teloxide-core/src/payloads/copy_messages.rs @@ -0,0 +1,36 @@ +//! Generated by `codegen_payloads`, do not edit by hand. + +use serde::Serialize; + +use crate::types::{MessageId, Recipient, ThreadId}; + +impl_payload! { + /// Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz [`Poll`] can be copied only if the value of the field _correct\_option\_id_ is known to the bot. The method is analogous to the method [`ForwardMessages`], but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. On success, an array of [`MessageId`] of the sent messages is returned. + /// + /// [`MessageId`]: crate::types::MessageId + /// [`Poll`]: crate::payloads::Poll + /// [`ForwardMessages`]: crate::payloads::ForwardMessages + #[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize)] + pub CopyMessages (CopyMessagesSetters) => Vec { + required { + /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) + pub chat_id: Recipient [into], + /// Unique identifier for the chat where the original message was sent (or channel username in the format `@channelusername`) + pub from_chat_id: Recipient [into], + /// Identifiers of 1-100 messages in the chat _from\_chat\_id_ to copy. The identifiers must be specified in a strictly increasing order. + pub message_ids: Vec [collect], + } + optional { + /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + pub message_thread_id: ThreadId, + /// Sends the message [silently]. Users will receive a notification with no sound. + /// + /// [silently]: https://telegram.org/blog/channels-2-0#silent-messages + pub disable_notification: bool, + /// Protects the contents of sent messages from forwarding and saving + pub protect_content: bool, + /// Pass _True_ to copy the messages without their captions + pub remove_caption: bool, + } + } +} diff --git a/crates/teloxide-core/src/payloads/delete_messages.rs b/crates/teloxide-core/src/payloads/delete_messages.rs new file mode 100644 index 00000000..f8306c03 --- /dev/null +++ b/crates/teloxide-core/src/payloads/delete_messages.rs @@ -0,0 +1,20 @@ +//! Generated by `codegen_payloads`, do not edit by hand. + +use serde::Serialize; + +use crate::types::{MessageId, Recipient, True}; + +impl_payload! { + /// Use this method to delete multiple messages simultaneously. If some of the specified messages can't be found, they are skipped. Returns _True_ on success. + #[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize)] + pub DeleteMessages (DeleteMessagesSetters) => True { + required { + /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`). + pub chat_id: Recipient [into], + /// Identifiers of 1-100 messages to delete. See [`DeleteMessage`] for limitations on which messages can be deleted + /// + /// [`DeleteMessage`]: crate::payloads::DeleteMessage + pub message_ids: Vec [collect], + } + } +} diff --git a/crates/teloxide-core/src/payloads/forward_messages.rs b/crates/teloxide-core/src/payloads/forward_messages.rs new file mode 100644 index 00000000..e191725b --- /dev/null +++ b/crates/teloxide-core/src/payloads/forward_messages.rs @@ -0,0 +1,32 @@ +//! Generated by `codegen_payloads`, do not edit by hand. + +use serde::Serialize; + +use crate::types::{MessageId, Recipient, ThreadId}; + +impl_payload! { + /// Use this method to forward multiple messages of any kind. If some of the specified messages can't be found or forwarded, they are skipped. Service messages and messages with protected content can't be forwarded. Album grouping is kept for forwarded messages. On success, an array of [`MessageId`] of the sent messages is returned. + /// + /// [`MessageId`]: crate::types::MessageId + #[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize)] + pub ForwardMessages (ForwardMessagesSetters) => Vec { + required { + /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) + pub chat_id: Recipient [into], + /// Unique identifier for the chat where the original message was sent (or channel username in the format `@channelusername`) + pub from_chat_id: Recipient [into], + /// A JSON-serialized list of 1-100 identifiers of messages in the chat _from\_chat\_id_ to forward. The identifiers must be specified in a strictly increasing order. + pub message_ids: Vec [collect], + } + optional { + /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + pub message_thread_id: ThreadId, + /// Sends the message [silently]. Users will receive a notification with no sound. + /// + /// [silently]: https://telegram.org/blog/channels-2-0#silent-messages + pub disable_notification: bool, + /// Protects the contents of sent messages from forwarding and saving + pub protect_content: bool, + } + } +} diff --git a/crates/teloxide-core/src/payloads/setters.rs b/crates/teloxide-core/src/payloads/setters.rs index 9771e38b..96ba6712 100644 --- a/crates/teloxide-core/src/payloads/setters.rs +++ b/crates/teloxide-core/src/payloads/setters.rs @@ -6,18 +6,19 @@ pub use crate::payloads::{ AnswerPreCheckoutQuerySetters as _, AnswerShippingQuerySetters as _, AnswerWebAppQuerySetters as _, ApproveChatJoinRequestSetters as _, BanChatMemberSetters as _, BanChatSenderChatSetters as _, CloseForumTopicSetters as _, CloseGeneralForumTopicSetters as _, - CloseSetters as _, CopyMessageSetters as _, CreateChatInviteLinkSetters as _, - CreateForumTopicSetters as _, CreateInvoiceLinkSetters as _, CreateNewStickerSetSetters as _, - DeclineChatJoinRequestSetters as _, DeleteChatPhotoSetters as _, - DeleteChatStickerSetSetters as _, DeleteForumTopicSetters as _, DeleteMessageSetters as _, - DeleteMyCommandsSetters as _, DeleteStickerFromSetSetters as _, DeleteStickerSetSetters as _, - DeleteWebhookSetters as _, EditChatInviteLinkSetters as _, EditForumTopicSetters as _, - EditGeneralForumTopicSetters as _, EditMessageCaptionInlineSetters as _, - EditMessageCaptionSetters as _, EditMessageLiveLocationInlineSetters as _, - EditMessageLiveLocationSetters as _, EditMessageMediaInlineSetters as _, - EditMessageMediaSetters as _, EditMessageReplyMarkupInlineSetters as _, - EditMessageReplyMarkupSetters as _, EditMessageTextInlineSetters as _, - EditMessageTextSetters as _, ExportChatInviteLinkSetters as _, ForwardMessageSetters as _, + CloseSetters as _, CopyMessageSetters as _, CopyMessagesSetters as _, + CreateChatInviteLinkSetters as _, CreateForumTopicSetters as _, CreateInvoiceLinkSetters as _, + CreateNewStickerSetSetters as _, DeclineChatJoinRequestSetters as _, + DeleteChatPhotoSetters as _, DeleteChatStickerSetSetters as _, DeleteForumTopicSetters as _, + DeleteMessageSetters as _, DeleteMessagesSetters as _, DeleteMyCommandsSetters as _, + DeleteStickerFromSetSetters as _, DeleteStickerSetSetters as _, DeleteWebhookSetters as _, + EditChatInviteLinkSetters as _, EditForumTopicSetters as _, EditGeneralForumTopicSetters as _, + EditMessageCaptionInlineSetters as _, EditMessageCaptionSetters as _, + EditMessageLiveLocationInlineSetters as _, EditMessageLiveLocationSetters as _, + EditMessageMediaInlineSetters as _, EditMessageMediaSetters as _, + EditMessageReplyMarkupInlineSetters as _, EditMessageReplyMarkupSetters as _, + EditMessageTextInlineSetters as _, EditMessageTextSetters as _, + ExportChatInviteLinkSetters as _, ForwardMessageSetters as _, ForwardMessagesSetters as _, GetChatAdministratorsSetters as _, GetChatMemberCountSetters as _, GetChatMemberSetters as _, GetChatMembersCountSetters as _, GetChatMenuButtonSetters as _, GetChatSetters as _, GetCustomEmojiStickersSetters as _, GetFileSetters as _, GetForumTopicIconStickersSetters as _, diff --git a/crates/teloxide-core/src/requests/requester.rs b/crates/teloxide-core/src/requests/requester.rs index a67b3a97..0b97abf9 100644 --- a/crates/teloxide-core/src/requests/requester.rs +++ b/crates/teloxide-core/src/requests/requester.rs @@ -203,6 +203,20 @@ pub trait Requester { C: Into, F: Into; + type ForwardMessages: Request; + + /// For Telegram documentation see [`ForwardMessages`]. + fn forward_messages( + &self, + chat_id: C, + from_chat_id: F, + message_ids: M, + ) -> Self::ForwardMessages + where + C: Into, + F: Into, + M: IntoIterator; + type CopyMessage: Request; /// For Telegram documentation see [`CopyMessage`]. @@ -216,6 +230,20 @@ pub trait Requester { C: Into, F: Into; + type CopyMessages: Request; + + /// For Telegram documentation see [`CopyMessages`]. + fn copy_messages( + &self, + chat_id: C, + from_chat_id: F, + message_ids: M, + ) -> Self::CopyMessages + where + C: Into, + F: Into, + M: IntoIterator; + type SendPhoto: Request; /// For Telegram documentation see [`SendPhoto`]. @@ -977,6 +1005,14 @@ pub trait Requester { where C: Into; + type DeleteMessages: Request; + + /// For Telegram documentation see [`DeleteMessages`]. + fn delete_messages(&self, chat_id: C, message_ids: M) -> Self::DeleteMessages + where + C: Into, + M: IntoIterator; + type SendSticker: Request; /// For Telegram documentation see [`SendSticker`]. @@ -1249,7 +1285,9 @@ macro_rules! forward_all { delete_webhook, get_webhook_info, forward_message, + forward_messages, copy_message, + copy_messages, send_message, send_photo, send_audio, @@ -1338,6 +1376,7 @@ macro_rules! forward_all { edit_message_reply_markup_inline, stop_poll, delete_message, + delete_messages, send_sticker, get_sticker_set, get_custom_emoji_stickers,