Struct slack_blocks::blocks::Input[][src]

pub struct Input<'a> { /* fields omitted */ }
Expand description

Input Block

slack api docs 🔗

A block that collects information from users -

Read slack’s guide to using modals 🔗 to learn how input blocks pass information to your app.

Implementations

impl<'a> Input<'a>[src]

pub fn builder() -> InputBuilderInit<'a>[src]

Build a new input block

For example, see blocks::input::build::InputBuilder.

pub fn from_label_and_element(
    label: impl Into<Plain>,
    element: impl Into<SupportedElement<'a>>
) -> Self
[src]

Create an Input Block from a text Label and interactive element.

Arguments

  • label - A label that appears above an input element in the form of a text object 🔗 that must have type of plain_text. Maximum length for the text in this field is 2000 characters.

  • element - An interactive block_element that will be used to gather the input for this block. For the kinds of Elements supported by Input blocks, see the SupportedElement enum. For info about Block Elements in general, see the elems module.

Example

use slack_blocks::elems::Select;
use slack_blocks::blocks;

let label = "On a scale from 1 - 5, how angsty are you?";
let input = Select::from_placeholder_and_action_id("Pick a channel...", "ABC123")
    .choose_from_public_channels();

let block = blocks::Input::from_label_and_element(label, input);

// < send to slack API >

pub fn with_block_id(self, block_id: impl Into<Cow<'a, str>>) -> Self[src]

Set a unique block_id to identify this instance of an Input Block.

Arguments

  • block_id - A string acting as a unique identifier for a block. You can use this block_id when you receive an interaction payload to identify the source of the action 🔗. If not specified, one will be generated. Maximum length for this field is 255 characters. block_id should be unique for each message and each iteration of a message. If a message is updated, use a new block_id.

Example

use slack_blocks::elems::Select;
use slack_blocks::blocks;

let label = "On a scale from 1 - 5, how angsty are you?";
let input = Select::from_placeholder_and_action_id("Pick a channel...", "ABC123")
    .choose_from_public_channels();

let block = blocks::Input
    ::from_label_and_element(label, input)
    .with_block_id("angst_rating_12345");

// < send to slack API >

pub fn with_hint(self, hint: impl Into<Plain>) -> Self[src]

Set the hint on this Input Block that appears below an input element in a lighter grey.

Arguments

  • hint - An optional hint that appears below an input element in a lighter grey. It must be a a text object 🔗 with a type of plain_text. Maximum length for the text in this field is 2000 characters.

Example

use slack_blocks::elems::Select;
use slack_blocks::blocks;

let label = "On a scale from 1 - 5, how angsty are you?";
let input = Select::from_placeholder_and_action_id("Pick a channel...", "ABC123")
    .choose_from_public_channels();

let block = blocks::Input
    ::from_label_and_element(label, input)
    .with_hint("PSST hey! Don't let them know how angsty you are!");

// < send to slack API >

pub fn with_optional(self, optionality: bool) -> Self[src]

Set whether or not this input is Optional.

Arguments

  • optionality - A boolean that indicates whether the input element may be empty when a user submits the modal. Defaults to false.

Example

use slack_blocks::elems::Select;
use slack_blocks::blocks;

let label = "On a scale from 1 - 5, how angsty are you?";
let input = Select::from_placeholder_and_action_id("Pick a channel...", "ABC123")
    .choose_from_public_channels();

let block = blocks::Input
    ::from_label_and_element(label, input)
    .with_hint("PSST hey! Don't even answer that!")
    .with_optional(true);

// < send to slack API >

pub fn dispatch_block_actions(self) -> Self[src]

Will allow the elements in this block to dispatch block_actions payloads. Defaults to false.

pub fn validate(&self) -> Result<(), ValidationErrors>[src]

Validate that this Input block agrees with Slack’s model requirements

Errors

  • If from_label_and_element was passed a Text object longer than 2000 chars
  • If with_hint was called with a block id longer than 2000 chars
  • If with_block_id was called with a block id longer than 256 chars

Example

use slack_blocks::elems::Select;
use slack_blocks::blocks;

let label = "On a scale from 1 - 5, how angsty are you?";
let input = Select::from_placeholder_and_action_id("Pick a channel...", "ABC123")
    .choose_from_public_channels();
let long_string = std::iter::repeat(' ').take(2001).collect::<String>();

let block = blocks::Input
    ::from_label_and_element(label, input)
    .with_block_id(long_string);

assert_eq!(true, matches!(block.validate(), Err(_)));

// < send to slack API >

Trait Implementations

impl<'a> Clone for Input<'a>[src]

fn clone(&self) -> Input<'a>[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<'a> Debug for Input<'a>[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl<'de, 'a> Deserialize<'de> for Input<'a>[src]

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
    __D: Deserializer<'de>, 
[src]

Deserialize this value from the given Serde deserializer. Read more

impl<'a> From<Input<'a>> for Block<'a>[src]

fn from(src: Input<'a>) -> Self[src]

Performs the conversion.

impl<'a> Hash for Input<'a>[src]

fn hash<__H: Hasher>(&self, state: &mut __H)[src]

Feeds this value into the given Hasher. Read more

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given Hasher. Read more

impl<'a> PartialEq<Input<'a>> for Input<'a>[src]

fn eq(&self, other: &Input<'a>) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &Input<'a>) -> bool[src]

This method tests for !=.

impl<'a> Serialize for Input<'a>[src]

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
    __S: Serializer
[src]

Serialize this value into the given Serde serializer. Read more

impl<'a> Validate for Input<'a>[src]

impl<'a> StructuralPartialEq for Input<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for Input<'a>

impl<'a> Send for Input<'a>

impl<'a> Sync for Input<'a>

impl<'a> Unpin for Input<'a>

impl<'a> UnwindSafe for Input<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]