Struct slack_blocks::block_elements::Button [−][src]
pub struct Button { /* fields omitted */ }
Expand description
Button
Works with block types:
An interactive component that inserts a button. The button can be a trigger for anything from opening a simple link to starting a complex workflow.
To use interactive components, you will need to make some changes to prepare your app.
Read our guide to enabling interactivity 🔗.
Implementations
impl Button
[src]
impl Button
[src]pub fn from_text_and_action_id(
text: impl Into<Plain>,
action_id: impl ToString
) -> Self
[src]
pub fn from_text_and_action_id(
text: impl Into<Plain>,
action_id: impl ToString
) -> Self
[src]Create a button::Contents
from a text label and ID for your app
to be able to identify what was pressed.
Arguments
text
- A text object 🔗 that defines the button’s text. Can only be of type:plain_text
. Maximum length for the text in this field is 75 characters.action_id
- An identifier for this action. You can use this when you receive an interaction payload to identify the source of the action 🔗. Should be unique among all otheraction_id
s used elsewhere by your app. Maximum length for this field is 255 characters.
Example
use slack_blocks::blocks::{Block, actions}; use slack_blocks::block_elements; let btn = block_elements::Button::from_text_and_action_id("Button", "123"); let actions_block: Block = actions::Contents::from_action_elements(vec![btn.into()]).into(); // < send block to slack's API >
pub fn with_url(self, url: impl ToString) -> Self
[src]
pub fn with_url(self, url: impl ToString) -> Self
[src]Configure a button to be a link to an external URL to load in the user’s browser on click.
Arguments
url
- A URL to load in the user’s browser when the button is clicked. Maximum length for this field is 3000 characters. If you’re using url, you’ll still receive an interaction payload 🔗 and will need to send an acknowledgement response 🔗.
Example
use slack_blocks::blocks::{Block, actions}; use slack_blocks::block_elements; let btn = block_elements::Button::from_text_and_action_id("Go to cheese!", "123").with_url("https://www.cheese.com/"); let actions_block: Block = actions::Contents::from_action_elements(vec![btn.into()]).into(); // < send block to slack's API >
pub fn with_value(self, value: impl ToString) -> Self
[src]
pub fn with_value(self, value: impl ToString) -> Self
[src]Add a meaningful value to send back to your app when this button is clicked.
Arguments
value
- The value to send along with the interaction payload. Maximum length for this field is 2000 characters.
Example
use slack_blocks::blocks::{Block, actions}; use slack_blocks::block_elements; let btn = block_elements::Button::from_text_and_action_id("Click me!", "123") .with_value("<something that will help your system better act on the interaction>"); let actions_block: Block = actions::Contents::from_action_elements(vec![btn.into()]).into(); // < send block to slack's API >
pub fn with_style(self, style: Style) -> Self
[src]
pub fn with_style(self, style: Style) -> Self
[src]Decorates buttons with alternative visual color schemes. Use this option with restraint.
If this method is not called, the default button style will be used.
Arguments
style
- The style to decorate your button with.
Example
use slack_blocks::blocks::{Block, actions}; use slack_blocks::block_elements::{Button, button::Style}; let confirm_btn = Button::from_text_and_action_id("Confirm!", "123") .with_style(Style::Primary); let deny_btn = Button::from_text_and_action_id("Deny!", "123") .with_style(Style::Danger); let actions_block: Block = actions::Contents::from_action_elements( vec![confirm_btn.into(), deny_btn.into()] ).into(); // < send block to slack's API >
pub fn validate(&self) -> Result<(), ValidationErrors>
[src]
pub fn validate(&self) -> Result<(), ValidationErrors>
[src]Validate that this Button element agrees with Slack’s model requirements
Errors
- If
from_text_and_action_id
was called with an action_id longer than 255 chars - If
from_text_and_action_id
was called with text longer than 75 chars - If
with_url
was called with url longer than 3000 chars - If
with_value
was called with url longer than 2000 chars
Example
use slack_blocks::block_elements::Button; let long_string = std::iter::repeat(' ').take(256).collect::<String>(); let btn = Button::from_text_and_action_id("Button", long_string); assert_eq!(true, matches!(btn.validate(), Err(_)));
Trait Implementations
impl<'de> Deserialize<'de> for Button
[src]
impl<'de> Deserialize<'de> for Button
[src]fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[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 From<Button> for BlockElement<'static>
[src]
impl From<Button> for BlockElement<'static>
[src]impl From<Button> for BlockElement<'static>
[src]
impl From<Button> for BlockElement<'static>
[src]impl StructuralPartialEq for Button
[src]
Auto Trait Implementations
impl RefUnwindSafe for Button
impl Send for Button
impl Sync for Button
impl Unpin for Button
impl UnwindSafe for Button
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
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]
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> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,