pub struct Message { /* private fields */ }Expand description
Message
representation.
See also Header, Section and any other blocks to know how to build these blocks.
Every block and its components have each builder and their build method returns Result.
For example, according to the official document, you can include up to 50 blocks in each message. If you include more than 50 blocks in a message, the build method of MessageBuilder returns Result::Err.
§Fields and Validations
For more details, see the official documentation.
| Field | Type | Required | Validation |
|---|---|---|---|
| text | String | No | N/A |
| blocks | Vec<Block> | No | Maximum 50 items |
| thread_ts | String | No | N/A |
| mrkdwn | bool | No | N/A |
| response_type | String | No | N/A |
| replace_original | bool | No | N/A |
| delete_original | bool | No | N/A |
| reply_broadcast | bool | No | N/A |
§Example
use slack_messaging::{mrkdwn, plain_text, Message};
use slack_messaging::blocks::{Header, Section};
let message = Message::builder()
.text("New Paid Time Off request from Fred Enriquez")
.block(
Header::builder()
.text(plain_text!("New request")?)
.build()?
)
.block(
Section::builder()
.field(mrkdwn!("*Type:*\nPaid Time Off")?)
.field(mrkdwn!("*Created by:*\n<example.com|Fred Enriquez>")?)
.build()?
)
.block(
Section::builder()
.field(mrkdwn!("*When:*\nAug 10 - Aug 13")?)
.build()?
)
.block(
Section::builder()
.text(mrkdwn!("<https://example.com|View request>")?)
.build()?
)
.build()?;
let expected = serde_json::json!({
"text": "New Paid Time Off request from Fred Enriquez",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "New request"
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Type:*\nPaid Time Off"
},
{
"type": "mrkdwn",
"text": "*Created by:*\n<example.com|Fred Enriquez>"
}
]
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*When:*\nAug 10 - Aug 13"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<https://example.com|View request>"
}
}
]
});
let json = serde_json::to_value(message)?;
assert_eq!(json, expected);Implementations§
Source§impl Message
impl Message
Sourcepub fn builder() -> MessageBuilder
pub fn builder() -> MessageBuilder
constract MessageBuilder object.
Trait Implementations§
impl StructuralPartialEq for Message
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnwindSafe for Message
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)