tgbot/types/contact/
mod.rs1use serde::{Deserialize, Serialize};
2
3use crate::{
4 api::{Method, Payload},
5 types::{ChatId, Integer, Message, ReplyMarkup, ReplyParameters},
6};
7
8#[cfg(test)]
9mod tests;
10
11#[serde_with::skip_serializing_none]
13#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
14pub struct Contact {
15 pub first_name: String,
17 pub phone_number: String,
19 pub last_name: Option<String>,
21 pub user_id: Option<Integer>,
23 pub vcard: Option<String>,
25}
26
27impl Contact {
28 pub fn new<A, B>(first_name: A, phone_number: B) -> Self
35 where
36 A: Into<String>,
37 B: Into<String>,
38 {
39 Self {
40 first_name: first_name.into(),
41 phone_number: phone_number.into(),
42 last_name: None,
43 user_id: None,
44 vcard: None,
45 }
46 }
47
48 pub fn with_last_name<T>(mut self, value: T) -> Self
54 where
55 T: Into<String>,
56 {
57 self.last_name = Some(value.into());
58 self
59 }
60
61 pub fn with_user_id(mut self, value: Integer) -> Self {
67 self.user_id = Some(value);
68 self
69 }
70
71 pub fn with_vcard<T>(mut self, value: T) -> Self
77 where
78 T: Into<String>,
79 {
80 self.vcard = Some(value.into());
81 self
82 }
83}
84
85#[serde_with::skip_serializing_none]
87#[derive(Clone, Debug, Serialize)]
88pub struct SendContact {
89 chat_id: ChatId,
90 first_name: String,
91 phone_number: String,
92 allow_paid_broadcast: Option<bool>,
93 business_connection_id: Option<String>,
94 disable_notification: Option<bool>,
95 last_name: Option<String>,
96 message_effect_id: Option<String>,
97 message_thread_id: Option<Integer>,
98 protect_content: Option<bool>,
99 reply_markup: Option<ReplyMarkup>,
100 reply_parameters: Option<ReplyParameters>,
101 vcard: Option<String>,
102}
103
104impl SendContact {
105 pub fn new<A, B, C>(chat_id: A, first_name: B, phone_number: C) -> Self
113 where
114 A: Into<ChatId>,
115 B: Into<String>,
116 C: Into<String>,
117 {
118 SendContact {
119 chat_id: chat_id.into(),
120 first_name: first_name.into(),
121 phone_number: phone_number.into(),
122 allow_paid_broadcast: None,
123 business_connection_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 vcard: None,
132 }
133 }
134
135 pub fn with_allow_paid_broadcast(mut self, value: bool) -> Self {
143 self.allow_paid_broadcast = Some(value);
144 self
145 }
146
147 pub fn with_business_connection_id<T>(mut self, value: T) -> Self
153 where
154 T: Into<String>,
155 {
156 self.business_connection_id = Some(value.into());
157 self
158 }
159
160 pub fn with_disable_notification(mut self, value: bool) -> Self {
167 self.disable_notification = Some(value);
168 self
169 }
170
171 pub fn with_last_name<T>(mut self, value: T) -> Self
177 where
178 T: Into<String>,
179 {
180 self.last_name = Some(value.into());
181 self
182 }
183
184 pub fn with_message_effect_id<T>(mut self, value: T) -> Self
190 where
191 T: Into<String>,
192 {
193 self.message_effect_id = Some(value.into());
194 self
195 }
196
197 pub fn with_message_thread_id(mut self, value: Integer) -> Self {
204 self.message_thread_id = Some(value);
205 self
206 }
207
208 pub fn with_protect_content(mut self, value: bool) -> Self {
215 self.protect_content = Some(value);
216 self
217 }
218
219 pub fn with_reply_markup<T>(mut self, value: T) -> Self
225 where
226 T: Into<ReplyMarkup>,
227 {
228 self.reply_markup = Some(value.into());
229 self
230 }
231
232 pub fn with_reply_parameters(mut self, value: ReplyParameters) -> Self {
238 self.reply_parameters = Some(value);
239 self
240 }
241
242 pub fn with_vcard<T>(mut self, value: T) -> Self
248 where
249 T: Into<String>,
250 {
251 self.vcard = Some(value.into());
252 self
253 }
254}
255
256impl Method for SendContact {
257 type Response = Message;
258
259 fn into_payload(self) -> Payload {
260 Payload::json("sendContact", self)
261 }
262}