telegram_bot_fork_raw/requests/
send_audio.rs1use std::{borrow::Cow, ops::Not};
2
3use requests::*;
4use types::*;
5
6#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
8#[must_use = "requests do nothing unless sent"]
9pub struct SendAudio<'s, 'c, 'p, 't> {
10 chat_id: ChatRef,
11 audio: Cow<'s, str>,
12 #[serde(skip_serializing_if = "Option::is_none")]
13 caption: Option<Cow<'c, str>>,
14 #[serde(skip_serializing_if = "Option::is_none")]
15 parse_mode: Option<ParseMode>,
16 #[serde(skip_serializing_if = "Option::is_none")]
17 duration: Option<i64>,
18 #[serde(skip_serializing_if = "Option::is_none")]
19 performer: Option<Cow<'p, str>>,
20 #[serde(skip_serializing_if = "Option::is_none")]
21 title: Option<Cow<'t, str>>,
22 #[serde(skip_serializing_if = "Option::is_none")]
23 reply_to_message_id: Option<MessageId>,
24 #[serde(skip_serializing_if = "Not::not")]
25 disable_notification: bool,
26 #[serde(skip_serializing_if = "Option::is_none")]
27 reply_markup: Option<ReplyMarkup>,
28}
29
30impl<'s, 'c, 'p, 't> Request for SendAudio<'s, 'c, 'p, 't> {
31 type Type = JsonRequestType<Self>;
32 type Response = JsonTrueToUnitResponse;
33
34 fn serialize(&self) -> Result<HttpRequest, Error> {
35 Self::Type::serialize(RequestUrl::method("sendAudio"), self)
36 }
37}
38
39impl<'s, 'c, 'p, 't> SendAudio<'s, 'c, 'p, 't> {
40 pub fn with_url<C, T>(chat: C, url: T) -> Self
41 where
42 C: ToChatRef,
43 T: Into<Cow<'s, str>>,
44 {
45 Self {
46 chat_id: chat.to_chat_ref(),
47 audio: url.into(),
48 caption: None,
49 parse_mode: None,
50 duration: None,
51 performer: None,
52 title: None,
53 reply_to_message_id: None,
54 reply_markup: None,
55 disable_notification: false,
56 }
57 }
58
59 pub fn caption<T>(&mut self, caption: T) -> &mut Self
60 where
61 T: Into<Cow<'c, str>>,
62 {
63 self.caption = Some(caption.into());
64 self
65 }
66
67 pub fn parse_mode(&mut self, parse_mode: ParseMode) -> &mut Self {
68 self.parse_mode = Some(parse_mode);
69 self
70 }
71
72 pub fn duration(&mut self, duration: i64) -> &mut Self {
73 self.duration = Some(duration);
74 self
75 }
76
77 pub fn performer<T>(&mut self, performer: T) -> &mut Self
78 where
79 T: Into<Cow<'p, str>>,
80 {
81 self.performer = Some(performer.into());
82 self
83 }
84
85 pub fn title<T>(&mut self, title: T) -> &mut Self
86 where
87 T: Into<Cow<'t, str>>,
88 {
89 self.title = Some(title.into());
90 self
91 }
92
93 pub fn reply_to<R>(&mut self, to: R) -> &mut Self
94 where
95 R: ToMessageId,
96 {
97 self.reply_to_message_id = Some(to.to_message_id());
98 self
99 }
100
101 pub fn reply_markup<R>(&mut self, reply_markup: R) -> &mut Self
102 where
103 R: Into<ReplyMarkup>,
104 {
105 self.reply_markup = Some(reply_markup.into());
106 self
107 }
108}
109
110pub trait CanReplySendAudio {
112 fn audio_url_reply<'s, 'c, 'p, 't, T>(&self, url: T) -> SendAudio<'s, 'c, 'p, 't>
113 where
114 T: Into<Cow<'s, str>>;
115}
116
117impl<M> CanReplySendAudio for M
118where
119 M: ToMessageId + ToSourceChat,
120{
121 fn audio_url_reply<'s, 'c, 'p, 't, T>(&self, url: T) -> SendAudio<'s, 'c, 'p, 't>
122 where
123 T: Into<Cow<'s, str>>,
124 {
125 let mut req = SendAudio::with_url(self.to_source_chat(), url);
126 req.reply_to(self);
127 req
128 }
129}
130
131pub trait CanSendAudio {
133 fn audio_url<'s, 'c, 'p, 't, T>(&self, url: T) -> SendAudio<'s, 'c, 'p, 't>
134 where
135 T: Into<Cow<'s, str>>;
136}
137
138impl<M> CanSendAudio for M
139where
140 M: ToChatRef,
141{
142 fn audio_url<'s, 'c, 'p, 't, T>(&self, url: T) -> SendAudio<'s, 'c, 'p, 't>
143 where
144 T: Into<Cow<'s, str>>,
145 {
146 SendAudio::with_url(self.to_chat_ref(), url)
147 }
148}