slacko 0.2.2

Comprehensive Rust SDK for the Slack API with stealth mode support
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
//! Interactive elements for Block Kit
//!
//! These are the interactive components that can appear in blocks.

use super::objects::{ConfirmationDialog, OptionObject, TextObject};
use serde::{Deserialize, Serialize};
use serde_json::Value;

/// Button element
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ButtonElement {
    #[serde(rename = "type")]
    type_field: String,
    pub text: TextObject,
    pub action_id: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub url: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub value: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub style: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub confirm: Option<ConfirmationDialog>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub accessibility_label: Option<String>,
}

impl ButtonElement {
    /// Create a new button
    pub fn new(action_id: impl Into<String>, text: impl Into<String>) -> Self {
        Self {
            type_field: "button".to_string(),
            text: TextObject::plain(text),
            action_id: action_id.into(),
            url: None,
            value: None,
            style: None,
            confirm: None,
            accessibility_label: None,
        }
    }

    /// Set the button URL
    pub fn url(mut self, url: impl Into<String>) -> Self {
        self.url = Some(url.into());
        self
    }

    /// Set the button value
    pub fn value(mut self, value: impl Into<String>) -> Self {
        self.value = Some(value.into());
        self
    }

    /// Set the button style
    pub fn style(mut self, style: impl Into<String>) -> Self {
        self.style = Some(style.into());
        self
    }

    /// Make button primary style
    pub fn primary(mut self) -> Self {
        self.style = Some("primary".to_string());
        self
    }

    /// Make button danger style
    pub fn danger(mut self) -> Self {
        self.style = Some("danger".to_string());
        self
    }

    /// Add confirmation dialog
    pub fn confirm(mut self, confirm: ConfirmationDialog) -> Self {
        self.confirm = Some(confirm);
        self
    }

    /// Convert to JSON value
    pub fn build(self) -> Value {
        serde_json::to_value(self).expect("ButtonElement is always serializable")
    }
}

/// Static select menu element
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SelectElement {
    #[serde(rename = "type")]
    type_field: String,
    pub action_id: String,
    pub placeholder: TextObject,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub options: Option<Vec<OptionObject>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub initial_option: Option<OptionObject>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub confirm: Option<ConfirmationDialog>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub focus_on_load: Option<bool>,
}

impl SelectElement {
    /// Create a static select menu
    pub fn new(action_id: impl Into<String>, placeholder: impl Into<String>) -> Self {
        Self {
            type_field: "static_select".to_string(),
            action_id: action_id.into(),
            placeholder: TextObject::plain(placeholder),
            options: None,
            initial_option: None,
            confirm: None,
            focus_on_load: None,
        }
    }

    /// Create a users select menu
    pub fn users(action_id: impl Into<String>, placeholder: impl Into<String>) -> Self {
        Self {
            type_field: "users_select".to_string(),
            action_id: action_id.into(),
            placeholder: TextObject::plain(placeholder),
            options: None,
            initial_option: None,
            confirm: None,
            focus_on_load: None,
        }
    }

    /// Create a conversations select menu
    pub fn conversations(action_id: impl Into<String>, placeholder: impl Into<String>) -> Self {
        Self {
            type_field: "conversations_select".to_string(),
            action_id: action_id.into(),
            placeholder: TextObject::plain(placeholder),
            options: None,
            initial_option: None,
            confirm: None,
            focus_on_load: None,
        }
    }

    /// Create a channels select menu
    pub fn channels(action_id: impl Into<String>, placeholder: impl Into<String>) -> Self {
        Self {
            type_field: "channels_select".to_string(),
            action_id: action_id.into(),
            placeholder: TextObject::plain(placeholder),
            options: None,
            initial_option: None,
            confirm: None,
            focus_on_load: None,
        }
    }

    /// Add options (for static select)
    pub fn options(mut self, options: Vec<OptionObject>) -> Self {
        self.options = Some(options);
        self
    }

    /// Set initial option
    pub fn initial_option(mut self, option: OptionObject) -> Self {
        self.initial_option = Some(option);
        self
    }

    /// Add confirmation dialog
    pub fn confirm(mut self, confirm: ConfirmationDialog) -> Self {
        self.confirm = Some(confirm);
        self
    }

    /// Focus on load
    pub fn focus_on_load(mut self) -> Self {
        self.focus_on_load = Some(true);
        self
    }

    /// Convert to JSON value
    pub fn build(self) -> Value {
        serde_json::to_value(self).expect("SelectElement is always serializable")
    }
}

