telegram_bot_raw/requests/
send_audio.rs1use std::borrow::Cow;
2
3use crate::requests::*;
4use crate::types::*;
5
6#[derive(Debug, Clone, PartialEq, PartialOrd)]
8#[must_use = "requests do nothing unless sent"]
9pub struct SendAudio<'c, 'p, 't> {
10 chat_id: ChatRef,
11 audio: InputFile,
12 caption: Option<Cow<'c, str>>,
13 parse_mode: Option<ParseMode>,
14 duration: Option<Integer>,
15 performer: Option<Cow<'p, str>>,
16 title: Option<Cow<'t, str>>,
17 thumb: Option<InputFile>,
18 reply_to_message_id: Option<MessageId>,
19 disable_notification: bool,
20 reply_markup: Option<ReplyMarkup>,
21}
22
23impl<'c, 'p, 't> ToMultipart for SendAudio<'c, 'p, 't> {
24 fn to_multipart(&self) -> Result<Multipart, Error> {
25 multipart_map! {
26 self,
27 (chat_id (text));
28 (audio (raw));
29 (caption (text), optional);
30 (parse_mode (text), optional);
31 (duration (text), optional);
32 (performer (text), optional);
33 (title (text), optional);
34 (thumb (raw), optional);
35 (reply_to_message_id (text), optional);
36 (disable_notification (text), when_true);
37 (reply_markup (json), optional);
38 }
39 }
40}
41
42impl<'c, 'p, 't> Request for SendAudio<'c, 'p, 't> {
43 type Type = MultipartRequestType<Self>;
44 type Response = JsonIdResponse<Message>;
45
46 fn serialize(&self) -> Result<HttpRequest, Error> {
47 Self::Type::serialize(RequestUrl::method("sendAudio"), self)
48 }
49}
50
51impl<'c, 'p, 't> SendAudio<'c, 'p, 't> {
52 pub fn new<C, V>(chat: C, audio: V) -> Self
53 where
54 C: ToChatRef,
55 V: Into<InputFile>,
56 {
57 Self {
58 chat_id: chat.to_chat_ref(),
59 audio: audio.into(),
60 caption: None,
61 parse_mode: None,
62 duration: None,
63 performer: None,
64 title: None,
65 thumb: None,
66 reply_to_message_id: None,
67 reply_markup: None,
68 disable_notification: false,
69 }
70 }
71
72 pub fn thumb<V>(&mut self, thumb: V) -> &mut Self
73 where
74 V: Into<InputFileUpload>,
75 {
76 self.thumb = Some(thumb.into().into());
77 self
78 }
79
80 pub fn caption<T>(&mut self, caption: T) -> &mut Self
81 where
82 T: Into<Cow<'c, str>>,
83 {
84 self.caption = Some(caption.into());
85 self
86 }
87
88 pub fn parse_mode(&mut self, parse_mode: ParseMode) -> &mut Self {
89 self.parse_mode = Some(parse_mode);
90 self
91 }
92
93 pub fn duration(&mut self, duration: Integer) -> &mut Self {
94 self.duration = Some(duration);
95 self
96 }
97
98 pub fn performer<T>(&mut self, performer: T) -> &mut Self
99 where
100 T: Into<Cow<'p, str>>,
101 {
102 self.performer = Some(performer.into());
103 self
104 }
105
106 pub fn title<T>(&mut self, title: T) -> &mut Self
107 where
108 T: Into<Cow<'t, str>>,
109 {
110 self.title = Some(title.into());
111 self
112 }
113
114 pub fn reply_to<R>(&mut self, to: R) -> &mut Self
115 where
116 R: ToMessageId,
117 {
118 self.reply_to_message_id = Some(to.to_message_id());
119 self
120 }
121
122 pub fn reply_markup<R>(&mut self, reply_markup: R) -> &mut Self
123 where
124 R: Into<ReplyMarkup>,
125 {
126 self.reply_markup = Some(reply_markup.into());
127 self
128 }
129
130 pub fn disable_notification(&mut self) -> &mut Self {
131 self.disable_notification = true;
132 self
133 }
134}
135
136pub trait CanReplySendAudio {
138 fn audio_reply<'c, 'p, 't, T>(&self, audio: T) -> SendAudio<'c, 'p, 't>
139 where
140 T: Into<InputFile>;
141}
142
143impl<M> CanReplySendAudio for M
144where
145 M: ToMessageId + ToSourceChat,
146{
147 fn audio_reply<'c, 'p, 't, T>(&self, audio: T) -> SendAudio<'c, 'p, 't>
148 where
149 T: Into<InputFile>,
150 {
151 let mut req = SendAudio::new(self.to_source_chat(), audio);
152 req.reply_to(self);
153 req
154 }
155}
156
157pub trait CanSendAudio {
159 fn audio<'c, 'p, 't, T>(&self, audio: T) -> SendAudio<'c, 'p, 't>
160 where
161 T: Into<InputFile>;
162}
163
164impl<M> CanSendAudio for M
165where
166 M: ToChatRef,
167{
168 fn audio<'c, 'p, 't, T>(&self, audio: T) -> SendAudio<'c, 'p, 't>
169 where
170 T: Into<InputFile>,
171 {
172 SendAudio::new(self.to_chat_ref(), audio)
173 }
174}