1use serde::{Deserialize, Serialize};
2
3use crate::{
4 api::{Method, Payload},
5 types::{ChatId, Integer, Message, ReplyMarkup, ReplyParameters, SuggestedPostParameters},
6};
7
8#[serde_with::skip_serializing_none]
10#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
11pub struct Contact {
12 pub first_name: String,
14 pub phone_number: String,
16 pub last_name: Option<String>,
18 pub user_id: Option<Integer>,
20 pub vcard: Option<String>,
22}
23
24impl Contact {
25 pub fn new<A, B>(first_name: A, phone_number: B) -> Self
32 where
33 A: Into<String>,
34 B: Into<String>,
35 {
36 Self {
37 first_name: first_name.into(),
38 phone_number: phone_number.into(),
39 last_name: None,
40 user_id: None,
41 vcard: None,
42 }
43 }
44
45 pub fn with_last_name<T>(mut self, value: T) -> Self
51 where
52 T: Into<String>,
53 {
54 self.last_name = Some(value.into());
55 self
56 }
57
58 pub fn with_user_id(mut self, value: Integer) -> Self {
64 self.user_id = Some(value);
65 self
66 }
67
68 pub fn with_vcard<T>(mut self, value: T) -> Self
74 where
75 T: Into<String>,
76 {
77 self.vcard = Some(value.into());
78 self
79 }
80}
81
82#[serde_with::skip_serializing_none]
84#[derive(Clone, Debug, Serialize)]
85pub struct SendContact {
86 chat_id: ChatId,
87 first_name: String,
88 phone_number: String,
89 allow_paid_broadcast: Option<bool>,
90 business_connection_id: Option<String>,
91 direct_messages_topic_id: Option<Integer>,
92 disable_notification: Option<bool>,
93 last_name: Option<String>,
94 message_effect_id: Option<String>,
95 message_thread_id: Option<Integer>,
96 protect_content: Option<bool>,
97 reply_markup: Option<ReplyMarkup>,
98 reply_parameters: Option<ReplyParameters>,
99 suggested_post_parameters: Option<SuggestedPostParameters>,
100 vcard: Option<String>,
101}
102
103impl SendContact {
104 pub fn new<A, B, C>(chat_id: A, first_name: B, phone_number: C) -> Self
112 where
113 A: Into<ChatId>,
114 B: Into<String>,
115 C: Into<String>,
116 {
117 SendContact {
118 chat_id: chat_id.into(),
119 first_name: first_name.into(),
120 phone_number: phone_number.into(),
121 allow_paid_broadcast: None,
122 business_connection_id: None,
123 direct_messages_topic_id: None,
124 disable_notification: None,
125 last_name: None,
126 message_effect_id: None,
127 message_thread_id: None,
128 protect_content: None,
129 reply_markup: None,
130 reply_parameters: None,
131 suggested_post_parameters: None,
132 vcard: None,
133 }
134 }
135
136 pub fn with_allow_paid_broadcast(mut self, value: bool) -> Self {
144 self.allow_paid_broadcast = Some(value);
145 self
146 }
147
148 pub fn with_business_connection_id<T>(mut self, value: T) -> Self
154 where
155 T: Into<String>,
156 {
157 self.business_connection_id = Some(value.into());
158 self
159 }
160
161 pub fn with_direct_messages_topic_id(mut self, value: Integer) -> Self {
167 self.direct_messages_topic_id = Some(value);
168 self
169 }
170
171 pub fn with_disable_notification(mut self, value: bool) -> Self {
178 self.disable_notification = Some(value);
179 self
180 }
181
182 pub fn with_last_name<T>(mut self, value: T) -> Self
188 where
189 T: Into<String>,
190 {
191 self.last_name = Some(value.into());
192 self
193 }
194
195 pub fn with_message_effect_id<T>(mut self, value: T) -> Self
201 where
202 T: Into<String>,
203 {
204 self.message_effect_id = Some(value.into());
205 self
206 }
207
208 pub fn with_message_thread_id(mut self, value: Integer) -> Self {
215 self.message_thread_id = Some(value);
216 self
217 }
218
219 pub fn with_protect_content(mut self, value: bool) -> Self {
226 self.protect_content = Some(value);
227 self
228 }
229
230 pub fn with_reply_markup<T>(mut self, value: T) -> Self
236 where
237 T: Into<ReplyMarkup>,
238 {
239 self.reply_markup = Some(value.into());
240 self
241 }
242
243 pub fn with_reply_parameters(mut self, value: ReplyParameters) -> Self {
249 self.reply_parameters = Some(value);
250 self
251 }
252
253 pub fn with_suggested_post_parameters(mut self, value: SuggestedPostParameters) -> Self {
263 self.suggested_post_parameters = Some(value);
264 self
265 }
266
267 pub fn with_vcard<T>(mut self, value: T) -> Self
273 where
274 T: Into<String>,
275 {
276 self.vcard = Some(value.into());
277 self
278 }
279}
280
281impl Method for SendContact {
282 type Response = Message;
283
284 fn into_payload(self) -> Payload {
285 Payload::json("sendContact", self)
286 }
287}