tgbot/types/definitions/checklist.rs
1use serde::{Deserialize, Serialize};
2
3use crate::{
4 api::{Method, Payload},
5 types::{InlineKeyboardMarkup, Integer, Message, ParseMode, ReplyParameters, TextEntities, TextEntity, User},
6};
7
8/// Describes a task in a checklist.
9#[serde_with::skip_serializing_none]
10#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
11pub struct ChecklistTask {
12 /// Unique identifier of the task.
13 pub id: Integer,
14 /// Text of the task.
15 pub text: String,
16 /// User that completed the task; omitted if the task wasn't completed.
17 pub completed_by_user: Option<User>,
18 /// Point in time (Unix timestamp) when the task was completed; 0 if the task wasn't completed.
19 pub completion_date: Option<Integer>,
20 /// Special entities that appear in the task text.
21 pub text_entities: Option<TextEntities>,
22}
23
24impl ChecklistTask {
25 /// Creates a new `ChecklistTask`.
26 ///
27 /// # Arguments
28 ///
29 /// * `id` - Unique identifier of the task.
30 /// * `text` - Text of the task.
31 pub fn new<T>(id: Integer, text: T) -> Self
32 where
33 T: Into<String>,
34 {
35 Self {
36 id,
37 text: text.into(),
38 completed_by_user: None,
39 completion_date: None,
40 text_entities: None,
41 }
42 }
43
44 /// Sets a new user that completed the task.
45 ///
46 /// # Arguments
47 ///
48 /// * `value` - User that completed the task; omitted if the task wasn't completed.
49 pub fn with_completed_by_user(mut self, value: User) -> Self {
50 self.completed_by_user = Some(value);
51 self
52 }
53
54 /// Sets a new completion date
55 ///
56 /// # Arguments
57 ///
58 /// * `value` - Point in time (Unix timestamp) when the task was completed; 0 if the task wasn't completed.
59 pub fn with_completion_date(mut self, value: Integer) -> Self {
60 self.completion_date = Some(value);
61 self
62 }
63
64 /// Sets a new list of text entities.
65 ///
66 /// # Arguments
67 ///
68 /// * `value` - Special entities that appear in the task text.
69 pub fn with_text_entities<T>(mut self, value: T) -> Self
70 where
71 T: IntoIterator<Item = TextEntity>,
72 {
73 self.text_entities = Some(TextEntities::from_iter(value));
74 self
75 }
76}
77
78/// Describes a checklist.
79#[serde_with::skip_serializing_none]
80#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
81pub struct Checklist {
82 /// List of tasks in the checklist.
83 pub tasks: Vec<ChecklistTask>,
84 /// Title of the checklist.
85 pub title: String,
86 /// Whether users other than the creator of the list can add tasks to the list.
87 pub others_can_add_tasks: Option<bool>,
88 /// Whether users other than the creator of the list can mark tasks as done or not done.
89 pub others_can_mark_tasks_as_done: Option<bool>,
90 /// Special entities that appear in the checklist title.
91 pub title_entities: Option<TextEntities>,
92}
93
94impl Checklist {
95 /// Creates a new `Checklist`.
96 ///
97 /// # Arguments
98 ///
99 /// * `tasks` - List of tasks in the checklist.
100 /// * `title` - Title of the checklist.
101 pub fn new<A, B>(tasks: A, title: B) -> Self
102 where
103 A: IntoIterator<Item = ChecklistTask>,
104 B: Into<String>,
105 {
106 Self {
107 tasks: tasks.into_iter().collect(),
108 title: title.into(),
109 others_can_add_tasks: None,
110 others_can_mark_tasks_as_done: None,
111 title_entities: None,
112 }
113 }
114
115 /// Sets a new value for the `others_can_add_tasks` flag.
116 ///
117 /// # Arguments
118 ///
119 /// * `value` - Whether users other than the creator of the list can add tasks to the list.
120 pub fn with_others_can_add_tasks(mut self, value: bool) -> Self {
121 self.others_can_add_tasks = Some(value);
122 self
123 }
124
125 /// Sets a new value for the `others_can_mark_tasks_as_done` flag.
126 ///
127 /// # Arguments
128 ///
129 /// * `value` - Whether users other than the creator of the list can mark tasks as done or not done.
130 pub fn with_others_can_mark_tasks_as_done(mut self, value: bool) -> Self {
131 self.others_can_mark_tasks_as_done = Some(value);
132 self
133 }
134
135 /// Sets a new list of title entities.
136 ///
137 /// # Arguments
138 ///
139 /// * `value` - Special entities that appear in the checklist title
140 pub fn with_title_entities<T>(mut self, value: T) -> Self
141 where
142 T: IntoIterator<Item = TextEntity>,
143 {
144 self.title_entities = Some(TextEntities::from_iter(value));
145 self
146 }
147}
148
149/// Describes a task to add to a checklist.
150#[serde_with::skip_serializing_none]
151#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
152pub struct InputChecklistTask {
153 /// Unique identifier of the task.
154 ///
155 /// Must be positive and unique among all task identifiers currently present in the checklist.
156 pub id: Integer,
157 /// Text of the task.
158 ///
159 /// 1-100 characters after entities parsing.
160 pub text: String,
161 /// Mode for parsing entities in the text.
162 pub parse_mode: Option<ParseMode>,
163 /// List of special entities that appear in the text.
164 ///
165 /// Can be specified instead of `parse_mode`.
166 /// Currently, only bold, italic, underline, strikethrough, spoiler, and custom_emoji entities are allowed.
167 pub text_entities: Option<TextEntities>,
168}
169
170impl InputChecklistTask {
171 /// Creates a new `InputChecklistTask`.
172 ///
173 /// # Arguments
174 ///
175 /// * `id` - Unique identifier of the task.
176 /// * `text` - Text of the task
177 pub fn new<T>(id: Integer, text: T) -> Self
178 where
179 T: Into<String>,
180 {
181 Self {
182 id,
183 text: text.into(),
184 parse_mode: None,
185 text_entities: None,
186 }
187 }
188
189 /// Sets a new parse mode.
190 ///
191 /// # Arguments
192 ///
193 /// * `value` - Mode for parsing entities in the text.
194 ///
195 /// Text entities will be set to [`None`] when this method is called.
196 pub fn with_parse_mode(mut self, value: ParseMode) -> Self {
197 self.text_entities = None;
198 self.parse_mode = Some(value);
199 self
200 }
201
202 /// Sets a new list of text entities.
203 ///
204 /// # Arguments
205 ///
206 /// * `value` - List of special entities that appear in the text.
207 ///
208 /// Parse mode will be set to [`None`] when this method is called.
209 pub fn with_text_entities<T>(mut self, value: T) -> Self
210 where
211 T: IntoIterator<Item = TextEntity>,
212 {
213 self.parse_mode = None;
214 self.text_entities = Some(TextEntities::from_iter(value));
215 self
216 }
217}
218
219/// Describes a checklist to create.
220#[serde_with::skip_serializing_none]
221#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
222pub struct InputChecklist {
223 /// List of 1-30 tasks in the checklist.
224 pub tasks: Vec<InputChecklistTask>,
225 /// Title of the checklist.
226 ///
227 /// 1-255 characters after entities parsing.
228 pub title: String,
229 /// Whether other users can add tasks to the checklist.
230 pub others_can_add_tasks: Option<bool>,
231 /// Whether other users can mark tasks as done or not done in the checklist.
232 pub others_can_mark_tasks_as_done: Option<bool>,
233 /// Mode for parsing entities in the title.
234 pub parse_mode: Option<ParseMode>,
235 /// List of special entities that appear in the title.
236 ///
237 /// Can be specified instead of parse_mode.
238 /// Currently, only bold, italic, underline, strikethrough, spoiler, and custom_emoji entities are allowed.
239 pub title_entities: Option<TextEntities>,
240}
241
242impl InputChecklist {
243 /// Creates a new `InputChecklist`.
244 ///
245 /// # Arguments
246 ///
247 /// * `tasks` - List of 1-30 tasks in the checklist.
248 /// * `title` - Title of the checklist.
249 pub fn new<A, B>(tasks: A, title: B) -> Self
250 where
251 A: IntoIterator<Item = InputChecklistTask>,
252 B: Into<String>,
253 {
254 Self {
255 tasks: tasks.into_iter().collect(),
256 title: title.into(),
257 others_can_add_tasks: None,
258 others_can_mark_tasks_as_done: None,
259 parse_mode: None,
260 title_entities: None,
261 }
262 }
263
264 /// Sets a new value for the `others_can_add_tasks` flag.
265 ///
266 /// # Arguments
267 ///
268 /// * `value` - Whether other users can add tasks to the checklist.
269 pub fn with_others_can_add_tasks(mut self, value: bool) -> Self {
270 self.others_can_add_tasks = Some(value);
271 self
272 }
273
274 /// Sets a new value for the `others_can_mark_tasks_as_done` flag.
275 ///
276 /// # Arguments
277 ///
278 /// * `value` - Whether other users can mark tasks as done or not done in the checklist.
279 pub fn with_others_can_mark_tasks_as_done(mut self, value: bool) -> Self {
280 self.others_can_mark_tasks_as_done = Some(value);
281 self
282 }
283
284 /// Sets a new parse mode.
285 ///
286 /// # Arguments
287 ///
288 /// * `value` - Mode for parsing entities in the title.
289 ///
290 /// Title entities will be set to [`None`] when this method is called.
291 pub fn with_parse_mode(mut self, value: ParseMode) -> Self {
292 self.title_entities = None;
293 self.parse_mode = Some(value);
294 self
295 }
296
297 /// Sets a new list of text entities.
298 ///
299 /// # Arguments
300 ///
301 /// * `value` - List of special entities that appear in the title.
302 ///
303 /// Parse mode will be set to [`None`] when this method is called.
304 pub fn with_title_entities<T>(mut self, value: T) -> Self
305 where
306 T: IntoIterator<Item = TextEntity>,
307 {
308 self.parse_mode = None;
309 self.title_entities = Some(TextEntities::from_iter(value));
310 self
311 }
312}
313
314/// Describes a service message about checklist tasks marked as done or not done.
315#[serde_with::skip_serializing_none]
316#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
317pub struct ChecklistTasksDone {
318 /// Message containing the checklist whose tasks were marked as done or not done.
319 ///
320 /// Note that the Message object in this field will not contain
321 /// the reply_to_message field even if it itself is a reply.
322 pub checklist_message: Option<Box<Message>>,
323 /// Identifiers of the tasks that were marked as done.
324 pub marked_as_done_task_ids: Option<Vec<Integer>>,
325 /// Identifiers of the tasks that were marked as not done.
326 pub marked_as_not_done_task_ids: Option<Vec<Integer>>,
327}
328
329impl ChecklistTasksDone {
330 /// Sets a new checklist message.
331 ///
332 /// # Arguments
333 ///
334 /// * `value` - Message containing the checklist whose tasks were marked as done or not done.
335 pub fn with_checklist_message(mut self, value: Message) -> Self {
336 self.checklist_message = Some(Box::new(value));
337 self
338 }
339
340 /// Sets a new list of task identifiers.
341 ///
342 /// # Arguments
343 ///
344 /// * `value` - Identifiers of the tasks that were marked as done.
345 pub fn with_marked_as_done_task_ids<T>(mut self, value: T) -> Self
346 where
347 T: IntoIterator<Item = Integer>,
348 {
349 self.marked_as_done_task_ids = Some(value.into_iter().collect());
350 self
351 }
352
353 /// Sets a new list of task identifiers.
354 ///
355 /// # Arguments
356 ///
357 /// * `value` - Identifiers of the tasks that were marked as not done.
358 pub fn with_marked_as_not_done_task_ids<T>(mut self, value: T) -> Self
359 where
360 T: IntoIterator<Item = Integer>,
361 {
362 self.marked_as_not_done_task_ids = Some(value.into_iter().collect());
363 self
364 }
365}
366
367/// Describes a service message about tasks added to a checklist.
368#[serde_with::skip_serializing_none]
369#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
370pub struct ChecklistTasksAdded {
371 /// List of tasks added to the checklist.
372 pub tasks: Vec<ChecklistTask>,
373 /// Message containing the checklist to which the tasks were added.
374 ///
375 /// Note that the Message object in this field will not contain
376 /// the reply_to_message field even if it itself is a reply.
377 pub checklist_message: Option<Box<Message>>,
378}
379
380impl ChecklistTasksAdded {
381 /// Creates a new `ChecklistTasksAdded`.
382 ///
383 /// # Arguments
384 ///
385 /// * `tasks` - List of tasks added to the checklist.
386 pub fn new<T>(tasks: T) -> Self
387 where
388 T: IntoIterator<Item = ChecklistTask>,
389 {
390 Self {
391 tasks: tasks.into_iter().collect(),
392 checklist_message: None,
393 }
394 }
395
396 /// Sets a new checklist message.
397 ///
398 /// # Arguments
399 ///
400 /// * `value` - Message containing the checklist to which the tasks were added.
401 pub fn with_checklist_message(mut self, value: Message) -> Self {
402 self.checklist_message = Some(Box::new(value));
403 self
404 }
405}
406
407/// Sends a checklist on behalf of a connected business account.
408#[serde_with::skip_serializing_none]
409#[derive(Clone, Debug, PartialEq, Serialize)]
410pub struct SendChecklist {
411 business_connection_id: String,
412 chat_id: Integer,
413 checklist: InputChecklist,
414 disable_notification: Option<bool>,
415 message_effect_id: Option<String>,
416 protect_content: Option<bool>,
417 reply_markup: Option<InlineKeyboardMarkup>,
418 reply_parameters: Option<ReplyParameters>,
419}
420
421impl SendChecklist {
422 /// Creates a new `SendChecklist`.
423 ///
424 /// # Arguments
425 ///
426 /// * `business_connection_id` - Unique identifier of the business connection.
427 /// * `chat_id` - Unique identifier for the target chat.
428 /// * `checklist` - The checklist to send.
429 pub fn new<T>(business_connection_id: T, chat_id: Integer, checklist: InputChecklist) -> Self
430 where
431 T: Into<String>,
432 {
433 Self {
434 business_connection_id: business_connection_id.into(),
435 chat_id,
436 checklist,
437 disable_notification: None,
438 message_effect_id: None,
439 protect_content: None,
440 reply_markup: None,
441 reply_parameters: None,
442 }
443 }
444
445 /// Sets a new value for the `disable_notification` flag.
446 ///
447 /// # Arguments
448 ///
449 /// * `value` - Whether to send the message silently.
450 ///
451 /// Users will receive a notification with no sound.
452 pub fn with_disable_notification(mut self, value: bool) -> Self {
453 self.disable_notification = Some(value);
454 self
455 }
456
457 /// Sets a new message effect ID.
458 ///
459 /// # Arguments
460 ///
461 /// * `value` - Unique identifier of the message effect to be added to the message.
462 pub fn with_message_effect_id<T>(mut self, value: T) -> Self
463 where
464 T: Into<String>,
465 {
466 self.message_effect_id = Some(value.into());
467 self
468 }
469
470 /// Sets a new value for the `protect_content` flag.
471 ///
472 /// # Arguments
473 ///
474 /// * `value` - Whether to protect the contents of the sent message from forwarding and saving.
475 pub fn with_protect_content(mut self, value: bool) -> Self {
476 self.protect_content = Some(value);
477 self
478 }
479
480 /// Sets a new reply markup.
481 ///
482 /// # Arguments
483 ///
484 // * `value` - An inline keyboard.
485 pub fn with_reply_markup<T>(mut self, value: T) -> Self
486 where
487 T: Into<InlineKeyboardMarkup>,
488 {
489 self.reply_markup = Some(value.into());
490 self
491 }
492
493 /// Sets a new list of reply parameters.
494 ///
495 /// # Arguments
496 ///
497 // * `value` - Description of the message to reply to.
498 pub fn with_reply_parameters(mut self, value: ReplyParameters) -> Self {
499 self.reply_parameters = Some(value);
500 self
501 }
502}
503
504impl Method for SendChecklist {
505 type Response = Message;
506
507 fn into_payload(self) -> Payload {
508 Payload::json("sendChecklist", self)
509 }
510}
511
512/// Edits a checklist on behalf of a connected business account. On success, the edited Message is returned.
513#[serde_with::skip_serializing_none]
514#[derive(Clone, Debug, PartialEq, Serialize)]
515pub struct EditMessageChecklist {
516 business_connection_id: String,
517 chat_id: Integer,
518 checklist: InputChecklist,
519 message_id: Integer,
520 reply_markup: Option<InlineKeyboardMarkup>,
521}
522
523impl EditMessageChecklist {
524 /// Creates a new `EditMessageChecklist`.
525 ///
526 /// # Arguments
527 ///
528 /// * `business_connection_id` - Unique identifier of the business connection.
529 /// * `chat_id` - Unique identifier for the target chat.
530 /// * `checklist` - The new checklist.
531 /// * `message_id` - Unique identifier for the target message.
532 pub fn new<T>(business_connection_id: T, chat_id: Integer, checklist: InputChecklist, message_id: Integer) -> Self
533 where
534 T: Into<String>,
535 {
536 Self {
537 business_connection_id: business_connection_id.into(),
538 chat_id,
539 checklist,
540 message_id,
541 reply_markup: None,
542 }
543 }
544
545 /// Sets a new reply markup.
546 ///
547 /// * `value` - The new inline keyboard for the message
548 pub fn with_reply_markup<T>(mut self, value: T) -> Self
549 where
550 T: Into<InlineKeyboardMarkup>,
551 {
552 self.reply_markup = Some(value.into());
553 self
554 }
555}
556
557impl Method for EditMessageChecklist {
558 type Response = Message;
559
560 fn into_payload(self) -> Payload {
561 Payload::json("editMessageChecklist", self)
562 }
563}