/// Multi-select menu element
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MultiSelectElement {
    #[serde(rename = "type")]
    type_field: String,
    pub action_id: String,
    pub placeholder: TextObject,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub options: Option<Vec<OptionObject>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub initial_options: Option<Vec<OptionObject>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_selected_items: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub confirm: Option<ConfirmationDialog>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub focus_on_load: Option<bool>,
}

impl MultiSelectElement {
    /// Create a multi-select menu
    pub fn new(action_id: impl Into<String>, placeholder: impl Into<String>) -> Self {
        Self {
            type_field: "multi_static_select".to_string(),
            action_id: action_id.into(),
            placeholder: TextObject::plain(placeholder),
            options: None,
            initial_options: None,
            max_selected_items: None,
            confirm: None,
            focus_on_load: None,
        }
    }

    /// Add options
    pub fn options(mut self, options: Vec<OptionObject>) -> Self {
        self.options = Some(options);
        self
    }

    /// Set max selected items
    pub fn max_selected_items(mut self, max: u32) -> Self {
        self.max_selected_items = Some(max);
        self
    }

    /// Convert to JSON value
    pub fn build(self) -> Value {
        serde_json::to_value(self).expect("MultiSelectElement is always serializable")
    }
}

/// Overflow menu element
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OverflowElement {
    #[serde(rename = "type")]
    type_field: String,
    pub action_id: String,
    pub options: Vec<OptionObject>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub confirm: Option<ConfirmationDialog>,
}

impl OverflowElement {
    /// Create an overflow menu
    pub fn new(action_id: impl Into<String>) -> Self {
        Self {
            type_field: "overflow".to_string(),
            action_id: action_id.into(),
            options: Vec::new(),
            confirm: None,
        }
    }

    /// Add an option
    pub fn option(mut self, option: OptionObject) -> Self {
        self.options.push(option);
        self
    }

    /// Add multiple options
    pub fn options(mut self, options: Vec<OptionObject>) -> Self {
        self.options.extend(options);
        self
    }

    /// Convert to JSON value
    pub fn build(self) -> Value {
        serde_json::to_value(self).expect("OverflowElement is always serializable")
    }
}

/// Date picker element
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DatePickerElement {
    #[serde(rename = "type")]
    type_field: String,
    pub action_id: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub placeholder: Option<TextObject>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub initial_date: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub confirm: Option<ConfirmationDialog>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub focus_on_load: Option<bool>,
}

impl DatePickerElement {
    /// Create a date picker
    pub fn new(action_id: impl Into<String>) -> Self {
        Self {
            type_field: "datepicker".to_string(),
            action_id: action_id.into(),
            placeholder: None,
            initial_date: None,
            confirm: None,
            focus_on_load: None,
        }
    }

    /// Set placeholder
    pub fn placeholder(mut self, text: impl Into<String>) -> Self {
        self.placeholder = Some(TextObject::plain(text));
        self
    }

    /// Set initial date (YYYY-MM-DD)
    pub fn initial_date(mut self, date: impl Into<String>) -> Self {
        self.initial_date = Some(date.into());
        self
    }

    /// Convert to JSON value
    pub fn build(self) -> Value {
        serde_json::to_value(self).expect("DatePickerElement is always serializable")
    }
}

/// Time picker element
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TimePickerElement {
    #[serde(rename = "type")]
    type_field: String,
    pub action_id: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub placeholder: Option<TextObject>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub initial_time: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub confirm: Option<ConfirmationDialog>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub focus_on_load: Option<bool>,
}

impl TimePickerElement {
    /// Create a time picker
    pub fn new(action_id: impl Into<String>) -> Self {
        Self {
            type_field: "timepicker".to_string(),
            action_id: action_id.into(),
            placeholder: None,
            initial_time: None,
            confirm: None,
            focus_on_load: None,
        }
    }

    /// Set placeholder
    pub fn placeholder(mut self, text: impl Into<String>) -> Self {
        self.placeholder = Some(TextObject::plain(text));
        self
    }

    /// Set initial time (HH:mm)
    pub fn initial_time(mut self, time: impl Into<String>) -> Self {
        self.initial_time = Some(time.into());
        self
    }

    /// Convert to JSON value
    pub fn build(self) -> Value {
        serde_json::to_value(self).expect("TimePickerElement is always serializable")
    }
}

/// Datetime picker element
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DatetimePickerElement {
    #[serde(rename = "type")]
    type_field: String,
    pub action_id: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub initial_date_time: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub confirm: Option<ConfirmationDialog>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub focus_on_load: Option<bool>,
}

