#![allow(clippy::too_many_arguments)]
use url::Url;
use crate::{errors::AsResponseParameters, payloads::*, requests::Request, types::*};
#[cfg_attr(all(any(docsrs, dep_docsrs), feature = "nightly"), doc(notable_trait))]
pub trait Requester {
type Err: std::error::Error + Send + AsResponseParameters;
type GetUpdates: Request<Payload = GetUpdates, Err = Self::Err>;
fn get_updates(&self) -> Self::GetUpdates;
type SetWebhook: Request<Payload = SetWebhook, Err = Self::Err>;
fn set_webhook(&self, url: Url) -> Self::SetWebhook;
type DeleteWebhook: Request<Payload = DeleteWebhook, Err = Self::Err>;
fn delete_webhook(&self) -> Self::DeleteWebhook;
type GetWebhookInfo: Request<Payload = GetWebhookInfo, Err = Self::Err>;
fn get_webhook_info(&self) -> Self::GetWebhookInfo;
type GetMe: Request<Payload = GetMe, Err = Self::Err>;
fn get_me(&self) -> Self::GetMe;
type LogOut: Request<Payload = LogOut, Err = Self::Err>;
fn log_out(&self) -> Self::LogOut;
type Close: Request<Payload = Close, Err = Self::Err>;
fn close(&self) -> Self::Close;
type SendMessage: Request<Payload = SendMessage, Err = Self::Err>;
fn send_message<C, T>(&self, chat_id: C, text: T) -> Self::SendMessage
where
C: Into<Recipient>,
T: Into<String>;
type ForwardMessage: Request<Payload = ForwardMessage, Err = Self::Err>;
fn forward_message<C, F>(
&self,
chat_id: C,
from_chat_id: F,
message_id: MessageId,
) -> Self::ForwardMessage
where
C: Into<Recipient>,
F: Into<Recipient>;
type ForwardMessages: Request<Payload = ForwardMessages, Err = Self::Err>;
fn forward_messages<C, F, M>(
&self,
chat_id: C,
from_chat_id: F,
message_ids: M,
) -> Self::ForwardMessages
where
C: Into<Recipient>,
F: Into<Recipient>,
M: IntoIterator<Item = MessageId>;
type CopyMessage: Request<Payload = CopyMessage, Err = Self::Err>;
fn copy_message<C, F>(
&self,
chat_id: C,
from_chat_id: F,
message_id: MessageId,
) -> Self::CopyMessage
where
C: Into<Recipient>,
F: Into<Recipient>;
type CopyMessages: Request<Payload = CopyMessages, Err = Self::Err>;
fn copy_messages<C, F, M>(
&self,
chat_id: C,
from_chat_id: F,
message_ids: M,
) -> Self::CopyMessages
where
C: Into<Recipient>,
F: Into<Recipient>,
M: IntoIterator<Item = MessageId>;
type SendPhoto: Request<Payload = SendPhoto, Err = Self::Err>;
fn send_photo<C>(&self, chat_id: C, photo: InputFile) -> Self::SendPhoto
where
C: Into<Recipient>;
type SendAudio: Request<Payload = SendAudio, Err = Self::Err>;
fn send_audio<C>(&self, chat_id: C, audio: InputFile) -> Self::SendAudio
where
C: Into<Recipient>;
type SendDocument: Request<Payload = SendDocument, Err = Self::Err>;
fn send_document<C>(&self, chat_id: C, document: InputFile) -> Self::SendDocument
where
C: Into<Recipient>;
type SendVideo: Request<Payload = SendVideo, Err = Self::Err>;
fn send_video<C>(&self, chat_id: C, video: InputFile) -> Self::SendVideo
where
C: Into<Recipient>;
type SendAnimation: Request<Payload = SendAnimation, Err = Self::Err>;
fn send_animation<C>(&self, chat_id: C, animation: InputFile) -> Self::SendAnimation
where
C: Into<Recipient>;
type SendVoice: Request<Payload = SendVoice, Err = Self::Err>;
fn send_voice<C>(&self, chat_id: C, voice: InputFile) -> Self::SendVoice
where
C: Into<Recipient>;
type SendVideoNote: Request<Payload = SendVideoNote, Err = Self::Err>;
fn send_video_note<C>(&self, chat_id: C, video_note: InputFile) -> Self::SendVideoNote
where
C: Into<Recipient>;
type SendMediaGroup: Request<Payload = SendMediaGroup, Err = Self::Err>;
fn send_media_group<C, M>(&self, chat_id: C, media: M) -> Self::SendMediaGroup
where
C: Into<Recipient>,
M: IntoIterator<Item = InputMedia>;
type SendLocation: Request<Payload = SendLocation, Err = Self::Err>;
fn send_location<C>(&self, chat_id: C, latitude: f64, longitude: f64) -> Self::SendLocation
where
C: Into<Recipient>;
type EditMessageLiveLocation: Request<Payload = EditMessageLiveLocation, Err = Self::Err>;
fn edit_message_live_location<C>(
&self,
chat_id: C,
message_id: MessageId,
latitude: f64,
longitude: f64,
) -> Self::EditMessageLiveLocation
where
C: Into<Recipient>;
type EditMessageLiveLocationInline: Request<
Payload = EditMessageLiveLocationInline,
Err = Self::Err,
>;
fn edit_message_live_location_inline<I>(
&self,
inline_message_id: I,
latitude: f64,
longitude: f64,
) -> Self::EditMessageLiveLocationInline
where
I: Into<String>;
type StopMessageLiveLocation: Request<Payload = StopMessageLiveLocation, Err = Self::Err>;
fn stop_message_live_location<C>(
&self,
chat_id: C,
message_id: MessageId,
) -> Self::StopMessageLiveLocation
where
C: Into<Recipient>;
type StopMessageLiveLocationInline: Request<
Payload = StopMessageLiveLocationInline,
Err = Self::Err,
>;
fn stop_message_live_location_inline<I>(
&self,
inline_message_id: I,
) -> Self::StopMessageLiveLocationInline
where
I: Into<String>;
type SendVenue: Request<Payload = SendVenue, Err = Self::Err>;
fn send_venue<C, T, A>(
&self,
chat_id: C,
latitude: f64,
longitude: f64,
title: T,
address: A,
) -> Self::SendVenue
where
C: Into<Recipient>,
T: Into<String>,
A: Into<String>;
type SendContact: Request<Payload = SendContact, Err = Self::Err>;
fn send_contact<C, P, F>(
&self,
chat_id: C,
phone_number: P,
first_name: F,
) -> Self::SendContact
where
C: Into<Recipient>,
P: Into<String>,
F: Into<String>;
type SendPoll: Request<Payload = SendPoll, Err = Self::Err>;
fn send_poll<C, Q, O>(&self, chat_id: C, question: Q, options: O) -> Self::SendPoll
where
C: Into<Recipient>,
Q: Into<String>,
O: IntoIterator<Item = String>;
type SendDice: Request<Payload = SendDice, Err = Self::Err>;
fn send_dice<C>(&self, chat_id: C) -> Self::SendDice
where
C: Into<Recipient>;
type SendChatAction: Request<Payload = SendChatAction, Err = Self::Err>;
fn send_chat_action<C>(&self, chat_id: C, action: ChatAction) -> Self::SendChatAction
where
C: Into<Recipient>;
type SetMessageReaction: Request<Payload = SetMessageReaction, Err = Self::Err>;
fn set_message_reaction<C>(
&self,
chat_id: C,
message_id: MessageId,
) -> Self::SetMessageReaction
where
C: Into<Recipient>;
type GetUserProfilePhotos: Request<Payload = GetUserProfilePhotos, Err = Self::Err>;
fn get_user_profile_photos(&self, user_id: UserId) -> Self::GetUserProfilePhotos;
type GetFile: Request<Payload = GetFile, Err = Self::Err>;
fn get_file<F>(&self, file_id: F) -> Self::GetFile
where
F: Into<String>;
type BanChatMember: Request<Payload = BanChatMember, Err = Self::Err>;
fn ban_chat_member<C>(&self, chat_id: C, user_id: UserId) -> Self::BanChatMember
where
C: Into<Recipient>;
type KickChatMember: Request<Payload = KickChatMember, Err = Self::Err>;
fn kick_chat_member<C>(&self, chat_id: C, user_id: UserId) -> Self::KickChatMember
where
C: Into<Recipient>;
type UnbanChatMember: Request<Payload = UnbanChatMember, Err = Self::Err>;
fn unban_chat_member<C>(&self, chat_id: C, user_id: UserId) -> Self::UnbanChatMember
where
C: Into<Recipient>;
type RestrictChatMember: Request<Payload = RestrictChatMember, Err = Self::Err>;
fn restrict_chat_member<C>(
&self,
chat_id: C,
user_id: UserId,
permissions: ChatPermissions,
) -> Self::RestrictChatMember
where
C: Into<Recipient>;
type PromoteChatMember: Request<Payload = PromoteChatMember, Err = Self::Err>;
fn promote_chat_member<C>(&self, chat_id: C, user_id: UserId) -> Self::PromoteChatMember
where
C: Into<Recipient>;
type SetChatAdministratorCustomTitle: Request<
Payload = SetChatAdministratorCustomTitle,
Err = Self::Err,
>;
fn set_chat_administrator_custom_title<Ch, C>(
&self,
chat_id: Ch,
user_id: UserId,
custom_title: C,
) -> Self::SetChatAdministratorCustomTitle
where
Ch: Into<Recipient>,
C: Into<String>;
type BanChatSenderChat: Request<Payload = BanChatSenderChat, Err = Self::Err>;
fn ban_chat_sender_chat<C, S>(&self, chat_id: C, sender_chat_id: S) -> Self::BanChatSenderChat
where
C: Into<Recipient>,
S: Into<ChatId>;
type UnbanChatSenderChat: Request<Payload = UnbanChatSenderChat, Err = Self::Err>;
fn unban_chat_sender_chat<C, S>(
&self,
chat_id: C,
sender_chat_id: S,
) -> Self::UnbanChatSenderChat
where
C: Into<Recipient>,
S: Into<ChatId>;
type SetChatPermissions: Request<Payload = SetChatPermissions, Err = Self::Err>;
fn set_chat_permissions<C>(
&self,
chat_id: C,
permissions: ChatPermissions,
) -> Self::SetChatPermissions
where
C: Into<Recipient>;
type ExportChatInviteLink: Request<Payload = ExportChatInviteLink, Err = Self::Err>;
fn export_chat_invite_link<C>(&self, chat_id: C) -> Self::ExportChatInviteLink
where
C: Into<Recipient>;
type CreateChatInviteLink: Request<Payload = CreateChatInviteLink, Err = Self::Err>;
fn create_chat_invite_link<C>(&self, chat_id: C) -> Self::CreateChatInviteLink
where
C: Into<Recipient>;
type EditChatInviteLink: Request<Payload = EditChatInviteLink, Err = Self::Err>;
fn edit_chat_invite_link<C, I>(&self, chat_id: C, invite_link: I) -> Self::EditChatInviteLink
where
C: Into<Recipient>,
I: Into<String>;
type RevokeChatInviteLink: Request<Payload = RevokeChatInviteLink, Err = Self::Err>;
fn revoke_chat_invite_link<C, I>(
&self,
chat_id: C,
invite_link: I,
) -> Self::RevokeChatInviteLink
where
C: Into<Recipient>,
I: Into<String>;
type ApproveChatJoinRequest: Request<Payload = ApproveChatJoinRequest, Err = Self::Err>;
fn approve_chat_join_request<C>(
&self,
chat_id: C,
user_id: UserId,
) -> Self::ApproveChatJoinRequest
where
C: Into<Recipient>;
type DeclineChatJoinRequest: Request<Payload = DeclineChatJoinRequest, Err = Self::Err>;
fn decline_chat_join_request<C>(
&self,
chat_id: C,
user_id: UserId,
) -> Self::DeclineChatJoinRequest
where
C: Into<Recipient>;
type SetChatPhoto: Request<Payload = SetChatPhoto, Err = Self::Err>;
fn set_chat_photo<C>(&self, chat_id: C, photo: InputFile) -> Self::SetChatPhoto
where
C: Into<Recipient>;
type DeleteChatPhoto: Request<Payload = DeleteChatPhoto, Err = Self::Err>;
fn delete_chat_photo<C>(&self, chat_id: C) -> Self::DeleteChatPhoto
where
C: Into<Recipient>;
type SetChatTitle: Request<Payload = SetChatTitle, Err = Self::Err>;
fn set_chat_title<C, T>(&self, chat_id: C, title: T) -> Self::SetChatTitle
where
C: Into<Recipient>,
T: Into<String>;
type SetChatDescription: Request<Payload = SetChatDescription, Err = Self::Err>;
fn set_chat_description<C>(&self, chat_id: C) -> Self::SetChatDescription
where
C: Into<Recipient>;
type PinChatMessage: Request<Payload = PinChatMessage, Err = Self::Err>;
fn pin_chat_message<C>(&self, chat_id: C, message_id: MessageId) -> Self::PinChatMessage
where
C: Into<Recipient>;
type UnpinChatMessage: Request<Payload = UnpinChatMessage, Err = Self::Err>;
fn unpin_chat_message<C>(&self, chat_id: C) -> Self::UnpinChatMessage
where
C: Into<Recipient>;
type UnpinAllChatMessages: Request<Payload = UnpinAllChatMessages, Err = Self::Err>;
fn unpin_all_chat_messages<C>(&self, chat_id: C) -> Self::UnpinAllChatMessages
where
C: Into<Recipient>;
type LeaveChat: Request<Payload = LeaveChat, Err = Self::Err>;
fn leave_chat<C>(&self, chat_id: C) -> Self::LeaveChat
where
C: Into<Recipient>;
type GetChat: Request<Payload = GetChat, Err = Self::Err>;
fn get_chat<C>(&self, chat_id: C) -> Self::GetChat
where
C: Into<Recipient>;
type GetChatAdministrators: Request<Payload = GetChatAdministrators, Err = Self::Err>;
fn get_chat_administrators<C>(&self, chat_id: C) -> Self::GetChatAdministrators
where
C: Into<Recipient>;
type GetChatMemberCount: Request<Payload = GetChatMemberCount, Err = Self::Err>;
fn get_chat_member_count<C>(&self, chat_id: C) -> Self::GetChatMemberCount
where
C: Into<Recipient>;
type GetChatMembersCount: Request<Payload = GetChatMembersCount, Err = Self::Err>;
fn get_chat_members_count<C>(&self, chat_id: C) -> Self::GetChatMembersCount
where
C: Into<Recipient>;
type GetChatMember: Request<Payload = GetChatMember, Err = Self::Err>;
fn get_chat_member<C>(&self, chat_id: C, user_id: UserId) -> Self::GetChatMember
where
C: Into<Recipient>;
type SetChatStickerSet: Request<Payload = SetChatStickerSet, Err = Self::Err>;
fn set_chat_sticker_set<C, S>(
&self,
chat_id: C,
sticker_set_name: S,
) -> Self::SetChatStickerSet
where
C: Into<Recipient>,
S: Into<String>;
type DeleteChatStickerSet: Request<Payload = DeleteChatStickerSet, Err = Self::Err>;
fn delete_chat_sticker_set<C>(&self, chat_id: C) -> Self::DeleteChatStickerSet
where
C: Into<Recipient>;
type GetForumTopicIconStickers: Request<Payload = GetForumTopicIconStickers, Err = Self::Err>;
fn get_forum_topic_icon_stickers(&self) -> Self::GetForumTopicIconStickers;
type CreateForumTopic: Request<Payload = CreateForumTopic, Err = Self::Err>;
fn create_forum_topic<C, N, I>(
&self,
chat_id: C,
name: N,
icon_color: u32,
icon_custom_emoji_id: I,
) -> Self::CreateForumTopic
where
C: Into<Recipient>,
N: Into<String>,
I: Into<String>;
type EditForumTopic: Request<Payload = EditForumTopic, Err = Self::Err>;
fn edit_forum_topic<C>(&self, chat_id: C, message_thread_id: ThreadId) -> Self::EditForumTopic
where
C: Into<Recipient>;
type CloseForumTopic: Request<Payload = CloseForumTopic, Err = Self::Err>;
fn close_forum_topic<C>(
&self,
chat_id: C,
message_thread_id: ThreadId,
) -> Self::CloseForumTopic
where
C: Into<Recipient>;
type ReopenForumTopic: Request<Payload = ReopenForumTopic, Err = Self::Err>;
fn reopen_forum_topic<C>(
&self,
chat_id: C,
message_thread_id: ThreadId,
) -> Self::ReopenForumTopic
where
C: Into<Recipient>;
type DeleteForumTopic: Request<Payload = DeleteForumTopic, Err = Self::Err>;
fn delete_forum_topic<C>(
&self,
chat_id: C,
message_thread_id: ThreadId,
) -> Self::DeleteForumTopic
where
C: Into<Recipient>;
type UnpinAllForumTopicMessages: Request<Payload = UnpinAllForumTopicMessages, Err = Self::Err>;
fn unpin_all_forum_topic_messages<C>(
&self,
chat_id: C,
message_thread_id: ThreadId,
) -> Self::UnpinAllForumTopicMessages
where
C: Into<Recipient>;
type EditGeneralForumTopic: Request<Payload = EditGeneralForumTopic, Err = Self::Err>;
fn edit_general_forum_topic<C, N>(&self, chat_id: C, name: N) -> Self::EditGeneralForumTopic
where
C: Into<Recipient>,
N: Into<String>;
type CloseGeneralForumTopic: Request<Payload = CloseGeneralForumTopic, Err = Self::Err>;
fn close_general_forum_topic<C>(&self, chat_id: C) -> Self::CloseGeneralForumTopic
where
C: Into<Recipient>;
type ReopenGeneralForumTopic: Request<Payload = ReopenGeneralForumTopic, Err = Self::Err>;
fn reopen_general_forum_topic<C>(&self, chat_id: C) -> Self::ReopenGeneralForumTopic
where
C: Into<Recipient>;
type HideGeneralForumTopic: Request<Payload = HideGeneralForumTopic, Err = Self::Err>;
fn hide_general_forum_topic<C>(&self, chat_id: C) -> Self::HideGeneralForumTopic
where
C: Into<Recipient>;
type UnhideGeneralForumTopic: Request<Payload = UnhideGeneralForumTopic, Err = Self::Err>;
fn unhide_general_forum_topic<C>(&self, chat_id: C) -> Self::UnhideGeneralForumTopic
where
C: Into<Recipient>;
type UnpinAllGeneralForumTopicMessages: Request<
Payload = UnpinAllGeneralForumTopicMessages,
Err = Self::Err,
>;
fn unpin_all_general_forum_topic_messages<C>(
&self,
chat_id: C,
) -> Self::UnpinAllGeneralForumTopicMessages
where
C: Into<Recipient>;
type AnswerCallbackQuery: Request<Payload = AnswerCallbackQuery, Err = Self::Err>;
fn answer_callback_query<C>(&self, callback_query_id: C) -> Self::AnswerCallbackQuery
where
C: Into<String>;
type GetUserChatBoosts: Request<Payload = GetUserChatBoosts, Err = Self::Err>;
fn get_user_chat_boosts<C>(&self, chat_id: C, user_id: UserId) -> Self::GetUserChatBoosts
where
C: Into<Recipient>;
type SetMyCommands: Request<Payload = SetMyCommands, Err = Self::Err>;
fn set_my_commands<C>(&self, commands: C) -> Self::SetMyCommands
where
C: IntoIterator<Item = BotCommand>;
type GetMyCommands: Request<Payload = GetMyCommands, Err = Self::Err>;
fn get_my_commands(&self) -> Self::GetMyCommands;
type SetMyName: Request<Payload = SetMyName, Err = Self::Err>;
fn set_my_name(&self) -> Self::SetMyName;
type GetMyName: Request<Payload = GetMyName, Err = Self::Err>;
fn get_my_name(&self) -> Self::GetMyName;
type SetMyDescription: Request<Payload = SetMyDescription, Err = Self::Err>;
fn set_my_description(&self) -> Self::SetMyDescription;
type GetMyDescription: Request<Payload = GetMyDescription, Err = Self::Err>;
fn get_my_description(&self) -> Self::GetMyDescription;
type SetMyShortDescription: Request<Payload = SetMyShortDescription, Err = Self::Err>;
fn set_my_short_description(&self) -> Self::SetMyShortDescription;
type GetMyShortDescription: Request<Payload = GetMyShortDescription, Err = Self::Err>;
fn get_my_short_description(&self) -> Self::GetMyShortDescription;
type SetChatMenuButton: Request<Payload = SetChatMenuButton, Err = Self::Err>;
fn set_chat_menu_button(&self) -> Self::SetChatMenuButton;
type GetChatMenuButton: Request<Payload = GetChatMenuButton, Err = Self::Err>;
fn get_chat_menu_button(&self) -> Self::GetChatMenuButton;
type SetMyDefaultAdministratorRights: Request<
Payload = SetMyDefaultAdministratorRights,
Err = Self::Err,
>;
fn set_my_default_administrator_rights(&self) -> Self::SetMyDefaultAdministratorRights;
type GetMyDefaultAdministratorRights: Request<
Payload = GetMyDefaultAdministratorRights,
Err = Self::Err,
>;
fn get_my_default_administrator_rights(&self) -> Self::GetMyDefaultAdministratorRights;
type DeleteMyCommands: Request<Payload = DeleteMyCommands, Err = Self::Err>;
fn delete_my_commands(&self) -> Self::DeleteMyCommands;
type AnswerInlineQuery: Request<Payload = AnswerInlineQuery, Err = Self::Err>;
fn answer_inline_query<I, R>(&self, inline_query_id: I, results: R) -> Self::AnswerInlineQuery
where
I: Into<String>,
R: IntoIterator<Item = InlineQueryResult>;
type AnswerWebAppQuery: Request<Payload = AnswerWebAppQuery, Err = Self::Err>;
fn answer_web_app_query<W>(
&self,
web_app_query_id: W,
result: InlineQueryResult,
) -> Self::AnswerWebAppQuery
where
W: Into<String>;
type EditMessageText: Request<Payload = EditMessageText, Err = Self::Err>;
fn edit_message_text<C, T>(
&self,
chat_id: C,
message_id: MessageId,
text: T,
) -> Self::EditMessageText
where
C: Into<Recipient>,
T: Into<String>;
type EditMessageTextInline: Request<Payload = EditMessageTextInline, Err = Self::Err>;
fn edit_message_text_inline<I, T>(
&self,
inline_message_id: I,
text: T,
) -> Self::EditMessageTextInline
where
I: Into<String>,
T: Into<String>;
type EditMessageCaption: Request<Payload = EditMessageCaption, Err = Self::Err>;
fn edit_message_caption<C>(
&self,
chat_id: C,
message_id: MessageId,
) -> Self::EditMessageCaption
where
C: Into<Recipient>;
type EditMessageCaptionInline: Request<Payload = EditMessageCaptionInline, Err = Self::Err>;
fn edit_message_caption_inline<I>(
&self,
inline_message_id: I,
) -> Self::EditMessageCaptionInline
where
I: Into<String>;
type EditMessageMedia: Request<Payload = EditMessageMedia, Err = Self::Err>;
fn edit_message_media<C>(
&self,
chat_id: C,
message_id: MessageId,
media: InputMedia,
) -> Self::EditMessageMedia
where
C: Into<Recipient>;
type EditMessageMediaInline: Request<Payload = EditMessageMediaInline, Err = Self::Err>;
fn edit_message_media_inline<I>(
&self,
inline_message_id: I,
media: InputMedia,
) -> Self::EditMessageMediaInline
where
I: Into<String>;
type EditMessageReplyMarkup: Request<Payload = EditMessageReplyMarkup, Err = Self::Err>;
fn edit_message_reply_markup<C>(
&self,
chat_id: C,
message_id: MessageId,
) -> Self::EditMessageReplyMarkup
where
C: Into<Recipient>;
type EditMessageReplyMarkupInline: Request<
Payload = EditMessageReplyMarkupInline,
Err = Self::Err,
>;
fn edit_message_reply_markup_inline<I>(
&self,
inline_message_id: I,
) -> Self::EditMessageReplyMarkupInline
where
I: Into<String>;
type StopPoll: Request<Payload = StopPoll, Err = Self::Err>;
fn stop_poll<C>(&self, chat_id: C, message_id: MessageId) -> Self::StopPoll
where
C: Into<Recipient>;
type DeleteMessage: Request<Payload = DeleteMessage, Err = Self::Err>;
fn delete_message<C>(&self, chat_id: C, message_id: MessageId) -> Self::DeleteMessage
where
C: Into<Recipient>;
type DeleteMessages: Request<Payload = DeleteMessages, Err = Self::Err>;
fn delete_messages<C, M>(&self, chat_id: C, message_ids: M) -> Self::DeleteMessages
where
C: Into<Recipient>,
M: IntoIterator<Item = MessageId>;
type SendSticker: Request<Payload = SendSticker, Err = Self::Err>;
fn send_sticker<C>(&self, chat_id: C, sticker: InputFile) -> Self::SendSticker
where
C: Into<Recipient>;
type GetStickerSet: Request<Payload = GetStickerSet, Err = Self::Err>;
fn get_sticker_set<N>(&self, name: N) -> Self::GetStickerSet
where
N: Into<String>;
type GetCustomEmojiStickers: Request<Payload = GetCustomEmojiStickers, Err = Self::Err>;
fn get_custom_emoji_stickers<C>(&self, custom_emoji_ids: C) -> Self::GetCustomEmojiStickers
where
C: IntoIterator<Item = String>;
type UploadStickerFile: Request<Payload = UploadStickerFile, Err = Self::Err>;
fn upload_sticker_file(
&self,
user_id: UserId,
sticker: InputFile,
sticker_format: StickerFormat,
) -> Self::UploadStickerFile;
type CreateNewStickerSet: Request<Payload = CreateNewStickerSet, Err = Self::Err>;
fn create_new_sticker_set<N, T, S>(
&self,
user_id: UserId,
name: N,
title: T,
stickers: S,
sticker_format: StickerFormat,
) -> Self::CreateNewStickerSet
where
N: Into<String>,
T: Into<String>,
S: IntoIterator<Item = InputSticker>;
type AddStickerToSet: Request<Payload = AddStickerToSet, Err = Self::Err>;
fn add_sticker_to_set<N>(
&self,
user_id: UserId,
name: N,
sticker: InputSticker,
) -> Self::AddStickerToSet
where
N: Into<String>;
type SetStickerPositionInSet: Request<Payload = SetStickerPositionInSet, Err = Self::Err>;
fn set_sticker_position_in_set<S>(
&self,
sticker: S,
position: u32,
) -> Self::SetStickerPositionInSet
where
S: Into<String>;
type DeleteStickerFromSet: Request<Payload = DeleteStickerFromSet, Err = Self::Err>;
fn delete_sticker_from_set<S>(&self, sticker: S) -> Self::DeleteStickerFromSet
where
S: Into<String>;
type SetStickerSetThumbnail: Request<Payload = SetStickerSetThumbnail, Err = Self::Err>;
fn set_sticker_set_thumbnail<N>(
&self,
name: N,
user_id: UserId,
) -> Self::SetStickerSetThumbnail
where
N: Into<String>;
type SetCustomEmojiStickerSetThumbnail: Request<
Payload = SetCustomEmojiStickerSetThumbnail,
Err = Self::Err,
>;
fn set_custom_emoji_sticker_set_thumbnail<N>(
&self,
name: N,
) -> Self::SetCustomEmojiStickerSetThumbnail
where
N: Into<String>;
type SetStickerSetTitle: Request<Payload = SetStickerSetTitle, Err = Self::Err>;
fn set_sticker_set_title<N, T>(&self, name: N, title: T) -> Self::SetStickerSetTitle
where
N: Into<String>,
T: Into<String>;
type DeleteStickerSet: Request<Payload = DeleteStickerSet, Err = Self::Err>;
fn delete_sticker_set<N>(&self, name: N) -> Self::DeleteStickerSet
where
N: Into<String>;
type SetStickerEmojiList: Request<Payload = SetStickerEmojiList, Err = Self::Err>;
fn set_sticker_emoji_list<S, E>(&self, sticker: S, emoji_list: E) -> Self::SetStickerEmojiList
where
S: Into<String>,
E: IntoIterator<Item = String>;
type SetStickerKeywords: Request<Payload = SetStickerKeywords, Err = Self::Err>;
fn set_sticker_keywords<S>(&self, sticker: S) -> Self::SetStickerKeywords
where
S: Into<String>;
type SetStickerMaskPosition: Request<Payload = SetStickerMaskPosition, Err = Self::Err>;
fn set_sticker_mask_position<S>(&self, sticker: S) -> Self::SetStickerMaskPosition
where
S: Into<String>;
type SendInvoice: Request<Payload = SendInvoice, Err = Self::Err>;
fn send_invoice<Ch, T, D, Pa, P, C, Pri>(
&self,
chat_id: Ch,
title: T,
description: D,
payload: Pa,
provider_token: P,
currency: C,
prices: Pri,
) -> Self::SendInvoice
where
Ch: Into<Recipient>,
T: Into<String>,
D: Into<String>,
Pa: Into<String>,
P: Into<String>,
C: Into<String>,
Pri: IntoIterator<Item = LabeledPrice>;
type CreateInvoiceLink: Request<Payload = CreateInvoiceLink, Err = Self::Err>;
fn create_invoice_link<T, D, Pa, P, C, Pri>(
&self,
title: T,
description: D,
payload: Pa,
provider_token: P,
currency: C,
prices: Pri,
) -> Self::CreateInvoiceLink
where
T: Into<String>,
D: Into<String>,
Pa: Into<String>,
P: Into<String>,
C: Into<String>,
Pri: IntoIterator<Item = LabeledPrice>;
type AnswerShippingQuery: Request<Payload = AnswerShippingQuery, Err = Self::Err>;
fn answer_shipping_query<S>(&self, shipping_query_id: S, ok: bool) -> Self::AnswerShippingQuery
where
S: Into<String>;
type AnswerPreCheckoutQuery: Request<Payload = AnswerPreCheckoutQuery, Err = Self::Err>;
fn answer_pre_checkout_query<P>(
&self,
pre_checkout_query_id: P,
ok: bool,
) -> Self::AnswerPreCheckoutQuery
where
P: Into<String>;
type SetPassportDataErrors: Request<Payload = SetPassportDataErrors, Err = Self::Err>;
fn set_passport_data_errors<E>(
&self,
user_id: UserId,
errors: E,
) -> Self::SetPassportDataErrors
where
E: IntoIterator<Item = PassportElementError>;
type SendGame: Request<Payload = SendGame, Err = Self::Err>;
fn send_game<C, G>(&self, chat_id: C, game_short_name: G) -> Self::SendGame
where
C: Into<ChatId>,
G: Into<String>;
type SetGameScore: Request<Payload = SetGameScore, Err = Self::Err>;
fn set_game_score(
&self,
user_id: UserId,
score: u64,
chat_id: u32,
message_id: MessageId,
) -> Self::SetGameScore;
type SetGameScoreInline: Request<Payload = SetGameScoreInline, Err = Self::Err>;
fn set_game_score_inline<I>(
&self,
user_id: UserId,
score: u64,
inline_message_id: I,
) -> Self::SetGameScoreInline
where
I: Into<String>;
type GetGameHighScores: Request<Payload = GetGameHighScores, Err = Self::Err>;
fn get_game_high_scores<T>(&self, user_id: UserId, target: T) -> Self::GetGameHighScores
where
T: Into<TargetMessage>;
}
macro_rules! fty {
($T:ident) => {
B::$T
};
}
macro_rules! fwd_deref {
($m:ident $this:ident ($($arg:ident : $T:ty),*)) => {
core::ops::Deref::deref($this).$m($($arg),*)
};
}
macro_rules! forward_all {
($body:ident, $ty:ident) => {
requester_forward! {
get_me,
log_out,
close,
get_updates,
set_webhook,
delete_webhook,
get_webhook_info,
forward_message,
forward_messages,
copy_message,
copy_messages,
send_message,
send_photo,
send_audio,
send_document,
send_video,
send_animation,
send_voice,
send_video_note,
send_media_group,
send_location,
edit_message_live_location,
edit_message_live_location_inline,
stop_message_live_location,
stop_message_live_location_inline,
send_venue,
send_contact,
send_poll,
send_dice,
send_chat_action,
set_message_reaction,
get_user_profile_photos,
get_file,
kick_chat_member,
ban_chat_member,
unban_chat_member,
restrict_chat_member,
promote_chat_member,
set_chat_administrator_custom_title,
ban_chat_sender_chat,
unban_chat_sender_chat,
set_chat_permissions,
export_chat_invite_link,
create_chat_invite_link,
edit_chat_invite_link,
revoke_chat_invite_link,
set_chat_photo,
delete_chat_photo,
set_chat_title,
set_chat_description,
pin_chat_message,
unpin_chat_message,
unpin_all_chat_messages,
leave_chat,
get_chat,
get_chat_administrators,
get_chat_members_count,
get_chat_member_count,
get_chat_member,
set_chat_sticker_set,
delete_chat_sticker_set,
get_forum_topic_icon_stickers,
create_forum_topic,
edit_forum_topic,
close_forum_topic,
reopen_forum_topic,
delete_forum_topic,
unpin_all_forum_topic_messages,
edit_general_forum_topic,
close_general_forum_topic,
reopen_general_forum_topic,
hide_general_forum_topic,
unhide_general_forum_topic,
unpin_all_general_forum_topic_messages,
answer_callback_query,
get_user_chat_boosts,
set_my_commands,
get_my_commands,
set_my_name,
get_my_name,
set_my_description,
get_my_description,
set_my_short_description,
get_my_short_description,
set_chat_menu_button,
get_chat_menu_button,
set_my_default_administrator_rights,
get_my_default_administrator_rights,
delete_my_commands,
answer_inline_query,
answer_web_app_query,
edit_message_text,
edit_message_text_inline,
edit_message_caption,
edit_message_caption_inline,
edit_message_media,
edit_message_media_inline,
edit_message_reply_markup,
edit_message_reply_markup_inline,
stop_poll,
delete_message,
delete_messages,
send_sticker,
get_sticker_set,
get_custom_emoji_stickers,
upload_sticker_file,
create_new_sticker_set,
add_sticker_to_set,
set_sticker_position_in_set,
delete_sticker_from_set,
set_sticker_set_thumbnail,
set_custom_emoji_sticker_set_thumbnail,
set_sticker_set_title,
delete_sticker_set,
set_sticker_emoji_list,
set_sticker_keywords,
set_sticker_mask_position,
send_invoice,
create_invoice_link,
answer_shipping_query,
answer_pre_checkout_query,
set_passport_data_errors,
send_game,
set_game_score,
set_game_score_inline,
get_game_high_scores,
approve_chat_join_request,
decline_chat_join_request
=> $body, $ty
}
};
() => {
forward_all! { fwd_deref, fty }
};
}
impl<B> Requester for &B
where
B: Requester,
{
type Err = B::Err;
forward_all! {}
}
impl<B> Requester for &mut B
where
B: Requester,
{
type Err = B::Err;
forward_all! {}
}
impl<B> Requester for Box<B>
where
B: Requester,
{
type Err = B::Err;
forward_all! {}
}
impl<B> Requester for std::sync::Arc<B>
where
B: Requester,
{
type Err = B::Err;
forward_all! {}
}
impl<B> Requester for std::rc::Rc<B>
where
B: Requester,
{
type Err = B::Err;
forward_all! {}
}
#[test]
#[allow(clippy::format_collect)]
fn codegen_requester_methods() {
use crate::codegen::{
add_hidden_preamble,
convert::{convert_for, Convert},
ensure_file_contents, min_prefix, project_root, reformat, replace_block,
schema::{self, Type},
to_uppercase,
};
use indexmap::IndexMap;
use itertools::Itertools;
let schema = schema::get();
let methods = schema
.methods
.iter()
.map(|m| {
let mut convert_params = m
.params
.iter()
.filter(|p| !matches!(p.ty, Type::Option(_)))
.map(|p| (&p.name, convert_for(&p.ty)))
.filter(|(_, c)| !matches!(c, Convert::Id(_)))
.map(|(name, _)| &**name)
.collect::<Vec<_>>();
convert_params.sort_unstable();
let prefixes: IndexMap<_, _> = convert_params
.iter()
.copied()
.chain(["\0"])
.tuple_windows()
.map(|(l, r)| (l, min_prefix(l, r)))
.collect();
let args = m
.params
.iter()
.filter(|p| !matches!(p.ty, schema::Type::Option(_)))
.map(|p| match prefixes.get(&*p.name) {
Some(prefix) => format!("{}: {}", p.name, to_uppercase(prefix)),
None => format!("{}: {}", p.name, p.ty),
})
.join(", ");
let generics = m
.params
.iter()
.flat_map(|p| prefixes.get(&*p.name))
.copied()
.map(to_uppercase)
.join(", ");
let where_clause = m
.params
.iter()
.filter(|p| !matches!(p.ty, Type::Option(_)))
.flat_map(|p| match convert_for(&p.ty) {
Convert::Id(_) => None,
Convert::Into(ty) => {
Some(format!("{}: Into<{}>", &to_uppercase(prefixes[&*p.name]), ty))
}
Convert::Collect(ty) => Some(format!(
"{}: IntoIterator<Item = {}>",
&to_uppercase(prefixes[&*p.name]),
ty
)),
})
.join(",\n ");
let generics =
if generics.is_empty() { String::from("") } else { format!("<{generics}>") };
let where_clause = if where_clause.is_empty() {
String::from("")
} else {
format!(" where {where_clause}")
};
format!(
"
type {Method}: Request<Payload = {Method}, Err = Self::Err>;
/// For Telegram documentation see [`{Method}`].
fn {method} {generics} (&self, {args}) -> Self::{Method}{where_clause};
",
Method = m.names.1,
method = m.names.2,
)
})
.collect::<String>();
let path = project_root().join("src/requests/requester.rs");
ensure_file_contents(
&path,
&reformat(replace_block(
&path,
"requester_methods",
&add_hidden_preamble("codegen_requester_methods", methods),
)),
);
}