use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use crate::chat::{Chat, ChatId, PinChatMessage, UnpinChatMessage};
use crate::file::{
Animation, Audio, Document, InputFile, InputFileVariant, InputMedia, PhotoSize, Video,
VideoNote, Voice,
};
use crate::markup::{InlineKeyboardMarkup, MessageEntity, ParseMode, ReplyMarkup};
use crate::payment::{Invoice, SuccessfulPayment};
use crate::sticker::Sticker;
use crate::user::User;
use crate::{FileMethod, JsonMethod, TelegramMethod};
#[derive(Debug, Deserialize)]
pub struct Message {
pub message_id: i64,
pub from: Option<User>,
pub sender_chat: Option<Chat>,
pub date: u64,
pub chat: Chat,
pub forward_from: Option<User>,
pub forward_from_chat: Option<Chat>,
pub forward_from_message_id: Option<i64>,
pub forward_signature: Option<String>,
pub forward_sender_name: Option<String>,
pub forward_date: Option<u64>,
pub reply_to_message: Option<Box<Message>>,
pub via_bot: Option<User>,
pub edit_date: Option<u64>,
pub media_group_id: Option<String>,
pub author_signature: Option<String>,
#[serde(flatten)]
pub kind: MessageKind,
pub reply_markup: Option<InlineKeyboardMarkup>,
}
impl Message {
pub fn reply_text(&self, text: impl Into<String>) -> SendMessage {
SendMessage::new(self.chat.id, text).reply_to(self.message_id)
}
pub fn forward_to(&self, chat_id: impl Into<ChatId>) -> ForwardMessage {
ForwardMessage::new(chat_id, self.chat.id, self.message_id)
}
pub fn copy_to(&self, chat_id: impl Into<ChatId>) -> CopyMessage {
CopyMessage::new(chat_id, self.chat.id, self.message_id)
}
pub fn pin(&self) -> PinChatMessage {
PinChatMessage::new(self.chat.id, self.message_id)
}
pub fn unpin(&self) -> UnpinChatMessage {
UnpinChatMessage::new(self.chat.id, self.message_id)
}
pub fn edit_text(&self, text: impl Into<String>) -> EditMessageText {
EditMessageText::new(self.chat.id, self.message_id, text)
}
pub fn remove_caption(&self) -> EditMessageCaption {
EditMessageCaption::new_empty(self.chat.id, self.message_id)
}
pub fn edit_caption(&self, caption: impl Into<String>) -> EditMessageCaption {
EditMessageCaption::new(self.chat.id, self.message_id, caption)
}
pub fn edit_media(&self, media: impl Into<InputMedia>) -> EditMessageMedia {
EditMessageMedia::new(self.chat.id, self.message_id, media)
}
pub fn remove_reply_markup(&self) -> EditMessageReplyMarkup {
EditMessageReplyMarkup::new_empty(self.chat.id, self.message_id)
}
pub fn edit_reply_markup(
&self,
reply_markup: impl Into<InlineKeyboardMarkup>,
) -> EditMessageReplyMarkup {
EditMessageReplyMarkup::new(self.chat.id, self.message_id, reply_markup)
}
pub fn stop_poll(&self) -> StopPoll {
StopPoll::new(self.chat.id, self.message_id)
}
pub fn delete(&self) -> DeleteMessage {
DeleteMessage::new(self.chat.id, self.message_id)
}
}
#[derive(Debug, Deserialize)]
#[serde(untagged)]
pub enum MessageKind {
Text {
text: String,
entities: Option<Vec<MessageEntity>>,
},
Animation {
animation: Animation,
document: Document,
caption: Option<String>,
caption_entities: Option<Vec<MessageEntity>>,
},
Audio {
audio: Audio,
caption: Option<String>,
caption_entities: Option<Vec<MessageEntity>>,
},
Document {
document: Document,
caption: Option<String>,
caption_entities: Option<Vec<MessageEntity>>,
},
Photo {
photo: Vec<PhotoSize>,
caption: Option<String>,
caption_entities: Option<Vec<MessageEntity>>,
},
Sticker {
sticker: Sticker,
},
Video {
video: Video,
caption: Option<String>,
caption_entities: Option<Vec<MessageEntity>>,
},
VideoNote {
video_note: VideoNote,
},
Voice {
voice: Voice,
caption: Option<String>,
caption_entities: Option<Vec<MessageEntity>>,
},
Contact {
contact: Contact,
},
Dice {
dice: Dice,
},
Game {
game: Game,
},
Poll {
poll: Poll,
},
Venue {
venue: Venue,
location: Location,
},
Location {
location: Location,
},
NewChatMembers {
new_chat_members: Vec<User>,
},
LeftChatMember {
left_chat_member: User,
},
NewChatTitle {
new_chat_title: String,
},
DeleteChatPhoto {
delete_chat_photo: bool,
},
GroupChatCreated {
group_chat_created: bool,
},
SupergroupChatCreated {
supergroup_chat_created: bool,
},
ChannelChatCreated {
channel_chat_created: bool,
},
MessageAutoDeleteTimerChanged {
message_auto_delete_timer_changed: MessageAutoDeleteTimerChanged,
},
GroupMigrated {
migrate_to_chat_id: i64,
migrate_from_chat_id: i64,
},
MessagePinned {
pinned_message: Box<Message>,
},
Invoice {
invoice: Invoice,
},
SuccessfulPayment {
successful_payment: SuccessfulPayment,
},
Login {
connected_website: String,
passport_data: PassportData,
},
ProximityAlertTriggered {
proximity_alert_triggered: ProximityAlertTriggered,
},
VoiceChatScheduled {
voice_chat_scheduled: VoiceChatScheduled,
},
VoiceChatStarted {
voice_chat_started: VoiceChatStarted,
},
VoiceChatEnded {
voice_chat_ended: VoiceChatEnded,
},
VoiceChatParticipantsInvited {
voice_chat_participants_invited: VoiceChatParticipantsInvited,
},
}
impl MessageKind {
pub fn text(&self) -> Option<&str> {
match self {
Self::Text { text, .. } => Some(text),
_ => None,
}
}
pub fn entities(&self) -> Option<&[MessageEntity]> {
match self {
Self::Text { entities, .. } => entities.as_deref(),
_ => None,
}
}
pub fn animation(&self) -> Option<&Animation> {
match self {
Self::Animation { animation, .. } => Some(animation),
_ => None,
}
}
pub fn document(&self) -> Option<&Document> {
match self {
Self::Animation { document, .. } | Self::Document { document, .. } => Some(document),
_ => None,
}
}
pub fn caption(&self) -> Option<&str> {
match self {
Self::Animation { caption, .. }
| Self::Audio { caption, .. }
| Self::Document { caption, .. }
| Self::Photo { caption, .. }
| Self::Video { caption, .. }
| Self::Voice { caption, .. } => caption.as_deref(),
_ => None,
}
}
pub fn caption_entities(&self) -> Option<&[MessageEntity]> {
match self {
Self::Animation {
caption_entities, ..
}
| Self::Audio {
caption_entities, ..
}
| Self::Document {
caption_entities, ..
}
| Self::Photo {
caption_entities, ..
}
| Self::Video {
caption_entities, ..
}
| Self::Voice {
caption_entities, ..
} => caption_entities.as_deref(),
_ => None,
}
}
pub fn audio(&self) -> Option<&Audio> {
match self {
Self::Audio { audio, .. } => Some(audio),
_ => None,
}
}
pub fn photo(&self) -> Option<&[PhotoSize]> {
match self {
Self::Photo { photo, .. } => Some(photo.as_ref()),
_ => None,
}
}
pub fn sticker(&self) -> Option<&Sticker> {
match self {
Self::Sticker { sticker } => Some(sticker),
_ => None,
}
}
pub fn video(&self) -> Option<&Video> {
match self {
Self::Video { video, .. } => Some(video),
_ => None,
}
}
pub fn video_note(&self) -> Option<&VideoNote> {
match self {
Self::VideoNote { video_note } => Some(video_note),
_ => None,
}
}
pub fn voice(&self) -> Option<&Voice> {
match self {
Self::Voice { voice, .. } => Some(voice),
_ => None,
}
}
pub fn contact(&self) -> Option<&Contact> {
match self {
Self::Contact { contact } => Some(contact),
_ => None,
}
}
pub fn dice(&self) -> Option<&Dice> {
match self {
Self::Dice { dice } => Some(dice),
_ => None,
}
}
pub fn game(&self) -> Option<&Game> {
match self {
Self::Game { game } => Some(game),
_ => None,
}
}
pub fn poll(&self) -> Option<&Poll> {
match self {
Self::Poll { poll } => Some(poll),
_ => None,
}
}
pub fn venue(&self) -> Option<&Venue> {
match self {
Self::Venue { venue, .. } => Some(venue),
_ => None,
}
}
pub fn location(&self) -> Option<&Location> {
match self {
Self::Venue { location, .. } | Self::Location { location } => Some(location),
_ => None,
}
}
pub fn new_chat_members(&self) -> Option<&[User]> {
match self {
Self::NewChatMembers { new_chat_members } => Some(new_chat_members.as_ref()),
_ => None,
}
}
pub fn left_chat_member(&self) -> Option<&User> {
match self {
Self::LeftChatMember { left_chat_member } => Some(left_chat_member),
_ => None,
}
}
pub fn new_chat_title(&self) -> Option<&str> {
match self {
Self::NewChatTitle { new_chat_title } => Some(new_chat_title),
_ => None,
}
}
pub fn message_auto_delete_timer_changed(&self) -> Option<&MessageAutoDeleteTimerChanged> {
match self {
Self::MessageAutoDeleteTimerChanged {
message_auto_delete_timer_changed,
} => Some(message_auto_delete_timer_changed),
_ => None,
}
}
pub fn migrate_to_chat_id(&self) -> Option<i64> {
match self {
Self::GroupMigrated {
migrate_to_chat_id, ..
} => Some(*migrate_to_chat_id),
_ => None,
}
}
pub fn migrate_from_chat_id(&self) -> Option<i64> {
match self {
Self::GroupMigrated {
migrate_from_chat_id,
..
} => Some(*migrate_from_chat_id),
_ => None,
}
}
pub fn pinned_message(&self) -> Option<&Message> {
match self {
Self::MessagePinned { pinned_message } => Some(pinned_message.as_ref()),
_ => None,
}
}
pub fn invoice(&self) -> Option<&Invoice> {
match self {
Self::Invoice { invoice } => Some(invoice),
_ => None,
}
}
pub fn successful_payment(&self) -> Option<&SuccessfulPayment> {
match self {
Self::SuccessfulPayment { successful_payment } => Some(successful_payment),
_ => None,
}
}
pub fn connected_website(&self) -> Option<&str> {
match self {
Self::Login {
connected_website, ..
} => Some(connected_website),
_ => None,
}
}
pub fn passport_data(&self) -> Option<&PassportData> {
match self {
Self::Login { passport_data, .. } => Some(passport_data),
_ => None,
}
}
pub fn proximity_alert_triggered(&self) -> Option<&ProximityAlertTriggered> {
match self {
Self::ProximityAlertTriggered {
proximity_alert_triggered,
} => Some(proximity_alert_triggered),
_ => None,
}
}
pub fn voice_chat_scheduled(&self) -> Option<&VoiceChatScheduled> {
match self {
Self::VoiceChatScheduled {
voice_chat_scheduled,
} => Some(voice_chat_scheduled),
_ => None,
}
}
pub fn voice_chat_started(&self) -> Option<&VoiceChatStarted> {
match self {
Self::VoiceChatStarted { voice_chat_started } => Some(voice_chat_started),
_ => None,
}
}
pub fn voice_chat_ended(&self) -> Option<&VoiceChatEnded> {
match self {
Self::VoiceChatEnded { voice_chat_ended } => Some(voice_chat_ended),
_ => None,
}
}
pub fn voice_chat_participants_invited(&self) -> Option<&VoiceChatParticipantsInvited> {
match self {
Self::VoiceChatParticipantsInvited {
voice_chat_participants_invited,
} => Some(voice_chat_participants_invited),
_ => None,
}
}
pub fn is_text(&self) -> bool {
matches!(self, Self::Text { .. })
}
pub fn is_animation(&self) -> bool {
matches!(self, Self::Animation { .. })
}
pub fn is_audio(&self) -> bool {
matches!(self, Self::Audio { .. })
}
pub fn is_document(&self) -> bool {
matches!(self, Self::Document { .. })
}
pub fn is_photo(&self) -> bool {
matches!(self, Self::Photo { .. })
}
pub fn is_sticker(&self) -> bool {
matches!(self, Self::Sticker { .. })
}
pub fn is_video(&self) -> bool {
matches!(self, Self::Video { .. })
}
pub fn is_video_note(&self) -> bool {
matches!(self, Self::VideoNote { .. })
}
pub fn is_voice(&self) -> bool {
matches!(self, Self::Voice { .. })
}
pub fn is_contact(&self) -> bool {
matches!(self, Self::Contact { .. })
}
pub fn is_dice(&self) -> bool {
matches!(self, Self::Dice { .. })
}
pub fn is_game(&self) -> bool {
matches!(self, Self::Game { .. })
}
pub fn is_poll(&self) -> bool {
matches!(self, Self::Poll { .. })
}
pub fn is_venue(&self) -> bool {
matches!(self, Self::Venue { .. })
}
pub fn is_location(&self) -> bool {
matches!(self, Self::Location { .. })
}
pub fn is_new_chat_members(&self) -> bool {
matches!(self, Self::NewChatMembers { .. })
}
pub fn is_left_chat_member(&self) -> bool {
matches!(self, Self::LeftChatMember { .. })
}
pub fn is_new_chat_title(&self) -> bool {
matches!(self, Self::NewChatTitle { .. })
}
pub fn is_delete_chat_photo(&self) -> bool {
matches!(self, Self::DeleteChatPhoto { .. })
}
pub fn is_group_chat_created(&self) -> bool {
matches!(self, Self::GroupChatCreated { .. })
}
pub fn is_supergroup_chat_created(&self) -> bool {
matches!(self, Self::SupergroupChatCreated { .. })
}
pub fn is_channel_chat_created(&self) -> bool {
matches!(self, Self::ChannelChatCreated { .. })
}
pub fn is_group_migrated(&self) -> bool {
matches!(self, Self::GroupMigrated { .. })
}
pub fn is_message_pinned(&self) -> bool {
matches!(self, Self::MessagePinned { .. })
}
pub fn is_invoice(&self) -> bool {
matches!(self, Self::Invoice { .. })
}
pub fn is_login(&self) -> bool {
matches!(self, Self::Login { .. })
}
pub fn is_proximity_alert_triggered(&self) -> bool {
matches!(self, Self::ProximityAlertTriggered { .. })
}
pub fn is_voice_chat_scheduled(&self) -> bool {
matches!(self, Self::VoiceChatScheduled { .. })
}
pub fn is_voice_chat_started(&self) -> bool {
matches!(self, Self::VoiceChatStarted { .. })
}
pub fn is_voice_chat_ended(&self) -> bool {
matches!(self, Self::VoiceChatEnded { .. })
}
pub fn is_voice_chat_participants_invited(&self) -> bool {
matches!(self, Self::VoiceChatParticipantsInvited { .. })
}
}
#[derive(Debug, Deserialize)]
pub struct MessageId {
pub message_id: i64,
}
#[derive(Debug, Deserialize)]
pub struct Location {
pub longitude: f32,
pub latitude: f32,
pub horizontal_accuracy: Option<f32>,
pub live_period: Option<i32>,
pub heading: Option<i32>,
pub proximity_alert_radius: Option<i32>,
}
#[derive(Debug, Deserialize)]
pub struct Contact {
pub phone_number: String,
pub first_name: String,
pub last_name: Option<String>,
pub user_id: Option<i64>,
pub vcard: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct Dice {
pub emoji: String,
pub value: i32,
}
#[derive(Debug, Deserialize)]
pub struct Game {}
#[derive(Debug, Deserialize)]
pub struct PollOption {
pub text: String,
pub voter_count: u32,
}
#[derive(Debug, Deserialize)]
pub struct PollAnswer {
pub poll_id: String,
pub user: User,
pub option_ids: Vec<u32>,
}
#[derive(Debug, Deserialize)]
pub struct Poll {
pub id: String,
pub question: String,
pub options: Vec<PollOption>,
pub total_voter_count: u32,
pub is_closed: bool,
pub is_anonymous: bool,
#[serde(flatten)]
pub kind: PollKind,
pub allows_multiple_answers: bool,
pub open_period: Option<u32>,
pub close_date: Option<u64>,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "snake_case", tag = "type")]
pub enum PollKind {
Regular,
Quiz {
correct_option_id: Option<usize>,
explanation: Option<String>,
explanation_entities: Option<Vec<MessageEntity>>,
},
}
impl PollKind {
pub fn correct_option_id(&self) -> Option<usize> {
match self {
Self::Quiz {
correct_option_id, ..
} => *correct_option_id,
_ => None,
}
}
pub fn explanation(&self) -> Option<&str> {
match self {
Self::Quiz { explanation, .. } => explanation.as_deref(),
_ => None,
}
}
pub fn explanation_entities(&self) -> Option<&[MessageEntity]> {
match self {
Self::Quiz {
explanation_entities,
..
} => explanation_entities.as_deref(),
_ => None,
}
}
pub fn is_regular(&self) -> bool {
matches!(self, Self::Regular)
}
pub fn is_quiz(&self) -> bool {
matches!(self, Self::Quiz { .. })
}
}
#[derive(Debug, Deserialize)]
pub struct Venue {
pub location: Location,
pub title: String,
pub address: String,
pub foursquare_id: Option<String>,
pub foursquare_type: Option<String>,
pub google_place_id: Option<String>,
pub google_place_type: String,
}
#[derive(Debug, Deserialize)]
pub struct MessageAutoDeleteTimerChanged {
pub message_auto_delete_time: u32,
}
#[derive(Debug, Deserialize)]
pub struct PassportData {}
#[derive(Debug, Deserialize)]
pub struct ProximityAlertTriggered {
pub traveler: User,
pub watcher: User,
pub distance: u32,
}
#[derive(Debug, Deserialize)]
pub struct VoiceChatScheduled {
pub start_date: u64,
}
#[derive(Debug, Deserialize)]
pub struct VoiceChatStarted;
#[derive(Debug, Deserialize)]
pub struct VoiceChatEnded {
pub duration: u32,
}
#[derive(Debug, Deserialize)]
pub struct VoiceChatParticipantsInvited {
pub users: Option<Vec<User>>,
}
#[derive(Clone, Serialize)]
pub struct SendMessage {
pub chat_id: ChatId,
pub text: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub parse_mode: Option<ParseMode>,
#[serde(skip_serializing_if = "Option::is_none")]
pub entities: Option<Vec<MessageEntity>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_web_page_preview: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_notification: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_to_message_id: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allow_sending_without_reply: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub protect_content: Option<bool>,
}
impl SendMessage {
pub fn new(chat_id: impl Into<ChatId>, text: impl Into<String>) -> Self {
Self {
chat_id: chat_id.into(),
text: text.into(),
parse_mode: None,
entities: None,
disable_web_page_preview: None,
disable_notification: None,
reply_to_message_id: None,
allow_sending_without_reply: None,
reply_markup: None,
protect_content: None,
}
}
pub fn with_parse_mode(self, parse_mode: ParseMode) -> Self {
Self {
parse_mode: Some(parse_mode),
..self
}
}
pub fn with_entities(self, entities: Vec<MessageEntity>) -> Self {
Self {
entities: Some(entities),
..self
}
}
pub fn with_entity(mut self, entity: MessageEntity) -> Self {
let entities = self.entities.get_or_insert_with(Default::default);
entities.push(entity);
self
}
pub fn disable_web_page_preview(self) -> Self {
Self {
disable_web_page_preview: Some(true),
..self
}
}
pub fn disable_notification(self) -> Self {
Self {
disable_notification: Some(true),
..self
}
}
pub fn reply_to(self, message_id: i64) -> Self {
Self {
reply_to_message_id: Some(message_id),
..self
}
}
pub fn allow_sending_without_reply(self) -> Self {
Self {
allow_sending_without_reply: Some(true),
..self
}
}
pub fn with_reply_markup(self, markup: impl Into<ReplyMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
pub fn protect_content(self) -> Self {
Self {
protect_content: Some(true),
..self
}
}
}
impl TelegramMethod for SendMessage {
type Response = Message;
fn name() -> &'static str {
"sendMessage"
}
}
impl JsonMethod for SendMessage {}
#[derive(Clone, Serialize)]
pub struct ForwardMessage {
pub chat_id: ChatId,
pub from_chat_id: ChatId,
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_notification: Option<bool>,
pub message_id: i64,
#[serde(skip_serializing_if = "Option::is_none")]
pub protect_content: Option<bool>,
}
impl ForwardMessage {
pub fn new(to: impl Into<ChatId>, from: impl Into<ChatId>, message: i64) -> Self {
Self {
chat_id: to.into(),
from_chat_id: from.into(),
disable_notification: None,
message_id: message,
protect_content: None,
}
}
pub fn disable_notification(self) -> Self {
Self {
disable_notification: Some(true),
..self
}
}
pub fn protect_content(self) -> Self {
Self {
protect_content: Some(true),
..self
}
}
}
impl TelegramMethod for ForwardMessage {
type Response = Message;
fn name() -> &'static str {
"forwardMessage"
}
}
impl JsonMethod for ForwardMessage {}
#[derive(Clone, Serialize)]
pub struct CopyMessage {
pub chat_id: ChatId,
pub from_chat_id: ChatId,
pub message_id: i64,
pub caption: Option<String>,
pub parse_mode: Option<ParseMode>,
pub caption_entities: Option<Vec<MessageEntity>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_notification: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_to_message_id: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allow_sending_without_reply: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub protect_content: Option<bool>,
}
impl CopyMessage {
pub fn new(to: impl Into<ChatId>, from: impl Into<ChatId>, message: i64) -> Self {
Self {
chat_id: to.into(),
from_chat_id: from.into(),
message_id: message,
caption: None,
parse_mode: None,
caption_entities: None,
disable_notification: None,
reply_to_message_id: None,
allow_sending_without_reply: None,
reply_markup: None,
protect_content: None,
}
}
pub fn with_caption(self, caption: impl Into<String>) -> Self {
Self {
caption: Some(caption.into()),
..self
}
}
pub fn with_parse_mode(self, parse_mode: ParseMode) -> Self {
Self {
parse_mode: Some(parse_mode),
..self
}
}
pub fn with_entities(self, entities: Vec<MessageEntity>) -> Self {
Self {
caption_entities: Some(entities),
..self
}
}
pub fn with_entity(mut self, entity: MessageEntity) -> Self {
let entities = self.caption_entities.get_or_insert_with(Default::default);
entities.push(entity);
self
}
pub fn disable_notification(self) -> Self {
Self {
disable_notification: Some(true),
..self
}
}
pub fn reply_to(self, message_id: i64) -> Self {
Self {
reply_to_message_id: Some(message_id),
..self
}
}
pub fn allow_sending_without_reply(self) -> Self {
Self {
allow_sending_without_reply: Some(true),
..self
}
}
pub fn with_reply_markup(self, markup: impl Into<ReplyMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
pub fn protect_content(self) -> Self {
Self {
protect_content: Some(true),
..self
}
}
}
impl TelegramMethod for CopyMessage {
type Response = MessageId;
fn name() -> &'static str {
"copyMessage"
}
}
impl JsonMethod for CopyMessage {}
#[derive(Clone, Serialize)]
pub struct SendPhoto {
pub chat_id: ChatId,
pub photo: InputFileVariant,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub parse_mode: Option<ParseMode>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption_entities: Option<Vec<MessageEntity>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_notification: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_to_message_id: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allow_sending_without_reply: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub protect_content: Option<bool>,
}
impl SendPhoto {
pub fn new(chat_id: impl Into<ChatId>, photo: impl Into<InputFileVariant>) -> Self {
Self {
chat_id: chat_id.into(),
photo: photo.into(),
caption: None,
parse_mode: None,
caption_entities: None,
disable_notification: None,
reply_to_message_id: None,
allow_sending_without_reply: None,
reply_markup: None,
protect_content: None,
}
}
pub fn with_caption(self, caption: impl Into<String>) -> Self {
Self {
caption: Some(caption.into()),
..self
}
}
pub fn with_parse_mode(self, parse_mode: ParseMode) -> Self {
Self {
parse_mode: Some(parse_mode),
..self
}
}
pub fn with_entities(self, entities: Vec<MessageEntity>) -> Self {
Self {
caption_entities: Some(entities),
..self
}
}
pub fn with_entity(mut self, entity: MessageEntity) -> Self {
let entities = self.caption_entities.get_or_insert_with(Default::default);
entities.push(entity);
self
}
pub fn disable_notification(self) -> Self {
Self {
disable_notification: Some(true),
..self
}
}
pub fn reply_to(self, message_id: i64) -> Self {
Self {
reply_to_message_id: Some(message_id),
..self
}
}
pub fn allow_sending_without_reply(self) -> Self {
Self {
allow_sending_without_reply: Some(true),
..self
}
}
pub fn with_reply_markup(self, markup: impl Into<ReplyMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
pub fn protect_content(self) -> Self {
Self {
protect_content: Some(true),
..self
}
}
}
impl TelegramMethod for SendPhoto {
type Response = Message;
fn name() -> &'static str {
"sendPhoto"
}
}
impl FileMethod for SendPhoto {
fn files(&self) -> Option<HashMap<&str, &InputFile>> {
if let InputFileVariant::File(file) = &self.photo {
let mut map = HashMap::new();
map.insert("photo", file);
Some(map)
} else {
None
}
}
}
#[derive(Clone, Serialize)]
pub struct SendAudio {
pub chat_id: ChatId,
pub audio: InputFileVariant,
#[serde(skip_serializing_if = "Option::is_none")]
pub duration: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub performer: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub title: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub thumb: Option<InputFileVariant>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub parse_mode: Option<ParseMode>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption_entities: Option<Vec<MessageEntity>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_notification: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_to_message_id: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allow_sending_without_reply: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub protect_content: Option<bool>,
}
impl SendAudio {
pub fn new(chat_id: impl Into<ChatId>, audio: impl Into<InputFileVariant>) -> Self {
Self {
chat_id: chat_id.into(),
audio: audio.into(),
duration: None,
performer: None,
title: None,
thumb: None,
caption: None,
parse_mode: None,
caption_entities: None,
disable_notification: None,
reply_to_message_id: None,
allow_sending_without_reply: None,
reply_markup: None,
protect_content: None,
}
}
pub fn with_duration(self, duration: u32) -> Self {
Self {
duration: Some(duration),
..self
}
}
pub fn with_performer(self, performer: impl Into<String>) -> Self {
Self {
performer: Some(performer.into()),
..self
}
}
pub fn with_title(self, title: impl Into<String>) -> Self {
Self {
title: Some(title.into()),
..self
}
}
pub fn with_thumbnail(self, thumbnail: impl Into<InputFileVariant>) -> Self {
Self {
thumb: Some(thumbnail.into()),
..self
}
}
pub fn with_caption(self, caption: impl Into<String>) -> Self {
Self {
caption: Some(caption.into()),
..self
}
}
pub fn with_parse_mode(self, parse_mode: ParseMode) -> Self {
Self {
parse_mode: Some(parse_mode),
..self
}
}
pub fn with_entities(self, entities: Vec<MessageEntity>) -> Self {
Self {
caption_entities: Some(entities),
..self
}
}
pub fn with_entity(mut self, entity: MessageEntity) -> Self {
let entities = self.caption_entities.get_or_insert_with(Default::default);
entities.push(entity);
self
}
pub fn disable_notification(self) -> Self {
Self {
disable_notification: Some(true),
..self
}
}
pub fn reply_to(self, message_id: i64) -> Self {
Self {
reply_to_message_id: Some(message_id),
..self
}
}
pub fn allow_sending_without_reply(self) -> Self {
Self {
allow_sending_without_reply: Some(true),
..self
}
}
pub fn with_reply_markup(self, markup: impl Into<ReplyMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
pub fn protect_content(self) -> Self {
Self {
protect_content: Some(true),
..self
}
}
}
impl TelegramMethod for SendAudio {
type Response = Message;
fn name() -> &'static str {
"sendAudio"
}
}
impl FileMethod for SendAudio {
fn files(&self) -> Option<HashMap<&str, &InputFile>> {
let mut map = HashMap::new();
if let InputFileVariant::File(file) = &self.audio {
map.insert("audio", file);
}
if let Some(InputFileVariant::File(file)) = &self.thumb {
map.insert("thumb", file);
}
if map.is_empty() {
None
} else {
Some(map)
}
}
}
#[derive(Clone, Serialize)]
pub struct SendDocument {
pub chat_id: ChatId,
pub document: InputFileVariant,
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_content_type_detection: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub thumb: Option<InputFileVariant>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub parse_mode: Option<ParseMode>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption_entities: Option<Vec<MessageEntity>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_notification: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_to_message_id: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allow_sending_without_reply: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub protect_content: Option<bool>,
}
impl SendDocument {
pub fn new(chat_id: impl Into<ChatId>, document: impl Into<InputFileVariant>) -> Self {
Self {
chat_id: chat_id.into(),
document: document.into(),
disable_content_type_detection: None,
thumb: None,
caption: None,
parse_mode: None,
caption_entities: None,
disable_notification: None,
reply_to_message_id: None,
allow_sending_without_reply: None,
reply_markup: None,
protect_content: None,
}
}
pub fn with_thumbnail(self, thumbnail: impl Into<InputFileVariant>) -> Self {
Self {
thumb: Some(thumbnail.into()),
..self
}
}
pub fn disable_content_type_detection(self) -> Self {
Self {
disable_content_type_detection: Some(true),
..self
}
}
pub fn with_caption(self, caption: impl Into<String>) -> Self {
Self {
caption: Some(caption.into()),
..self
}
}
pub fn with_parse_mode(self, parse_mode: ParseMode) -> Self {
Self {
parse_mode: Some(parse_mode),
..self
}
}
pub fn with_entities(self, entities: Vec<MessageEntity>) -> Self {
Self {
caption_entities: Some(entities),
..self
}
}
pub fn with_entity(mut self, entity: MessageEntity) -> Self {
let entities = self.caption_entities.get_or_insert_with(Default::default);
entities.push(entity);
self
}
pub fn disable_notification(self) -> Self {
Self {
disable_notification: Some(true),
..self
}
}
pub fn reply_to(self, message_id: i64) -> Self {
Self {
reply_to_message_id: Some(message_id),
..self
}
}
pub fn allow_sending_without_reply(self) -> Self {
Self {
allow_sending_without_reply: Some(true),
..self
}
}
pub fn with_reply_markup(self, markup: impl Into<ReplyMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
pub fn protect_content(self) -> Self {
Self {
protect_content: Some(true),
..self
}
}
}
impl TelegramMethod for SendDocument {
type Response = Message;
fn name() -> &'static str {
"sendDocument"
}
}
impl FileMethod for SendDocument {
fn files(&self) -> Option<HashMap<&str, &InputFile>> {
let mut map = HashMap::new();
if let InputFileVariant::File(file) = &self.document {
map.insert("document", file);
}
if let Some(InputFileVariant::File(file)) = &self.thumb {
map.insert("thumb", file);
}
if map.is_empty() {
None
} else {
Some(map)
}
}
}
#[derive(Clone, Serialize)]
pub struct SendVideo {
pub chat_id: ChatId,
pub video: InputFileVariant,
#[serde(skip_serializing_if = "Option::is_none")]
pub duration: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub width: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub height: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub supports_streaming: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub thumb: Option<InputFileVariant>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub parse_mode: Option<ParseMode>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption_entities: Option<Vec<MessageEntity>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_notification: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_to_message_id: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allow_sending_without_reply: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub protect_content: Option<bool>,
}
impl SendVideo {
pub fn new(chat_id: impl Into<ChatId>, video: impl Into<InputFileVariant>) -> Self {
Self {
chat_id: chat_id.into(),
video: video.into(),
duration: None,
width: None,
height: None,
supports_streaming: None,
thumb: None,
caption: None,
parse_mode: None,
caption_entities: None,
disable_notification: None,
reply_to_message_id: None,
allow_sending_without_reply: None,
reply_markup: None,
protect_content: None,
}
}
pub fn with_duration(self, duration: u32) -> Self {
Self {
duration: Some(duration),
..self
}
}
pub fn with_width(self, width: u32) -> Self {
Self {
width: Some(width),
..self
}
}
pub fn with_height(self, height: u32) -> Self {
Self {
height: Some(height),
..self
}
}
pub fn set_streaming(self) -> Self {
Self {
supports_streaming: Some(true),
..self
}
}
pub fn with_thumbnail(self, thumbnail: impl Into<InputFileVariant>) -> Self {
Self {
thumb: Some(thumbnail.into()),
..self
}
}
pub fn with_caption(self, caption: impl Into<String>) -> Self {
Self {
caption: Some(caption.into()),
..self
}
}
pub fn with_parse_mode(self, parse_mode: ParseMode) -> Self {
Self {
parse_mode: Some(parse_mode),
..self
}
}
pub fn with_entities(self, entities: Vec<MessageEntity>) -> Self {
Self {
caption_entities: Some(entities),
..self
}
}
pub fn with_entity(mut self, entity: MessageEntity) -> Self {
let entities = self.caption_entities.get_or_insert_with(Default::default);
entities.push(entity);
self
}
pub fn disable_notification(self) -> Self {
Self {
disable_notification: Some(true),
..self
}
}
pub fn reply_to(self, message_id: i64) -> Self {
Self {
reply_to_message_id: Some(message_id),
..self
}
}
pub fn allow_sending_without_reply(self) -> Self {
Self {
allow_sending_without_reply: Some(true),
..self
}
}
pub fn with_reply_markup(self, markup: impl Into<ReplyMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
pub fn protect_content(self) -> Self {
Self {
protect_content: Some(true),
..self
}
}
}
impl TelegramMethod for SendVideo {
type Response = Message;
fn name() -> &'static str {
"sendVideo"
}
}
impl FileMethod for SendVideo {
fn files(&self) -> Option<HashMap<&str, &InputFile>> {
let mut map = HashMap::new();
if let InputFileVariant::File(file) = &self.video {
map.insert("video", file);
}
if let Some(InputFileVariant::File(file)) = &self.thumb {
map.insert("thumb", file);
}
if map.is_empty() {
None
} else {
Some(map)
}
}
}
#[derive(Clone, Serialize)]
pub struct SendAnimation {
pub chat_id: ChatId,
pub animation: InputFileVariant,
#[serde(skip_serializing_if = "Option::is_none")]
pub duration: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub width: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub height: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub thumb: Option<InputFileVariant>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub parse_mode: Option<ParseMode>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption_entities: Option<Vec<MessageEntity>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_notification: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_to_message_id: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allow_sending_without_reply: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub protect_content: Option<bool>,
}
impl SendAnimation {
pub fn new(chat_id: impl Into<ChatId>, animation: impl Into<InputFileVariant>) -> Self {
Self {
chat_id: chat_id.into(),
animation: animation.into(),
duration: None,
width: None,
height: None,
thumb: None,
caption: None,
parse_mode: None,
caption_entities: None,
disable_notification: None,
reply_to_message_id: None,
allow_sending_without_reply: None,
reply_markup: None,
protect_content: None,
}
}
pub fn with_duration(self, duration: u32) -> Self {
Self {
duration: Some(duration),
..self
}
}
pub fn with_width(self, width: u32) -> Self {
Self {
width: Some(width),
..self
}
}
pub fn with_height(self, height: u32) -> Self {
Self {
height: Some(height),
..self
}
}
pub fn with_thumbnail(self, thumbnail: impl Into<InputFileVariant>) -> Self {
Self {
thumb: Some(thumbnail.into()),
..self
}
}
pub fn with_caption(self, caption: impl Into<String>) -> Self {
Self {
caption: Some(caption.into()),
..self
}
}
pub fn with_parse_mode(self, parse_mode: ParseMode) -> Self {
Self {
parse_mode: Some(parse_mode),
..self
}
}
pub fn with_entities(self, entities: Vec<MessageEntity>) -> Self {
Self {
caption_entities: Some(entities),
..self
}
}
pub fn with_entity(mut self, entity: MessageEntity) -> Self {
let entities = self.caption_entities.get_or_insert_with(Default::default);
entities.push(entity);
self
}
pub fn disable_notification(self) -> Self {
Self {
disable_notification: Some(true),
..self
}
}
pub fn reply_to(self, message_id: i64) -> Self {
Self {
reply_to_message_id: Some(message_id),
..self
}
}
pub fn allow_sending_without_reply(self) -> Self {
Self {
allow_sending_without_reply: Some(true),
..self
}
}
pub fn with_reply_markup(self, markup: impl Into<ReplyMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
pub fn protect_content(self) -> Self {
Self {
protect_content: Some(true),
..self
}
}
}
impl TelegramMethod for SendAnimation {
type Response = Message;
fn name() -> &'static str {
"sendAnimation"
}
}
impl FileMethod for SendAnimation {
fn files(&self) -> Option<HashMap<&str, &InputFile>> {
let mut map = HashMap::new();
if let InputFileVariant::File(file) = &self.animation {
map.insert("animation", file);
}
if let Some(InputFileVariant::File(file)) = &self.thumb {
map.insert("thumb", file);
}
if map.is_empty() {
None
} else {
Some(map)
}
}
}
#[derive(Clone, Serialize)]
pub struct SendVoice {
pub chat_id: ChatId,
pub voice: InputFileVariant,
#[serde(skip_serializing_if = "Option::is_none")]
pub duration: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub parse_mode: Option<ParseMode>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption_entities: Option<Vec<MessageEntity>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_notification: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_to_message_id: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allow_sending_without_reply: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub protect_content: Option<bool>,
}
impl SendVoice {
pub fn new(chat_id: impl Into<ChatId>, voice: impl Into<InputFileVariant>) -> Self {
Self {
chat_id: chat_id.into(),
voice: voice.into(),
duration: None,
caption: None,
parse_mode: None,
caption_entities: None,
disable_notification: None,
reply_to_message_id: None,
allow_sending_without_reply: None,
reply_markup: None,
protect_content: None,
}
}
pub fn with_duration(self, duration: u32) -> Self {
Self {
duration: Some(duration),
..self
}
}
pub fn with_caption(self, caption: impl Into<String>) -> Self {
Self {
caption: Some(caption.into()),
..self
}
}
pub fn with_parse_mode(self, parse_mode: ParseMode) -> Self {
Self {
parse_mode: Some(parse_mode),
..self
}
}
pub fn with_entities(self, entities: Vec<MessageEntity>) -> Self {
Self {
caption_entities: Some(entities),
..self
}
}
pub fn with_entity(mut self, entity: MessageEntity) -> Self {
let entities = self.caption_entities.get_or_insert_with(Default::default);
entities.push(entity);
self
}
pub fn disable_notification(self) -> Self {
Self {
disable_notification: Some(true),
..self
}
}
pub fn reply_to(self, message_id: i64) -> Self {
Self {
reply_to_message_id: Some(message_id),
..self
}
}
pub fn allow_sending_without_reply(self) -> Self {
Self {
allow_sending_without_reply: Some(true),
..self
}
}
pub fn with_reply_markup(self, markup: impl Into<ReplyMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
pub fn protect_content(self) -> Self {
Self {
protect_content: Some(true),
..self
}
}
}
impl TelegramMethod for SendVoice {
type Response = Message;
fn name() -> &'static str {
"sendVoice"
}
}
impl FileMethod for SendVoice {
fn files(&self) -> Option<HashMap<&str, &InputFile>> {
if let InputFileVariant::File(file) = &self.voice {
let mut map = HashMap::new();
map.insert("voice", file);
Some(map)
} else {
None
}
}
}
#[derive(Clone, Serialize)]
pub struct SendVideoNote {
pub chat_id: ChatId,
pub video_note: InputFileVariant,
#[serde(skip_serializing_if = "Option::is_none")]
pub duration: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub length: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub thumb: Option<InputFileVariant>,
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_notification: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_to_message_id: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allow_sending_without_reply: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub protect_content: Option<bool>,
}
impl SendVideoNote {
pub fn new(chat_id: impl Into<ChatId>, video_note: impl Into<InputFileVariant>) -> Self {
Self {
chat_id: chat_id.into(),
video_note: video_note.into(),
duration: None,
length: None,
thumb: None,
disable_notification: None,
reply_to_message_id: None,
allow_sending_without_reply: None,
reply_markup: None,
protect_content: None,
}
}
pub fn with_duration(self, duration: u32) -> Self {
Self {
duration: Some(duration),
..self
}
}
pub fn with_length(self, length: u32) -> Self {
Self {
length: Some(length),
..self
}
}
pub fn with_thumbnail(self, thumbnail: impl Into<InputFileVariant>) -> Self {
Self {
thumb: Some(thumbnail.into()),
..self
}
}
pub fn disable_notification(self) -> Self {
Self {
disable_notification: Some(true),
..self
}
}
pub fn reply_to(self, message_id: i64) -> Self {
Self {
reply_to_message_id: Some(message_id),
..self
}
}
pub fn allow_sending_without_reply(self) -> Self {
Self {
allow_sending_without_reply: Some(true),
..self
}
}
pub fn with_reply_markup(self, markup: impl Into<ReplyMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
pub fn protect_content(self) -> Self {
Self {
protect_content: Some(true),
..self
}
}
}
impl TelegramMethod for SendVideoNote {
type Response = Message;
fn name() -> &'static str {
"sendVideoNote"
}
}
impl FileMethod for SendVideoNote {
fn files(&self) -> Option<HashMap<&str, &InputFile>> {
let mut map = HashMap::new();
if let InputFileVariant::File(file) = &self.video_note {
map.insert("video_note", file);
}
if let Some(InputFileVariant::File(file)) = &self.thumb {
map.insert("thumb", file);
}
if map.is_empty() {
None
} else {
Some(map)
}
}
}
#[derive(Clone, Serialize)]
pub struct SendMediaGroup {
pub chat_id: ChatId,
pub media: Vec<InputMedia>,
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_notification: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_to_message_id: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allow_sending_without_reply: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub protect_content: Option<bool>,
}
impl SendMediaGroup {
pub fn new(chat_id: impl Into<ChatId>) -> Self {
Self {
chat_id: chat_id.into(),
media: vec![],
disable_notification: None,
reply_to_message_id: None,
allow_sending_without_reply: None,
protect_content: None,
}
}
pub fn with_media_group(self, media_group: Vec<InputMedia>) -> Self {
Self {
media: media_group,
..self
}
}
pub fn with_media(mut self, media: impl Into<InputMedia>) -> Self {
self.media.push(media.into());
self
}
pub fn disable_notification(self) -> Self {
Self {
disable_notification: Some(true),
..self
}
}
pub fn reply_to(self, message_id: i64) -> Self {
Self {
reply_to_message_id: Some(message_id),
..self
}
}
pub fn allow_sending_without_reply(self) -> Self {
Self {
allow_sending_without_reply: Some(true),
..self
}
}
pub fn protect_content(self) -> Self {
Self {
protect_content: Some(true),
..self
}
}
}
impl TelegramMethod for SendMediaGroup {
type Response = Vec<Message>;
fn name() -> &'static str {
"sendMediaGroup"
}
}
#[derive(Clone, Serialize)]
pub struct SendLocation {
pub chat_id: ChatId,
pub latitude: f32,
pub longitude: f32,
pub horizontal_accuracy: f32,
#[serde(skip_serializing_if = "Option::is_none")]
pub live_period: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub heading: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub proximity_alert_radius: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_notification: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_to_message_id: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allow_sending_without_reply: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub protect_content: Option<bool>,
}
impl SendLocation {
pub fn new(
chat_id: impl Into<ChatId>,
latitude: f32,
longitude: f32,
horizontal_accuracy: f32,
) -> Self {
Self {
chat_id: chat_id.into(),
latitude,
longitude,
horizontal_accuracy,
live_period: None,
heading: None,
proximity_alert_radius: None,
disable_notification: None,
reply_to_message_id: None,
allow_sending_without_reply: None,
reply_markup: None,
protect_content: None,
}
}
pub fn with_live_period(self, live_period: u32) -> Self {
Self {
live_period: Some(live_period),
..self
}
}
pub fn with_heading(self, direction: u32) -> Self {
Self {
heading: Some(direction),
..self
}
}
pub fn proximity_alert_within(self, radius: u32) -> Self {
Self {
proximity_alert_radius: Some(radius),
..self
}
}
pub fn disable_notification(self) -> Self {
Self {
disable_notification: Some(true),
..self
}
}
pub fn reply_to(self, message_id: i64) -> Self {
Self {
reply_to_message_id: Some(message_id),
..self
}
}
pub fn allow_sending_without_reply(self) -> Self {
Self {
allow_sending_without_reply: Some(true),
..self
}
}
pub fn with_reply_markup(self, markup: impl Into<ReplyMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
pub fn protect_content(self) -> Self {
Self {
protect_content: Some(true),
..self
}
}
}
impl TelegramMethod for SendLocation {
type Response = Message;
fn name() -> &'static str {
"sendLocation"
}
}
impl JsonMethod for SendLocation {}
#[derive(Clone, Serialize)]
pub struct EditMessageLiveLocation {
pub chat_id: ChatId,
pub message_id: i64,
pub latitude: f32,
pub longitude: f32,
pub horizontal_accuracy: Option<f32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub heading: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub proximity_alert_radius: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<InlineKeyboardMarkup>,
}
impl EditMessageLiveLocation {
pub fn new(chat_id: impl Into<ChatId>, message_id: i64, latitude: f32, longitude: f32) -> Self {
Self {
chat_id: chat_id.into(),
message_id,
latitude,
longitude,
horizontal_accuracy: None,
heading: None,
proximity_alert_radius: None,
reply_markup: None,
}
}
pub fn with_horizontal_accuracy(self, accuracy: f32) -> Self {
Self {
horizontal_accuracy: Some(accuracy),
..self
}
}
pub fn with_heading(self, direction: u32) -> Self {
Self {
heading: Some(direction),
..self
}
}
pub fn proximity_alert_within(self, radius: u32) -> Self {
Self {
proximity_alert_radius: Some(radius),
..self
}
}
pub fn with_reply_markup(self, markup: impl Into<InlineKeyboardMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
}
impl TelegramMethod for EditMessageLiveLocation {
type Response = Message;
fn name() -> &'static str {
"editMessageLiveLocation"
}
}
impl JsonMethod for EditMessageLiveLocation {}
#[derive(Clone, Serialize)]
pub struct EditInlineMessageLiveLocation {
pub inline_message_id: String,
pub latitude: f32,
pub longitude: f32,
pub horizontal_accuracy: Option<f32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub heading: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub proximity_alert_radius: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<InlineKeyboardMarkup>,
}
impl EditInlineMessageLiveLocation {
pub fn new(inline_message_id: impl Into<String>, latitude: f32, longitude: f32) -> Self {
Self {
inline_message_id: inline_message_id.into(),
latitude,
longitude,
horizontal_accuracy: None,
heading: None,
proximity_alert_radius: None,
reply_markup: None,
}
}
pub fn with_horizontal_accuracy(self, accuracy: f32) -> Self {
Self {
horizontal_accuracy: Some(accuracy),
..self
}
}
pub fn with_heading(self, direction: u32) -> Self {
Self {
heading: Some(direction),
..self
}
}
pub fn proximity_alert_within(self, radius: u32) -> Self {
Self {
proximity_alert_radius: Some(radius),
..self
}
}
pub fn with_reply_markup(self, markup: impl Into<InlineKeyboardMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
}
impl TelegramMethod for EditInlineMessageLiveLocation {
type Response = bool;
fn name() -> &'static str {
"editMessageLiveLocation"
}
}
impl JsonMethod for EditInlineMessageLiveLocation {}
#[derive(Clone, Serialize)]
pub struct StopMessageLiveLocation {
pub chat_id: ChatId,
pub message_id: i64,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<InlineKeyboardMarkup>,
}
impl StopMessageLiveLocation {
pub fn from_chat(chat_id: impl Into<ChatId>, message_id: i64) -> Self {
Self {
chat_id: chat_id.into(),
message_id,
reply_markup: None,
}
}
pub fn with_reply_markup(self, markup: impl Into<InlineKeyboardMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
}
impl TelegramMethod for StopMessageLiveLocation {
type Response = Message;
fn name() -> &'static str {
"stopMessageLiveLocation"
}
}
impl JsonMethod for StopMessageLiveLocation {}
#[derive(Clone, Serialize)]
pub struct StopInlineMessageLiveLocation {
pub inline_message_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<InlineKeyboardMarkup>,
}
impl StopInlineMessageLiveLocation {
pub fn new(inline_message_id: impl Into<String>) -> Self {
Self {
inline_message_id: inline_message_id.into(),
reply_markup: None,
}
}
pub fn with_reply_markup(self, markup: impl Into<InlineKeyboardMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
}
impl TelegramMethod for StopInlineMessageLiveLocation {
type Response = bool;
fn name() -> &'static str {
"stopMessageLiveLocation"
}
}
impl JsonMethod for StopInlineMessageLiveLocation {}
#[derive(Clone, Serialize)]
pub struct SendVenue {
pub chat_id: ChatId,
pub latitude: f32,
pub longitude: f32,
pub title: String,
pub address: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub foursquare_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub foursquare_type: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub google_place_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub google_place_type: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_notification: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_to_message_id: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allow_sending_without_reply: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub protect_content: Option<bool>,
}
impl SendVenue {
pub fn new(
chat_id: impl Into<ChatId>,
latitude: f32,
longitude: f32,
title: impl Into<String>,
address: impl Into<String>,
) -> Self {
Self {
chat_id: chat_id.into(),
latitude,
longitude,
title: title.into(),
address: address.into(),
foursquare_id: None,
foursquare_type: None,
google_place_id: None,
google_place_type: None,
disable_notification: None,
reply_to_message_id: None,
allow_sending_without_reply: None,
reply_markup: None,
protect_content: None,
}
}
pub fn with_foursqaure(self, id: impl Into<String>, kind: Option<String>) -> Self {
Self {
foursquare_id: Some(id.into()),
foursquare_type: kind,
..self
}
}
pub fn with_google_place(self, id: impl Into<String>, kind: Option<String>) -> Self {
Self {
google_place_id: Some(id.into()),
google_place_type: kind,
..self
}
}
pub fn disable_notification(self) -> Self {
Self {
disable_notification: Some(true),
..self
}
}
pub fn reply_to(self, message_id: i64) -> Self {
Self {
reply_to_message_id: Some(message_id),
..self
}
}
pub fn allow_sending_without_reply(self) -> Self {
Self {
allow_sending_without_reply: Some(true),
..self
}
}
pub fn with_reply_markup(self, markup: impl Into<ReplyMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
pub fn protect_content(self) -> Self {
Self {
protect_content: Some(true),
..self
}
}
}
impl TelegramMethod for SendVenue {
type Response = Message;
fn name() -> &'static str {
"sendVenue"
}
}
impl JsonMethod for SendVenue {}
#[derive(Clone, Serialize)]
pub struct SendContact {
pub chat_id: ChatId,
pub phone_number: String,
pub first_name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub last_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub vcard: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_notification: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_to_message_id: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allow_sending_without_reply: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub protect_content: Option<bool>,
}
impl SendContact {
pub fn new(
chat_id: impl Into<ChatId>,
phone_number: impl Into<String>,
first_name: impl Into<String>,
) -> Self {
Self {
chat_id: chat_id.into(),
phone_number: phone_number.into(),
first_name: first_name.into(),
last_name: None,
vcard: None,
disable_notification: None,
reply_to_message_id: None,
allow_sending_without_reply: None,
reply_markup: None,
protect_content: None,
}
}
pub fn with_last_name(self, last_name: impl Into<String>) -> Self {
Self {
last_name: Some(last_name.into()),
..self
}
}
pub fn with_vcard(self, vcard: impl Into<String>) -> Self {
Self {
vcard: Some(vcard.into()),
..self
}
}
pub fn disable_notification(self) -> Self {
Self {
disable_notification: Some(true),
..self
}
}
pub fn reply_to(self, message_id: i64) -> Self {
Self {
reply_to_message_id: Some(message_id),
..self
}
}
pub fn allow_sending_without_reply(self) -> Self {
Self {
allow_sending_without_reply: Some(true),
..self
}
}
pub fn with_reply_markup(self, markup: impl Into<ReplyMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
pub fn protect_content(self) -> Self {
Self {
protect_content: Some(true),
..self
}
}
}
impl TelegramMethod for SendContact {
type Response = Message;
fn name() -> &'static str {
"sendContact"
}
}
impl JsonMethod for SendContact {}
#[derive(Clone, Serialize)]
pub struct SendPoll {
pub chat_id: ChatId,
pub question: String,
pub options: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_anonymous: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "type")]
pub kind: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allows_multiple_answers: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub correct_option_id: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub explanation: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub explanation_parse_mode: Option<ParseMode>,
#[serde(skip_serializing_if = "Option::is_none")]
pub explanation_entities: Option<Vec<MessageEntity>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub open_period: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub close_date: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_closed: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_notification: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_to_message_id: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allow_sending_without_reply: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub protect_content: Option<bool>,
}
impl SendPoll {
pub fn new_regular(
chat_id: impl Into<ChatId>,
question: impl Into<String>,
options: Vec<String>,
) -> Self {
Self {
chat_id: chat_id.into(),
question: question.into(),
options,
is_anonymous: None,
kind: Some("quiz".into()),
allows_multiple_answers: None,
correct_option_id: None,
explanation: None,
explanation_parse_mode: None,
explanation_entities: None,
open_period: None,
close_date: None,
is_closed: None,
disable_notification: None,
reply_to_message_id: None,
allow_sending_without_reply: None,
reply_markup: None,
protect_content: None,
}
}
pub fn new_quiz(
chat_id: impl Into<ChatId>,
question: impl Into<String>,
options: Vec<String>,
correct_option_id: u32,
) -> Self {
Self {
chat_id: chat_id.into(),
question: question.into(),
options,
is_anonymous: None,
kind: Some("quiz".into()),
allows_multiple_answers: None,
correct_option_id: Some(correct_option_id),
explanation: None,
explanation_parse_mode: None,
explanation_entities: None,
open_period: None,
close_date: None,
is_closed: None,
disable_notification: None,
reply_to_message_id: None,
allow_sending_without_reply: None,
reply_markup: None,
protect_content: None,
}
}
pub fn anonymous(self) -> Self {
Self {
is_anonymous: Some(true),
..self
}
}
pub fn allow_multiple_answers(self) -> Self {
Self {
allows_multiple_answers: Some(true),
..self
}
}
pub fn with_explanation(self, explanation: impl Into<String>) -> Self {
Self {
explanation: Some(explanation.into()),
..self
}
}
pub fn with_parse_mode(self, parse_mode: ParseMode) -> Self {
Self {
explanation_parse_mode: Some(parse_mode),
..self
}
}
pub fn with_entities(self, entities: Vec<MessageEntity>) -> Self {
Self {
explanation_entities: Some(entities),
..self
}
}
pub fn with_entity(mut self, entity: MessageEntity) -> Self {
let entities = self
.explanation_entities
.get_or_insert_with(Default::default);
entities.push(entity);
self
}
pub fn with_open_period(self, period: u32) -> Self {
Self {
open_period: Some(period),
close_date: None,
..self
}
}
pub fn with_close_date(self, close_date: u64) -> Self {
Self {
close_date: Some(close_date),
open_period: None,
..self
}
}
pub fn closed(self) -> Self {
Self {
is_closed: Some(true),
..self
}
}
pub fn disable_notification(self) -> Self {
Self {
disable_notification: Some(true),
..self
}
}
pub fn reply_to(self, message_id: i64) -> Self {
Self {
reply_to_message_id: Some(message_id),
..self
}
}
pub fn allow_sending_without_reply(self) -> Self {
Self {
allow_sending_without_reply: Some(true),
..self
}
}
pub fn with_reply_markup(self, markup: impl Into<ReplyMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
pub fn protect_content(self) -> Self {
Self {
protect_content: Some(true),
..self
}
}
}
impl TelegramMethod for SendPoll {
type Response = Message;
fn name() -> &'static str {
"sendPoll"
}
}
impl JsonMethod for SendPoll {}
#[derive(Clone, Serialize)]
pub struct SendDice {
pub chat_id: ChatId,
#[serde(skip_serializing_if = "Option::is_none")]
pub emoji: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_notification: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_to_message_id: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allow_sending_without_reply: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub protect_content: Option<bool>,
}
impl SendDice {
pub fn new(chat_id: impl Into<ChatId>) -> Self {
Self {
chat_id: chat_id.into(),
emoji: None,
disable_notification: None,
reply_to_message_id: None,
allow_sending_without_reply: None,
reply_markup: None,
protect_content: None,
}
}
pub fn with_emoji(self, emoji: impl Into<String>) -> Self {
Self {
emoji: Some(emoji.into()),
..self
}
}
pub fn disable_notification(self) -> Self {
Self {
disable_notification: Some(true),
..self
}
}
pub fn reply_to(self, message_id: i64) -> Self {
Self {
reply_to_message_id: Some(message_id),
..self
}
}
pub fn allow_sending_without_reply(self) -> Self {
Self {
allow_sending_without_reply: Some(true),
..self
}
}
pub fn with_reply_markup(self, markup: impl Into<ReplyMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
pub fn protect_content(self) -> Self {
Self {
protect_content: Some(true),
..self
}
}
}
impl TelegramMethod for SendDice {
type Response = Message;
fn name() -> &'static str {
"sendDice"
}
}
impl JsonMethod for SendDice {}
#[derive(Clone, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum ChatActionKind {
Typing,
UploadPhoto,
RecordVideo,
UploadVideo,
RecordVoice,
UploadVoice,
UplaodDocument,
FindLocation,
RecordVideoNote,
UploadVideoNote,
}
#[derive(Clone, Serialize)]
pub struct SendChatAction {
pub chat_id: ChatId,
pub action: ChatActionKind,
}
impl SendChatAction {
pub fn new(chat_id: impl Into<ChatId>, action: ChatActionKind) -> Self {
Self {
chat_id: chat_id.into(),
action,
}
}
}
impl TelegramMethod for SendChatAction {
type Response = Message;
fn name() -> &'static str {
"sendChatAction"
}
}
impl JsonMethod for SendChatAction {}
#[derive(Clone, Serialize)]
pub struct EditMessageText {
pub chat_id: ChatId,
pub message_id: i64,
pub text: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub parse_mode: Option<ParseMode>,
#[serde(skip_serializing_if = "Option::is_none")]
pub entities: Option<Vec<MessageEntity>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_web_page_preview: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<InlineKeyboardMarkup>,
}
impl EditMessageText {
pub fn new(chat_id: impl Into<ChatId>, message_id: i64, text: impl Into<String>) -> Self {
Self {
chat_id: chat_id.into(),
message_id,
text: text.into(),
parse_mode: None,
entities: None,
disable_web_page_preview: None,
reply_markup: None,
}
}
pub fn with_parse_mode(self, parse_mode: ParseMode) -> Self {
Self {
parse_mode: Some(parse_mode),
..self
}
}
pub fn with_entities(self, entities: Vec<MessageEntity>) -> Self {
Self {
entities: Some(entities),
..self
}
}
pub fn with_entity(mut self, entity: MessageEntity) -> Self {
let entities = self.entities.get_or_insert_with(Default::default);
entities.push(entity);
self
}
pub fn disable_web_page_preview(self) -> Self {
Self {
disable_web_page_preview: Some(true),
..self
}
}
pub fn with_reply_markup(self, markup: impl Into<InlineKeyboardMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
}
impl TelegramMethod for EditMessageText {
type Response = Message;
fn name() -> &'static str {
"editMessageText"
}
}
impl JsonMethod for EditMessageText {}
#[derive(Clone, Serialize)]
pub struct EditInlineMessageText {
pub inline_message_id: String,
pub text: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub parse_mode: Option<ParseMode>,
#[serde(skip_serializing_if = "Option::is_none")]
pub entities: Option<Vec<MessageEntity>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_web_page_preview: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<InlineKeyboardMarkup>,
}
impl EditInlineMessageText {
pub fn new(inline_message_id: impl Into<String>, text: impl Into<String>) -> Self {
Self {
inline_message_id: inline_message_id.into(),
text: text.into(),
parse_mode: None,
entities: None,
disable_web_page_preview: None,
reply_markup: None,
}
}
pub fn with_parse_mode(self, parse_mode: ParseMode) -> Self {
Self {
parse_mode: Some(parse_mode),
..self
}
}
pub fn with_entities(self, entities: Vec<MessageEntity>) -> Self {
Self {
entities: Some(entities),
..self
}
}
pub fn with_entity(mut self, entity: MessageEntity) -> Self {
let entities = self.entities.get_or_insert_with(Default::default);
entities.push(entity);
self
}
pub fn disable_web_page_preview(self) -> Self {
Self {
disable_web_page_preview: Some(true),
..self
}
}
pub fn with_reply_markup(self, markup: impl Into<InlineKeyboardMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
}
impl TelegramMethod for EditInlineMessageText {
type Response = bool;
fn name() -> &'static str {
"editMessageText"
}
}
impl JsonMethod for EditInlineMessageText {}
#[derive(Clone, Serialize)]
pub struct EditMessageCaption {
pub chat_id: ChatId,
pub message_id: i64,
pub caption: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption_entities: Option<Vec<MessageEntity>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub parse_mode: Option<ParseMode>,
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_web_page_preview: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<InlineKeyboardMarkup>,
}
impl EditMessageCaption {
pub fn new_empty(chat_id: impl Into<ChatId>, message_id: i64) -> Self {
Self {
chat_id: chat_id.into(),
message_id,
caption: None,
parse_mode: None,
caption_entities: None,
disable_web_page_preview: None,
reply_markup: None,
}
}
pub fn new(chat_id: impl Into<ChatId>, message_id: i64, caption: impl Into<String>) -> Self {
Self {
chat_id: chat_id.into(),
message_id,
caption: Some(caption.into()),
parse_mode: None,
caption_entities: None,
disable_web_page_preview: None,
reply_markup: None,
}
}
pub fn with_parse_mode(self, parse_mode: ParseMode) -> Self {
Self {
parse_mode: Some(parse_mode),
..self
}
}
pub fn with_entities(self, entities: Vec<MessageEntity>) -> Self {
Self {
caption_entities: Some(entities),
..self
}
}
pub fn with_entity(mut self, entity: MessageEntity) -> Self {
let entities = self.caption_entities.get_or_insert_with(Default::default);
entities.push(entity);
self
}
pub fn disable_web_page_preview(self) -> Self {
Self {
disable_web_page_preview: Some(true),
..self
}
}
pub fn with_reply_markup(self, markup: impl Into<InlineKeyboardMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
}
impl TelegramMethod for EditMessageCaption {
type Response = Message;
fn name() -> &'static str {
"editMessageCaption"
}
}
impl JsonMethod for EditMessageCaption {}
#[derive(Clone, Serialize)]
pub struct EditInlineMessageCaption {
pub inline_message_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption_entities: Option<Vec<MessageEntity>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub parse_mode: Option<ParseMode>,
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_web_page_preview: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<InlineKeyboardMarkup>,
}
impl EditInlineMessageCaption {
pub fn new_empty(inline_message_id: impl Into<String>) -> Self {
Self {
inline_message_id: inline_message_id.into(),
caption: None,
parse_mode: None,
caption_entities: None,
disable_web_page_preview: None,
reply_markup: None,
}
}
pub fn new(inline_message_id: impl Into<String>, caption: impl Into<String>) -> Self {
Self {
inline_message_id: inline_message_id.into(),
caption: Some(caption.into()),
parse_mode: None,
caption_entities: None,
disable_web_page_preview: None,
reply_markup: None,
}
}
pub fn with_parse_mode(self, parse_mode: ParseMode) -> Self {
Self {
parse_mode: Some(parse_mode),
..self
}
}
pub fn with_entities(self, entities: Vec<MessageEntity>) -> Self {
Self {
caption_entities: Some(entities),
..self
}
}
pub fn with_entity(mut self, entity: MessageEntity) -> Self {
let entities = self.caption_entities.get_or_insert_with(Default::default);
entities.push(entity);
self
}
pub fn disable_web_page_preview(self) -> Self {
Self {
disable_web_page_preview: Some(true),
..self
}
}
pub fn with_reply_markup(self, markup: impl Into<InlineKeyboardMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
}
impl TelegramMethod for EditInlineMessageCaption {
type Response = bool;
fn name() -> &'static str {
"editMessageCaption"
}
}
impl JsonMethod for EditInlineMessageCaption {}
#[derive(Clone, Serialize)]
pub struct EditMessageMedia {
pub chat_id: ChatId,
pub message_id: i64,
pub media: InputMedia,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<InlineKeyboardMarkup>,
}
impl EditMessageMedia {
pub fn new(chat_id: impl Into<ChatId>, message_id: i64, media: impl Into<InputMedia>) -> Self {
Self {
chat_id: chat_id.into(),
message_id,
media: media.into(),
reply_markup: None,
}
}
pub fn with_reply_markup(self, markup: impl Into<InlineKeyboardMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
}
impl TelegramMethod for EditMessageMedia {
type Response = Message;
fn name() -> &'static str {
"editMessageMedia"
}
}
impl JsonMethod for EditMessageMedia {}
#[derive(Clone, Serialize)]
pub struct EditInlineMessageMedia {
pub inline_message_id: String,
pub media: InputMedia,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<InlineKeyboardMarkup>,
}
impl EditInlineMessageMedia {
pub fn new(inline_message_id: impl Into<String>, media: impl Into<InputMedia>) -> Self {
Self {
inline_message_id: inline_message_id.into(),
media: media.into(),
reply_markup: None,
}
}
pub fn with_reply_markup(self, markup: impl Into<InlineKeyboardMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
}
impl TelegramMethod for EditInlineMessageMedia {
type Response = bool;
fn name() -> &'static str {
"editMessageMedia"
}
}
impl JsonMethod for EditInlineMessageMedia {}
#[derive(Clone, Serialize)]
pub struct EditMessageReplyMarkup {
pub chat_id: ChatId,
pub message_id: i64,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<InlineKeyboardMarkup>,
}
impl EditMessageReplyMarkup {
pub fn new_empty(chat_id: impl Into<ChatId>, message_id: i64) -> Self {
Self {
chat_id: chat_id.into(),
message_id,
reply_markup: None,
}
}
pub fn new(
chat_id: impl Into<ChatId>,
message_id: i64,
reply_markup: impl Into<InlineKeyboardMarkup>,
) -> Self {
Self {
chat_id: chat_id.into(),
message_id,
reply_markup: Some(reply_markup.into()),
}
}
}
impl TelegramMethod for EditMessageReplyMarkup {
type Response = Message;
fn name() -> &'static str {
"editMessageReplyMarkup"
}
}
impl JsonMethod for EditMessageReplyMarkup {}
#[derive(Clone, Serialize)]
pub struct EditInlineMessageReplyMarkup {
pub inline_message_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<InlineKeyboardMarkup>,
}
impl EditInlineMessageReplyMarkup {
pub fn new_empty(inline_message_id: impl Into<String>) -> Self {
Self {
inline_message_id: inline_message_id.into(),
reply_markup: None,
}
}
pub fn new(
inline_message_id: impl Into<String>,
reply_markup: impl Into<InlineKeyboardMarkup>,
) -> Self {
Self {
inline_message_id: inline_message_id.into(),
reply_markup: Some(reply_markup.into()),
}
}
}
impl TelegramMethod for EditInlineMessageReplyMarkup {
type Response = bool;
fn name() -> &'static str {
"editMessageReplyMarkup"
}
}
impl JsonMethod for EditInlineMessageReplyMarkup {}
#[derive(Clone, Serialize)]
pub struct StopPoll {
pub chat_id: ChatId,
pub message_id: i64,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<InlineKeyboardMarkup>,
}
impl StopPoll {
pub fn new(chat_id: impl Into<ChatId>, message_id: i64) -> Self {
Self {
chat_id: chat_id.into(),
message_id,
reply_markup: None,
}
}
pub fn with_reply_markup(self, markup: impl Into<InlineKeyboardMarkup>) -> Self {
Self {
reply_markup: Some(markup.into()),
..self
}
}
}
impl TelegramMethod for StopPoll {
type Response = Poll;
fn name() -> &'static str {
"stopPoll"
}
}
impl JsonMethod for StopPoll {}
#[derive(Clone, Serialize)]
pub struct DeleteMessage {
pub chat_id: ChatId,
pub message_id: i64,
}
impl DeleteMessage {
pub fn new(chat_id: impl Into<ChatId>, message_id: i64) -> Self {
Self {
chat_id: chat_id.into(),
message_id,
}
}
}
impl TelegramMethod for DeleteMessage {
type Response = bool;
fn name() -> &'static str {
"deleteMessage"
}
}
impl JsonMethod for DeleteMessage {}