mattermost_client/posts/
create.rs

1use crate::openapi::{
2    apis::{posts_api as apis, Result},
3    models::{self, CreatePostRequestMetadata},
4};
5use typed_builder::TypedBuilder;
6
7use crate::Client;
8
9#[derive(Debug, TypedBuilder)]
10#[builder(doc, field_defaults(default, setter(strip_option)))]
11pub struct CreatePost {
12    /// The channel ID to post in
13    #[builder(!default, setter(into, !strip_option))]
14    pub channel_id: String,
15    /// The message contents, can be formatted with Markdown
16    #[builder(!default, setter(into, !strip_option))]
17    pub message: String,
18    /// The post ID to comment on
19    pub root_id: Option<String>,
20    /// A list of file IDs to associate with the post. Note that posts are limited to 5 files maximum. Please use additional posts for more files.
21    pub file_ids: Option<Vec<String>>,
22    /// A general JSON property bag to attach to the post
23    pub props: Option<serde_json::Value>,
24    pub metadata: Option<CreatePostRequestMetadata>,
25    /// Whether to set the user status as online or not
26    pub set_online: Option<bool>,
27}
28
29impl CreatePost {
30    pub async fn send(self, client: &Client) -> Result<models::Post, apis::CreatePostError> {
31        let params = apis::CreatePostParams {
32            create_post_request: models::CreatePostRequest {
33                channel_id: self.channel_id,
34                message: self.message,
35                root_id: self.root_id,
36                file_ids: self.file_ids,
37                props: self.props,
38                metadata: self.metadata.map(Box::new),
39            },
40            set_online: self.set_online,
41        };
42
43        apis::create_post(client.configuration(), params).await
44    }
45}