slack_blocks/elems/select/multi/
public_channel.rs

1//! # Public Channel Select
2//! [slack api docs 🔗](https://api.slack.com/reference/block-kit/block-elements#channel_select)
3//!
4//! This select menu will populate its options with a list of
5//! public channels visible to the current user in the active workspace.
6
7use std::borrow::Cow;
8
9use serde::{Deserialize, Serialize};
10#[cfg(feature = "validation")]
11use validator::Validate;
12
13#[cfg(feature = "validation")]
14use crate::val_helpr::ValidationResult;
15use crate::{compose::Confirm, elems::select::public_channel::build, text};
16
17/// # Public Channel Select
18/// [slack api docs 🔗](https://api.slack.com/reference/block-kit/block-elements#channel_select)
19///
20/// This select menu will populate its options with a list of
21/// public channels visible to the current user in the active workspace.
22#[derive(Clone, Debug, Deserialize, Hash, PartialEq, Serialize)]
23#[cfg_attr(feature = "validation", derive(Validate))]
24pub struct PublicChannel<'a> {
25  #[cfg_attr(feature = "validation",
26             validate(custom = "crate::elems::select::validate::placeholder"))]
27  pub(in crate::elems::select) placeholder: text::Text,
28
29  #[cfg_attr(feature = "validation", validate(length(max = 255)))]
30  pub(in crate::elems::select) action_id: Cow<'a, str>,
31
32  #[serde(skip_serializing_if = "Option::is_none")]
33  #[cfg_attr(feature = "validation", validate)]
34  pub(in crate::elems::select) confirm: Option<Confirm>,
35
36  #[serde(skip_serializing_if = "Option::is_none")]
37  pub(in crate::elems::select) initial_channels: Option<Cow<'a, [String]>>,
38
39  #[cfg_attr(feature = "validation", validate(range(min = 1)))]
40  #[serde(skip_serializing_if = "Option::is_none")]
41  pub(in crate::elems::select) max_selected_items: Option<u32>,
42}
43
44impl<'a> PublicChannel<'a> {
45  /// Build a new conversation multi-select element
46  ///
47  /// # Examples
48  /// ```
49  /// // TODO(#130)
50  /// ```
51  pub fn builder() -> build::MultiPublicChannelBuilderInit<'a> {
52    build::MultiPublicChannelBuilderInit::new()
53  }
54
55  /// Validate that this Public Channel Select element
56  /// agrees with Slack's model requirements
57  ///
58  /// # Errors
59  /// - If `placeholder` longer than 150 chars
60  /// - If `action_id` longer than 255 chars
61  ///
62  /// # Example
63  /// ```
64  /// use slack_blocks::elems::select;
65  ///
66  /// let select = select::multi::PublicChannel::builder().placeholder(
67  ///                           r#"Hey I really would appreciate it if you chose
68  ///         a channel relatively soon, so that we can figure out
69  ///         where we need to send this poll, ok? it's kind of
70  ///         important that you specify where this poll should be
71  ///         sent, in case we haven't made that super clear.
72  ///         If you understand, could you pick a channel, already??"#,
73  /// )
74  ///              .action_id("ABC123")
75  ///              .build();
76  ///
77  /// assert!(matches!(select.validate(), Err(_)))
78  /// ```
79  #[cfg(feature = "validation")]
80  #[cfg_attr(docsrs, doc(cfg(feature = "validation")))]
81  pub fn validate(&self) -> ValidationResult {
82    Validate::validate(&self)
83  }
84}