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