[][src]Struct slack_blocks::blocks::input::Contents

pub struct Contents { /* fields omitted */ }

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 Contents[src]

pub fn from_label_and_element<Label: Into<Text>, El: Into<InputElement>>(
    label: Label,
    element: El
) -> 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 InputElement enum. For info about Block Elements in general, see the block_elements module.

Example

use slack_blocks::block_elements::select;
use slack_blocks::blocks;
use slack_blocks::compose;

let label = compose::Text::plain("On a scale from 1 - 5, how angsty are you?");
let input = select::Static {};

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

// < send to slack API >

pub fn with_block_id<StrIsh: AsRef<str>>(self, block_id: StrIsh) -> 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::block_elements::select;
use slack_blocks::blocks;
use slack_blocks::compose;

let label = compose::Text::plain("On a scale from 1 - 5, how angsty are you?");
let input = select::Static {};

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

// < send to slack API >

pub fn with_hint<IntoText: Into<Text>>(self, hint: IntoText) -> 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::block_elements::select;
use slack_blocks::blocks;
use slack_blocks::compose;

let label = compose::Text::plain("On a scale from 1 - 5, how angsty are you?");
let input = select::Static {};

let block = blocks::input
    ::Contents
    ::from_label_and_element(label, input)
    .with_hint(compose::Text::plain("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::block_elements::select;
use slack_blocks::blocks;
use slack_blocks::compose;

let label = compose::Text::plain("On a scale from 1 - 5, how angsty are you?");
let input = select::Static {};

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

// < send to slack API >

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::block_elements::select;
use slack_blocks::blocks;
use slack_blocks::compose;

let label = compose::Text::plain("On a scale from 1 - 5, how angsty are you?");
let input = select::Static {};
let long_string = std::iter::repeat(' ').take(2001).collect::<String>();

let block = blocks::input
    ::Contents
    ::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 Clone for Contents[src]

impl Debug for Contents[src]

impl<'de> Deserialize<'de> for Contents[src]

impl From<Contents> for Block[src]

impl Hash for Contents[src]

impl PartialEq<Contents> for Contents[src]

impl Serialize for Contents[src]

impl StructuralPartialEq for Contents[src]

impl Validate for Contents[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

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

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

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

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

type Owned = T

The resulting type after obtaining ownership.

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.

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.