use serde::{Deserialize, Serialize};
use crate::file::{InputFile, InputFileVariant, InputMedia};
use crate::markup::InlineKeyboardMarkup;
use crate::message::{
ChatActionKind, DeleteMessage, EditMessageCaption, EditMessageMedia, EditMessageReplyMarkup,
EditMessageText, Location, Message, SendAnimation, SendAudio, SendChatAction, SendContact,
SendDice, SendDocument, SendLocation, SendMediaGroup, SendMessage, SendPhoto, SendPoll,
SendVenue, SendVideo, SendVideoNote, SendVoice, StopPoll,
};
use crate::user::User;
use crate::{JsonMethod, TelegramMethod};
#[derive(Debug, Deserialize)]
pub struct Chat {
pub id: i64,
#[serde(flatten)]
pub kind: ChatKind,
pub title: Option<String>,
pub username: Option<String>,
pub first_name: Option<String>,
pub last_name: Option<String>,
pub photo: Option<ChatPhoto>,
pub bio: Option<String>,
pub description: Option<String>,
pub invite_link: Option<String>,
pub pinned_message: Option<Box<Message>>,
pub permissions: Option<ChatPermissions>,
pub slow_mode_delay: Option<i32>,
pub message_auto_delete_time: Option<i32>,
pub sticker_set_name: Option<String>,
pub can_get_sticker_set: Option<bool>,
pub linked_chat_id: Option<i32>,
pub location: Option<ChatLocation>,
}
impl Chat {
pub fn send_animation(&self, animation: impl Into<InputFileVariant>) -> SendAnimation {
SendAnimation::new(self.id, animation)
}
pub fn send_audio(&self, audio: impl Into<InputFileVariant>) -> SendAudio {
SendAudio::new(self.id, audio)
}
pub fn send_chat_action(&self, action: ChatActionKind) -> SendChatAction {
SendChatAction::new(self.id, action)
}
pub fn send_contact(
&self,
phone_number: impl Into<String>,
first_name: impl Into<String>,
) -> SendContact {
SendContact::new(self.id, phone_number, first_name)
}
pub fn send_dice(&self) -> SendDice {
SendDice::new(self.id)
}
pub fn send_document(&self, document: impl Into<InputFileVariant>) -> SendDocument {
SendDocument::new(self.id, document)
}
pub fn send_location(
&self,
latitude: f32,
longitude: f32,
horizontal_accuracy: f32,
) -> SendLocation {
SendLocation::new(self.id, latitude, longitude, horizontal_accuracy)
}
pub fn send_media_group(&self) -> SendMediaGroup {
SendMediaGroup::new(self.id)
}
pub fn send_message(&self, text: impl Into<String>) -> SendMessage {
SendMessage::new(self.id, text)
}
pub fn send_photo(&self, photo: impl Into<InputFileVariant>) -> SendPhoto {
SendPhoto::new(self.id, photo)
}
pub fn send_poll(&self, question: impl Into<String>, options: Vec<String>) -> SendPoll {
SendPoll::new_regular(self.id, question, options)
}
pub fn send_quiz(
&self,
question: impl Into<String>,
options: Vec<String>,
correct_option_id: u32,
) -> SendPoll {
SendPoll::new_quiz(self.id, question, options, correct_option_id)
}
pub fn send_venue(
&self,
latitude: f32,
longitude: f32,
title: impl Into<String>,
address: impl Into<String>,
) -> SendVenue {
SendVenue::new(self.id, latitude, longitude, title, address)
}
pub fn send_video(&self, video: impl Into<InputFileVariant>) -> SendVideo {
SendVideo::new(self.id, video)
}
pub fn send_video_note(&self, video_note: impl Into<InputFileVariant>) -> SendVideoNote {
SendVideoNote::new(self.id, video_note)
}
pub fn send_voice(&self, voice: impl Into<InputFileVariant>) -> SendVoice {
SendVoice::new(self.id, voice)
}
pub fn ban(&self, user_id: i64) -> BanChatMember {
BanChatMember::new(self.id, user_id)
}
pub fn unban(&self, user_id: i64) -> UnbanChatMember {
UnbanChatMember::new(self.id, user_id)
}
pub fn restrict(&self, user_id: i64, permissions: ChatPermissions) -> RestrictChatMember {
RestrictChatMember::new(self.id, user_id, permissions)
}
pub fn promote(&self, user_id: i64) -> PromoteChatMember {
PromoteChatMember::new(self.id, user_id)
}
pub fn set_administrator_title(
&self,
user_id: i64,
custom_title: impl Into<String>,
) -> SetChatAdministratorCustomTitle {
SetChatAdministratorCustomTitle::new(self.id, user_id, custom_title)
}
pub fn set_permissions(&self, permissions: ChatPermissions) -> SetChatPermissions {
SetChatPermissions::new(self.id, permissions)
}
pub fn export_invite_link(&self) -> ExportChatInviteLink {
ExportChatInviteLink::new(self.id)
}
pub fn create_invite_link(&self) -> CreateChatInviteLink {
CreateChatInviteLink::new(self.id)
}
pub fn edit_invite_link(&self, invite_link: impl Into<String>) -> EditChatInviteLink {
EditChatInviteLink::new(self.id, invite_link)
}
pub fn revoke_invite_link(&self, invite_link: impl Into<String>) -> RevokeChatInviteLink {
RevokeChatInviteLink::new(self.id, invite_link)
}
pub fn approve_join(&self, user_id: i64) -> ApproveChatJoinRequest {
ApproveChatJoinRequest::new(self.id, user_id)
}
pub fn decline_join(&self, user_id: i64) -> DeclineChatJoinRequest {
DeclineChatJoinRequest::new(self.id, user_id)
}
pub fn set_photo(&self, photo: InputFile) -> SetChatPhoto {
SetChatPhoto::new(self.id, photo)
}
pub fn delete_photo(&self) -> DeleteChatPhoto {
DeleteChatPhoto::new(self.id)
}
pub fn set_title(&self, title: impl Into<String>) -> SetChatTitle {
SetChatTitle::new(self.id, title)
}
pub fn set_description(&self, description: impl Into<String>) -> SetChatDescription {
SetChatDescription::new(self.id, description)
}
pub fn remove_description(&self) -> SetChatDescription {
SetChatDescription::new_empty(self.id)
}
pub fn pin_message(&self, message_id: i64) -> PinChatMessage {
PinChatMessage::new(self.id, message_id)
}
pub fn unpin_message(&self, message_id: i64) -> UnpinChatMessage {
UnpinChatMessage::new(self.id, message_id)
}
pub fn unpin_latest_message(&self) -> UnpinChatMessage {
UnpinChatMessage::new_recent(self.id)
}
pub fn unpin_all_messages(&self) -> UnpinAllChatMessages {
UnpinAllChatMessages::new(self.id)
}
pub fn leave(&self) -> LeaveChat {
LeaveChat::new(self.id)
}
pub fn get_details(&self) -> GetChat {
GetChat::new(self.id)
}
pub fn get_administrators(&self) -> GetChatAdministrators {
GetChatAdministrators::new(self.id)
}
pub fn get_member_count(&self) -> GetChatMemberCount {
GetChatMemberCount::new(self.id)
}
pub fn get_member(&self, user_id: i64) -> GetChatMember {
GetChatMember::new(self.id, user_id)
}
pub fn set_sticker_set(&self, sticker_set_name: impl Into<String>) -> SetChatStickerSet {
SetChatStickerSet::new(self.id, sticker_set_name)
}
pub fn delete_sticker_set(&self) -> DeleteChatStickerSet {
DeleteChatStickerSet::new(self.id)
}
pub fn edit_text_of(&self, message_id: i64, text: impl Into<String>) -> EditMessageText {
EditMessageText::new(self.id, message_id, text)
}
pub fn remove_caption_of(&self, message_id: i64) -> EditMessageCaption {
EditMessageCaption::new_empty(self.id, message_id)
}
pub fn edit_caption_of(
&self,
message_id: i64,
caption: impl Into<String>,
) -> EditMessageCaption {
EditMessageCaption::new(self.id, message_id, caption)
}
pub fn edit_media_of(&self, message_id: i64, media: impl Into<InputMedia>) -> EditMessageMedia {
EditMessageMedia::new(self.id, message_id, media)
}
pub fn remove_reply_markup_of(&self, message_id: i64) -> EditMessageReplyMarkup {
EditMessageReplyMarkup::new_empty(self.id, message_id)
}
pub fn edit_reply_markup_of(
&self,
message_id: i64,
reply_markup: impl Into<InlineKeyboardMarkup>,
) -> EditMessageReplyMarkup {
EditMessageReplyMarkup::new(self.id, message_id, reply_markup)
}
pub fn stop_poll(&self, message_id: i64) -> StopPoll {
StopPoll::new(self.id, message_id)
}
pub fn delete_message(&self, message_id: i64) -> DeleteMessage {
DeleteMessage::new(self.id, message_id)
}
}
#[derive(Debug, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "snake_case", tag = "type")]
pub enum ChatKind {
Private,
Group,
Supergroup,
Channel,
}
#[derive(Debug, Deserialize)]
pub struct ChatPhoto {
pub small_file_id: String,
pub small_file_unique_id: String,
pub big_file_id: String,
pub big_file_unique_id: String,
}
#[derive(Debug, Deserialize)]
pub struct ChatLocation {
pub location: Location,
pub address: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct ChatPermissions {
#[serde(skip_serializing_if = "Option::is_none")]
pub can_send_messages: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub can_send_media_messages: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub can_send_polls: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub can_send_other_messages: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub can_add_web_page_previews: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub can_change_info: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub can_invite_users: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub can_pin_messages: Option<bool>,
}
impl ChatPermissions {
pub fn new() -> Self {
Default::default()
}
pub fn allow_send_messages(self) -> Self {
Self {
can_send_messages: Some(true),
..self
}
}
pub fn allow_send_media_messages(self) -> Self {
Self {
can_send_media_messages: Some(true),
..self
}
}
pub fn allow_send_polls(self) -> Self {
Self {
can_send_polls: Some(true),
..self
}
}
pub fn allow_send_other_messages(self) -> Self {
Self {
can_send_other_messages: Some(true),
..self
}
}
pub fn allow_add_web_page_previews(self) -> Self {
Self {
can_add_web_page_previews: Some(true),
..self
}
}
pub fn allow_change_info(self) -> Self {
Self {
can_change_info: Some(true),
..self
}
}
pub fn allow_invite_users(self) -> Self {
Self {
can_invite_users: Some(true),
..self
}
}
pub fn allow_pin_messages(self) -> Self {
Self {
can_pin_messages: Some(true),
..self
}
}
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "snake_case", tag = "status")]
pub enum ChatMember {
#[serde(rename = "creator")]
Owner {
user: User,
is_anonymous: bool,
custom_title: Option<String>,
},
Administrator {
user: User,
can_be_edited: bool,
is_anonymous: bool,
can_manage_chat: bool,
can_delete_messages: bool,
can_manage_voice_chats: bool,
can_restrict_members: bool,
can_promote_members: bool,
can_change_info: bool,
can_invite_users: bool,
can_post_messages: Option<bool>,
can_edit_messages: Option<bool>,
can_pin_messages: Option<bool>,
custom_title: Option<String>,
},
Member {
user: User,
},
Restricted {
user: User,
is_member: bool,
can_change_info: bool,
can_invite_users: bool,
can_pin_messages: bool,
can_send_messages: bool,
can_send_media_messages: bool,
can_send_polls: bool,
can_send_other_messages: bool,
can_add_web_page_previews: bool,
until_date: u64,
},
Left {
user: User,
},
#[serde(rename = "kicked")]
Banned {
user: User,
until_date: u64,
},
}
impl ChatMember {
pub fn user(&self) -> &User {
match self {
ChatMember::Owner { user, .. }
| ChatMember::Administrator { user, .. }
| ChatMember::Member { user }
| ChatMember::Restricted { user, .. }
| ChatMember::Left { user }
| ChatMember::Banned { user, .. } => user,
}
}
pub fn is_anonymous(&self) -> Option<bool> {
match self {
ChatMember::Owner { is_anonymous, .. }
| ChatMember::Administrator { is_anonymous, .. } => Some(*is_anonymous),
_ => None,
}
}
pub fn custom_title(&self) -> Option<&str> {
match self {
Self::Owner { custom_title, .. } | Self::Administrator { custom_title, .. } => {
custom_title.as_deref()
}
_ => None,
}
}
pub fn can_be_edited(&self) -> Option<bool> {
match self {
Self::Administrator { can_be_edited, .. } => Some(*can_be_edited),
_ => None,
}
}
pub fn can_manage_chat(&self) -> Option<bool> {
match self {
Self::Administrator {
can_manage_chat, ..
} => Some(*can_manage_chat),
_ => None,
}
}
pub fn can_delete_messages(&self) -> Option<bool> {
match self {
Self::Administrator {
can_delete_messages,
..
} => Some(*can_delete_messages),
_ => None,
}
}
pub fn can_manage_voice_chats(&self) -> Option<bool> {
match self {
Self::Administrator {
can_manage_voice_chats,
..
} => Some(*can_manage_voice_chats),
_ => None,
}
}
pub fn can_restrict_members(&self) -> Option<bool> {
match self {
Self::Administrator {
can_restrict_members,
..
} => Some(*can_restrict_members),
_ => None,
}
}
pub fn can_promote_members(&self) -> Option<bool> {
match self {
Self::Administrator {
can_promote_members,
..
} => Some(*can_promote_members),
_ => None,
}
}
pub fn can_change_info(&self) -> Option<bool> {
match self {
Self::Administrator {
can_change_info, ..
}
| Self::Restricted {
can_change_info, ..
} => Some(*can_change_info),
_ => None,
}
}
pub fn can_invite_users(&self) -> Option<bool> {
match self {
Self::Administrator {
can_invite_users, ..
}
| Self::Restricted {
can_invite_users, ..
} => Some(*can_invite_users),
_ => None,
}
}
pub fn can_edit_messages(&self) -> Option<bool> {
match self {
Self::Administrator {
can_edit_messages, ..
} => *can_edit_messages,
_ => None,
}
}
pub fn can_pin_messages(&self) -> Option<bool> {
match self {
Self::Administrator {
can_pin_messages, ..
} => *can_pin_messages,
Self::Restricted {
can_pin_messages, ..
} => Some(*can_pin_messages),
_ => None,
}
}
pub fn can_post_messages(&self) -> Option<bool> {
match self {
Self::Administrator {
can_post_messages, ..
} => *can_post_messages,
_ => None,
}
}
pub fn can_send_messages(&self) -> Option<bool> {
match self {
Self::Restricted {
can_send_messages, ..
} => Some(*can_send_messages),
_ => None,
}
}
pub fn can_send_media_messages(&self) -> Option<bool> {
match self {
Self::Restricted {
can_send_media_messages,
..
} => Some(*can_send_media_messages),
_ => None,
}
}
pub fn can_send_polls(&self) -> Option<bool> {
match self {
Self::Restricted { can_send_polls, .. } => Some(*can_send_polls),
_ => None,
}
}
pub fn can_send_other_messages(&self) -> Option<bool> {
match self {
Self::Restricted {
can_send_other_messages,
..
} => Some(*can_send_other_messages),
_ => None,
}
}
pub fn can_add_web_page_previews(&self) -> Option<bool> {
match self {
Self::Restricted {
can_add_web_page_previews,
..
} => Some(*can_add_web_page_previews),
_ => None,
}
}
pub fn is_member(&self) -> bool {
match self {
Self::Owner { .. } | Self::Administrator { .. } | Self::Member { .. } => true,
Self::Restricted { is_member, .. } => *is_member,
ChatMember::Left { .. } | ChatMember::Banned { .. } => false,
}
}
pub fn banned_until(&self) -> Option<u64> {
match self {
Self::Banned { until_date, .. } => Some(*until_date),
_ => None,
}
}
pub fn restricted_until(&self) -> Option<u64> {
match self {
Self::Restricted { until_date, .. } => Some(*until_date),
_ => None,
}
}
}
#[derive(Debug, Deserialize)]
pub struct ChatInviteLink {
pub invite_link: String,
pub creator: User,
pub is_primary: bool,
pub is_revoked: bool,
pub expire_date: Option<u64>,
pub member_limit: Option<u32>,
}
#[derive(Debug, Deserialize)]
pub struct ChatMemberUpdated {
pub chat: Chat,
pub from: User,
pub date: u64,
pub old_chat_member: ChatMember,
pub new_chat_member: ChatMember,
pub invite_link: Option<ChatInviteLink>,
}
#[derive(Clone, Serialize)]
#[serde(untagged)]
pub enum ChatId {
Id(i64),
Username(String),
}
impl From<i64> for ChatId {
fn from(id: i64) -> Self {
Self::Id(id)
}
}
impl From<String> for ChatId {
fn from(username: String) -> Self {
Self::Username(username)
}
}
impl From<&str> for ChatId {
fn from(username: &str) -> Self {
Self::Username(username.to_string())
}
}
#[derive(Clone, Serialize)]
pub struct BanChatMember {
pub chat_id: ChatId,
pub user_id: i64,
#[serde(skip_serializing_if = "Option::is_none")]
pub until_date: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub revoke_messages: Option<bool>,
}
impl BanChatMember {
pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
Self {
chat_id: chat_id.into(),
user_id,
until_date: None,
revoke_messages: None,
}
}
pub fn until_date(self, date: u64) -> Self {
Self {
until_date: Some(date),
..self
}
}
pub fn revoke_messages(self) -> Self {
Self {
revoke_messages: Some(true),
..self
}
}
}
impl TelegramMethod for BanChatMember {
type Response = bool;
fn name() -> &'static str {
"banChatMember"
}
}
impl JsonMethod for BanChatMember {}
#[derive(Clone, Serialize)]
pub struct UnbanChatMember {
pub chat_id: ChatId,
pub user_id: i64,
#[serde(skip_serializing_if = "Option::is_none")]
pub only_if_banned: Option<bool>,
}
impl UnbanChatMember {
pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
Self {
chat_id: chat_id.into(),
user_id,
only_if_banned: None,
}
}
pub fn only_if_banned(self) -> Self {
Self {
only_if_banned: Some(true),
..self
}
}
}
impl TelegramMethod for UnbanChatMember {
type Response = bool;
fn name() -> &'static str {
"unbanChatMember"
}
}
impl JsonMethod for UnbanChatMember {}
#[derive(Clone, Serialize)]
pub struct RestrictChatMember {
pub chat_id: ChatId,
pub user_id: i64,
pub permissions: ChatPermissions,
#[serde(skip_serializing_if = "Option::is_none")]
pub until_date: Option<u64>,
}
impl RestrictChatMember {
pub fn new(chat_id: impl Into<ChatId>, user_id: i64, permissions: ChatPermissions) -> Self {
Self {
chat_id: chat_id.into(),
user_id,
permissions,
until_date: None,
}
}
pub fn until_date(self, date: u64) -> Self {
Self {
until_date: Some(date),
..self
}
}
}
impl TelegramMethod for RestrictChatMember {
type Response = bool;
fn name() -> &'static str {
"restrictChatMember"
}
}
impl JsonMethod for RestrictChatMember {}
#[derive(Clone, Serialize)]
pub struct PromoteChatMember {
pub chat_id: ChatId,
pub user_id: i64,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_anonymous: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub can_manage_chat: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub can_delete_messages: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub can_manage_voice_chats: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub can_restrict_members: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub can_promote_members: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub can_change_info: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub can_invite_users: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub can_post_messages: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub can_edit_messages: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub can_pin_messages: Option<bool>,
}
impl PromoteChatMember {
pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
Self {
chat_id: chat_id.into(),
user_id,
is_anonymous: None,
can_manage_chat: None,
can_delete_messages: None,
can_manage_voice_chats: None,
can_restrict_members: None,
can_promote_members: None,
can_change_info: None,
can_invite_users: None,
can_post_messages: None,
can_edit_messages: None,
can_pin_messages: None,
}
}
pub fn demote(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
Self {
chat_id: chat_id.into(),
user_id,
is_anonymous: Some(false),
can_manage_chat: Some(false),
can_delete_messages: Some(false),
can_manage_voice_chats: Some(false),
can_restrict_members: Some(false),
can_promote_members: Some(false),
can_change_info: Some(false),
can_invite_users: Some(false),
can_post_messages: Some(false),
can_edit_messages: Some(false),
can_pin_messages: Some(false),
}
}
pub fn anonymous(self) -> Self {
Self {
is_anonymous: Some(true),
..self
}
}
pub fn allow_manage_chat(self) -> Self {
Self {
can_manage_chat: Some(true),
..self
}
}
pub fn allow_delete_messages(self) -> Self {
Self {
can_delete_messages: Some(true),
..self
}
}
pub fn allow_manage_voice_chats(self) -> Self {
Self {
can_manage_voice_chats: Some(true),
..self
}
}
pub fn allow_restrict_members(self) -> Self {
Self {
can_restrict_members: Some(true),
..self
}
}
pub fn allow_promote_members(self) -> Self {
Self {
can_promote_members: Some(true),
..self
}
}
pub fn allow_change_info(self) -> Self {
Self {
can_change_info: Some(true),
..self
}
}
pub fn allow_invite_users(self) -> Self {
Self {
can_invite_users: Some(true),
..self
}
}
pub fn allow_post_messages(self) -> Self {
Self {
can_post_messages: Some(true),
..self
}
}
pub fn allow_edit_messages(self) -> Self {
Self {
can_edit_messages: Some(true),
..self
}
}
pub fn allow_pin_messages(self) -> Self {
Self {
can_pin_messages: Some(true),
..self
}
}
}
impl TelegramMethod for PromoteChatMember {
type Response = bool;
fn name() -> &'static str {
"promoteChatMember"
}
}
impl JsonMethod for PromoteChatMember {}
#[derive(Clone, Serialize)]
pub struct SetChatAdministratorCustomTitle {
pub chat_id: ChatId,
pub user_id: i64,
pub custom_title: String,
}
impl SetChatAdministratorCustomTitle {
pub fn new(chat_id: impl Into<ChatId>, user_id: i64, custom_title: impl Into<String>) -> Self {
Self {
chat_id: chat_id.into(),
user_id,
custom_title: custom_title.into(),
}
}
}
impl TelegramMethod for SetChatAdministratorCustomTitle {
type Response = bool;
fn name() -> &'static str {
"setChatAdministratorCustomTitle"
}
}
impl JsonMethod for SetChatAdministratorCustomTitle {}
#[derive(Clone, Serialize)]
pub struct SetChatPermissions {
pub chat_id: ChatId,
pub permissions: ChatPermissions,
}
impl SetChatPermissions {
pub fn new(chat_id: impl Into<ChatId>, permissions: ChatPermissions) -> Self {
Self {
chat_id: chat_id.into(),
permissions,
}
}
}
impl TelegramMethod for SetChatPermissions {
type Response = bool;
fn name() -> &'static str {
"setChatPermissions"
}
}
impl JsonMethod for SetChatPermissions {}
#[derive(Clone, Serialize)]
pub struct ExportChatInviteLink {
pub chat_id: ChatId,
}
impl ExportChatInviteLink {
pub fn new(chat_id: impl Into<ChatId>) -> Self {
Self {
chat_id: chat_id.into(),
}
}
}
impl TelegramMethod for ExportChatInviteLink {
type Response = String;
fn name() -> &'static str {
"exportChatInviteLink"
}
}
impl JsonMethod for ExportChatInviteLink {}
#[derive(Clone, Serialize)]
pub struct CreateChatInviteLink {
pub chat_id: ChatId,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub expire_date: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub member_limit: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub creates_join_request: Option<bool>,
}
impl CreateChatInviteLink {
pub fn new(chat_id: impl Into<ChatId>) -> Self {
Self {
chat_id: chat_id.into(),
name: None,
expire_date: None,
member_limit: None,
creates_join_request: None,
}
}
pub fn with_name(self, name: impl Into<String>) -> Self {
Self {
name: Some(name.into()),
..self
}
}
pub fn with_expire_date(self, expire_date: u64) -> Self {
Self {
expire_date: Some(expire_date),
..self
}
}
pub fn with_member_limit(self, member_limit: u32) -> Self {
Self {
member_limit: Some(member_limit),
..self
}
}
pub fn create_join_reqeuest(self) -> Self {
Self {
creates_join_request: Some(true),
..self
}
}
}
impl TelegramMethod for CreateChatInviteLink {
type Response = ChatInviteLink;
fn name() -> &'static str {
"createChatInviteLink"
}
}
impl JsonMethod for CreateChatInviteLink {}
#[derive(Clone, Serialize)]
pub struct EditChatInviteLink {
pub chat_id: ChatId,
pub invite_link: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub expire_date: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub member_limit: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub creates_join_request: Option<bool>,
}
impl EditChatInviteLink {
pub fn new(chat_id: impl Into<ChatId>, invite_link: impl Into<String>) -> Self {
Self {
chat_id: chat_id.into(),
invite_link: invite_link.into(),
name: None,
expire_date: None,
member_limit: None,
creates_join_request: None,
}
}
pub fn with_name(self, name: impl Into<String>) -> Self {
Self {
name: Some(name.into()),
..self
}
}
pub fn with_expire_date(self, expire_date: u64) -> Self {
Self {
expire_date: Some(expire_date),
..self
}
}
pub fn with_member_limit(self, member_limit: u32) -> Self {
Self {
member_limit: Some(member_limit),
..self
}
}
pub fn create_join_reqeuest(self) -> Self {
Self {
creates_join_request: Some(true),
..self
}
}
}
#[derive(Clone, Serialize)]
pub struct RevokeChatInviteLink {
pub chat_id: ChatId,
pub invite_link: String,
}
impl RevokeChatInviteLink {
pub fn new(chat_id: impl Into<ChatId>, invite_link: impl Into<String>) -> Self {
Self {
chat_id: chat_id.into(),
invite_link: invite_link.into(),
}
}
}
impl TelegramMethod for RevokeChatInviteLink {
type Response = ChatInviteLink;
fn name() -> &'static str {
"revokeChatInviteLink"
}
}
impl JsonMethod for RevokeChatInviteLink {}
#[derive(Clone, Serialize)]
pub struct ApproveChatJoinRequest {
pub chat_id: ChatId,
pub user_id: i64,
}
impl ApproveChatJoinRequest {
pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
Self {
chat_id: chat_id.into(),
user_id,
}
}
}
impl TelegramMethod for ApproveChatJoinRequest {
type Response = bool;
fn name() -> &'static str {
"approveChatJoinRequest"
}
}
impl JsonMethod for ApproveChatJoinRequest {}
#[derive(Clone, Serialize)]
pub struct DeclineChatJoinRequest {
pub chat_id: ChatId,
pub user_id: i64,
}
impl DeclineChatJoinRequest {
pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
Self {
chat_id: chat_id.into(),
user_id,
}
}
}
impl TelegramMethod for DeclineChatJoinRequest {
type Response = bool;
fn name() -> &'static str {
"declineChatJoinRequest"
}
}
impl JsonMethod for DeclineChatJoinRequest {}
#[derive(Clone, Serialize)]
pub struct SetChatPhoto {
pub chat_id: ChatId,
pub photo: InputFile,
}
impl SetChatPhoto {
pub fn new(chat_id: impl Into<ChatId>, photo: InputFile) -> Self {
Self {
chat_id: chat_id.into(),
photo,
}
}
}
impl TelegramMethod for SetChatPhoto {
type Response = bool;
fn name() -> &'static str {
"setChatPhoto"
}
}
impl JsonMethod for SetChatPhoto {}
#[derive(Clone, Serialize)]
pub struct DeleteChatPhoto {
pub chat_id: ChatId,
}
impl DeleteChatPhoto {
pub fn new(chat_id: impl Into<ChatId>) -> Self {
Self {
chat_id: chat_id.into(),
}
}
}
impl TelegramMethod for DeleteChatPhoto {
type Response = bool;
fn name() -> &'static str {
"deleteChatPhoto"
}
}
impl JsonMethod for DeleteChatPhoto {}
#[derive(Clone, Serialize)]
pub struct SetChatTitle {
pub chat_id: ChatId,
pub title: String,
}
impl SetChatTitle {
pub fn new(chat_id: impl Into<ChatId>, title: impl Into<String>) -> Self {
Self {
chat_id: chat_id.into(),
title: title.into(),
}
}
}
impl TelegramMethod for SetChatTitle {
type Response = bool;
fn name() -> &'static str {
"setChatTitle"
}
}
impl JsonMethod for SetChatTitle {}
#[derive(Clone, Serialize)]
pub struct SetChatDescription {
pub chat_id: ChatId,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
}
impl SetChatDescription {
pub fn new_empty(chat_id: impl Into<ChatId>) -> Self {
Self {
chat_id: chat_id.into(),
description: None,
}
}
pub fn new(chat_id: impl Into<ChatId>, description: impl Into<String>) -> Self {
Self {
chat_id: chat_id.into(),
description: Some(description.into()),
}
}
}
impl TelegramMethod for SetChatDescription {
type Response = bool;
fn name() -> &'static str {
"setChatDescription"
}
}
#[derive(Clone, Serialize)]
pub struct PinChatMessage {
pub chat_id: ChatId,
pub message_id: i64,
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_notification: Option<bool>,
}
impl PinChatMessage {
pub fn new(chat_id: impl Into<ChatId>, message_id: i64) -> Self {
Self {
chat_id: chat_id.into(),
message_id,
disable_notification: None,
}
}
pub fn disable_notification(self) -> Self {
Self {
disable_notification: Some(true),
..self
}
}
}
impl TelegramMethod for PinChatMessage {
type Response = bool;
fn name() -> &'static str {
"pinChatMessage"
}
}
impl JsonMethod for PinChatMessage {}
#[derive(Clone, Serialize)]
pub struct UnpinChatMessage {
pub chat_id: ChatId,
#[serde(skip_serializing_if = "Option::is_none")]
pub message_id: Option<i64>,
}
impl UnpinChatMessage {
pub fn new_recent(chat_id: impl Into<ChatId>) -> Self {
Self {
chat_id: chat_id.into(),
message_id: None,
}
}
pub fn new(chat_id: impl Into<ChatId>, message_id: i64) -> Self {
Self {
chat_id: chat_id.into(),
message_id: Some(message_id),
}
}
}
impl TelegramMethod for UnpinChatMessage {
type Response = bool;
fn name() -> &'static str {
"unpinChatMessage"
}
}
impl JsonMethod for UnpinChatMessage {}
#[derive(Clone, Serialize)]
pub struct UnpinAllChatMessages {
pub chat_id: ChatId,
}
impl UnpinAllChatMessages {
pub fn new(chat_id: impl Into<ChatId>) -> Self {
Self {
chat_id: chat_id.into(),
}
}
}
impl TelegramMethod for UnpinAllChatMessages {
type Response = bool;
fn name() -> &'static str {
"unpinAllChatMessages"
}
}
impl JsonMethod for UnpinAllChatMessages {}
#[derive(Clone, Serialize)]
pub struct LeaveChat {
pub chat_id: ChatId,
}
impl LeaveChat {
pub fn new(chat_id: impl Into<ChatId>) -> Self {
Self {
chat_id: chat_id.into(),
}
}
}
impl TelegramMethod for LeaveChat {
type Response = bool;
fn name() -> &'static str {
"leaveChat"
}
}
impl JsonMethod for LeaveChat {}
#[derive(Clone, Serialize)]
pub struct GetChat {
pub chat_id: ChatId,
}
impl GetChat {
pub fn new(chat_id: impl Into<ChatId>) -> Self {
Self {
chat_id: chat_id.into(),
}
}
}
impl TelegramMethod for GetChat {
type Response = Chat;
fn name() -> &'static str {
"getChat"
}
}
impl JsonMethod for GetChat {}
#[derive(Clone, Serialize)]
pub struct GetChatAdministrators {
pub chat_id: ChatId,
}
impl GetChatAdministrators {
pub fn new(chat_id: impl Into<ChatId>) -> Self {
Self {
chat_id: chat_id.into(),
}
}
}
impl TelegramMethod for GetChatAdministrators {
type Response = Vec<ChatMember>;
fn name() -> &'static str {
"getChatAdministrators"
}
}
impl JsonMethod for GetChatAdministrators {}
#[derive(Clone, Serialize)]
pub struct GetChatMemberCount {
pub chat_id: ChatId,
}
impl GetChatMemberCount {
pub fn new(chat_id: impl Into<ChatId>) -> Self {
Self {
chat_id: chat_id.into(),
}
}
}
impl TelegramMethod for GetChatMemberCount {
type Response = u32;
fn name() -> &'static str {
"getChatMemberCount"
}
}
impl JsonMethod for GetChatMemberCount {}
#[derive(Clone, Serialize)]
pub struct GetChatMember {
pub chat_id: ChatId,
pub user_id: i64,
}
impl GetChatMember {
pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
Self {
chat_id: chat_id.into(),
user_id,
}
}
}
impl TelegramMethod for GetChatMember {
type Response = ChatMember;
fn name() -> &'static str {
"getChatMember"
}
}
#[derive(Clone, Serialize)]
pub struct SetChatStickerSet {
pub chat_id: ChatId,
pub sticker_set_name: String,
}
impl SetChatStickerSet {
pub fn new(chat_id: impl Into<ChatId>, sticker_set_name: impl Into<String>) -> Self {
Self {
chat_id: chat_id.into(),
sticker_set_name: sticker_set_name.into(),
}
}
}
impl TelegramMethod for SetChatStickerSet {
type Response = bool;
fn name() -> &'static str {
"setChatStickerSet"
}
}
impl JsonMethod for SetChatStickerSet {}
#[derive(Clone, Serialize)]
pub struct DeleteChatStickerSet {
pub chat_id: ChatId,
}
impl DeleteChatStickerSet {
pub fn new(chat_id: impl Into<ChatId>) -> Self {
Self {
chat_id: chat_id.into(),
}
}
}
impl TelegramMethod for DeleteChatStickerSet {
type Response = bool;
fn name() -> &'static str {
"deleteChatStickerSet"
}
}
impl JsonMethod for DeleteChatStickerSet {}