pub struct MessageBuilder { /* private fields */ }
Expand description

Builder for Message object.

Implementations§

source§

impl MessageBuilder

source

pub fn set_text(self, text: Option<String>) -> Self

Set text field.

let message = Message::builder()
    .set_text(Some("New Paid Time Off request from Fred Enriquez".into()))
    .build();

let expected = serde_json::json!({
    "text": "New Paid Time Off request from Fred Enriquez",
});

let json = serde_json::to_value(message).unwrap();

assert_eq!(json, expected);
source

pub fn text(self, text: impl Into<String>) -> Self

Set text field.

let message = Message::builder()
    .text("New Paid Time Off request from Fred Enriquez")
    .build();

let expected = serde_json::json!({
    "text": "New Paid Time Off request from Fred Enriquez",
});

let json = serde_json::to_value(message).unwrap();

assert_eq!(json, expected);
source

pub fn set_blocks(self, blocks: Vec<Block>) -> Self

Set blocks field. The argument is a vector composed from any objects that can transform into the enum Block.

let message = Message::builder()
    .set_blocks(
        vec![
            Header::builder()
                .text("New request")
                .build()
                .into(),
            Section::builder()
                .text(mrkdwn!("<https://example.com|View request>"))
                .build()
                .into(),
        ]
    )
    .build();

let expected = serde_json::json!({
    "blocks": [
        {
            "type": "header",
            "text": {
                "type": "plain_text",
                "text": "New request"
            }
        },
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "<https://example.com|View request>"
            }
        }
    ]
});

let json = serde_json::to_value(message).unwrap();

assert_eq!(json, expected);
source

pub fn block(self, block: impl Into<Block>) -> Self

Add an object to blocks field. The argument is an any object that can transform into the enum Block.

let message = Message::builder()
    .block(
        Header::builder()
            .text("New request")
            .build()
    )
    .block(
        Section::builder()
            .text(mrkdwn!("<https://example.com|View request>"))
            .build()
    )
    .build();

let expected = serde_json::json!({
    "blocks": [
        {
            "type": "header",
            "text": {
                "type": "plain_text",
                "text": "New request"
            }
        },
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "<https://example.com|View request>"
            }
        }
    ]
});

let json = serde_json::to_value(message).unwrap();

assert_eq!(json, expected);
source

pub fn set_thread_ts(self, thread_ts: Option<String>) -> Self

Set thread_ts field.

let message = Message::builder()
    .set_thread_ts(Some("some ts value".into()))
    .build();

let expected = serde_json::json!({
    "thread_ts": "some ts value",
});

let json = serde_json::to_value(message).unwrap();

assert_eq!(json, expected);
source

pub fn thread_ts(self, thread_ts: impl Into<String>) -> Self

Set thread_ts field.

let message = Message::builder()
    .thread_ts("some ts value")
    .build();

let expected = serde_json::json!({
    "thread_ts": "some ts value",
});

let json = serde_json::to_value(message).unwrap();

assert_eq!(json, expected);
source

pub fn set_mrkdwn(self, mrkdwn: Option<bool>) -> Self

Set mrkdwn field.

let message = Message::builder()
    .set_mrkdwn(Some(true))
    .build();

let expected = serde_json::json!({
    "mrkdwn": true,
});

let json = serde_json::to_value(message).unwrap();

assert_eq!(json, expected);
source

pub fn mrkdwn(self, mrkdwn: bool) -> Self

Set mrkdwn field.

let message = Message::builder()
    .mrkdwn(true)
    .build();

let expected = serde_json::json!({
    "mrkdwn": true,
});

let json = serde_json::to_value(message).unwrap();

assert_eq!(json, expected);
source

pub fn build(self) -> Message

Build a Message object.

source

pub fn get_text(&self) -> &Option<String>

Get text value.

source

pub fn get_blocks(&self) -> &[Block]

Get blocks value.

source

pub fn get_thread_ts(&self) -> &Option<String>

Get thread_ts value.

source

pub fn get_mrkdwn(&self) -> &Option<bool>

Get mrkdwn value.

Trait Implementations§

source§

impl Debug for MessageBuilder

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for MessageBuilder

source§

fn default() -> MessageBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.