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