impl DatetimePickerElement {
    /// Create a datetime picker
    pub fn new(action_id: impl Into<String>) -> Self {
        Self {
            type_field: "datetimepicker".to_string(),
            action_id: action_id.into(),
            initial_date_time: None,
            confirm: None,
            focus_on_load: None,
        }
    }

    /// Set initial datetime (Unix timestamp)
    pub fn initial_date_time(mut self, timestamp: i64) -> Self {
        self.initial_date_time = Some(timestamp);
        self
    }

    /// Convert to JSON value
    pub fn build(self) -> Value {
        serde_json::to_value(self).expect("DatetimePickerElement is always serializable")
    }
}

/// Plain text input element
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PlainTextInputElement {
    #[serde(rename = "type")]
    type_field: String,
    pub action_id: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub placeholder: Option<TextObject>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub initial_value: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub multiline: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_length: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_length: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub dispatch_action_config: Option<Value>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub focus_on_load: Option<bool>,
}

impl PlainTextInputElement {
    /// Create a plain text input
    pub fn new(action_id: impl Into<String>) -> Self {
        Self {
            type_field: "plain_text_input".to_string(),
            action_id: action_id.into(),
            placeholder: None,
            initial_value: None,
            multiline: None,
            min_length: None,
            max_length: None,
            dispatch_action_config: None,
            focus_on_load: None,
        }
    }

    /// Set placeholder
    pub fn placeholder(mut self, text: impl Into<String>) -> Self {
        self.placeholder = Some(TextObject::plain(text));
        self
    }

    /// Set initial value
    pub fn initial_value(mut self, value: impl Into<String>) -> Self {
        self.initial_value = Some(value.into());
        self
    }

    /// Enable multiline
    pub fn multiline(mut self) -> Self {
        self.multiline = Some(true);
        self
    }

    /// Set min length
    pub fn min_length(mut self, length: u32) -> Self {
        self.min_length = Some(length);
        self
    }

    /// Set max length
    pub fn max_length(mut self, length: u32) -> Self {
        self.max_length = Some(length);
        self
    }

    /// Convert to JSON value
    pub fn build(self) -> Value {
        serde_json::to_value(self).expect("PlainTextInputElement is always serializable")
    }
}

/// Radio buttons element
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RadioButtonsElement {
    #[serde(rename = "type")]
    type_field: String,
    pub action_id: String,
    pub options: Vec<OptionObject>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub initial_option: Option<OptionObject>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub confirm: Option<ConfirmationDialog>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub focus_on_load: Option<bool>,
}

impl RadioButtonsElement {
    /// Create radio buttons
    pub fn new(action_id: impl Into<String>) -> Self {
        Self {
            type_field: "radio_buttons".to_string(),
            action_id: action_id.into(),
            options: Vec::new(),
            initial_option: None,
            confirm: None,
            focus_on_load: None,
        }
    }

    /// Add an option
    pub fn option(mut self, option: OptionObject) -> Self {
        self.options.push(option);
        self
    }

    /// Add multiple options
    pub fn options(mut self, options: Vec<OptionObject>) -> Self {
        self.options.extend(options);
        self
    }

    /// Set initial option
    pub fn initial_option(mut self, option: OptionObject) -> Self {
        self.initial_option = Some(option);
        self
    }

    /// Convert to JSON value
    pub fn build(self) -> Value {
        serde_json::to_value(self).expect("RadioButtonsElement is always serializable")
    }
}

/// Checkboxes element
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CheckboxesElement {
    #[serde(rename = "type")]
    type_field: String,
    pub action_id: String,
    pub options: Vec<OptionObject>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub initial_options: Option<Vec<OptionObject>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub confirm: Option<ConfirmationDialog>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub focus_on_load: Option<bool>,
}

impl CheckboxesElement {
    /// Create checkboxes
    pub fn new(action_id: impl Into<String>) -> Self {
        Self {
            type_field: "checkboxes".to_string(),
            action_id: action_id.into(),
            options: Vec::new(),
            initial_options: None,
            confirm: None,
            focus_on_load: None,
        }
    }

    /// Add an option
    pub fn option(mut self, option: OptionObject) -> Self {
        self.options.push(option);
        self
    }

    /// Add multiple options
    pub fn options(mut self, options: Vec<OptionObject>) -> Self {
        self.options.extend(options);
        self
    }

    /// Convert to JSON value
    pub fn build(self) -> Value {
        serde_json::to_value(self).expect("CheckboxesElement is always serializable")
    }
}