Skip to main content

slack_web_api/api/
blocks.rs

1// このファイルは codegen/generate.py が生成する。手で編集しない
2
3#![allow(unused_imports)]
4
5use crate::objects::*;
6use crate::{
7    CursorPaginated, NextCursor, ResponseMetadata, SlackApiMethod, SlackClient, SlackError,
8};
9use serde::{Deserialize, Serialize};
10
11/// Arguments for the Slack Web API method [`blocks.validate`](https://docs.slack.dev/reference/methods/blocks.validate): Validates blocks, messages, and views Block Kit JSON payloads.
12///
13/// Send it with [`SlackClient::blocks_validate`].
14#[doc(alias = "blocks.validate")]
15#[derive(Debug, Clone, PartialEq, Serialize, Default)]
16#[non_exhaustive]
17pub struct BlocksValidateRequest {
18    /// A JSON-encoded array of [structured blocks](https://docs.slack.dev/reference/block-kit/blocks.md). Provide exactly one of `blocks`, `view`, or `message`.
19    #[serde(
20        skip_serializing_if = "Option::is_none",
21        serialize_with = "crate::form::as_json"
22    )]
23    pub blocks: Option<Vec<crate::blocks::Block>>,
24    /// A JSON-encoded [message payload](https://docs.slack.dev/messaging/creating-interactive-messages.md) to validate. Provide exactly one of `blocks`, `view`, or `message`.
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub message: Option<String>,
27    /// A JSON-encoded [view payload](https://docs.slack.dev/reference/views.md) to validate. Provide exactly one of `blocks`, `view`, or `message`.
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub view: Option<crate::blocks::View>,
30}
31
32impl BlocksValidateRequest {
33    pub fn new() -> Self {
34        Self {
35            blocks: None,
36            message: None,
37            view: None,
38        }
39    }
40
41    pub fn blocks(mut self, blocks: Vec<crate::blocks::Block>) -> Self {
42        self.blocks = Some(blocks);
43        self
44    }
45
46    pub fn message(mut self, message: impl Into<String>) -> Self {
47        self.message = Some(message.into());
48        self
49    }
50
51    pub fn view(mut self, view: crate::blocks::View) -> Self {
52        self.view = Some(view);
53        self
54    }
55}
56
57impl SlackApiMethod for BlocksValidateRequest {
58    const METHOD: &'static str = "blocks.validate";
59    type Response = BlocksValidateResponse;
60}
61
62/// Successful response of the Slack Web API method [`blocks.validate`](https://docs.slack.dev/reference/methods/blocks.validate).
63#[doc(alias = "blocks.validate")]
64#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
65pub struct BlocksValidateResponse {
66    /// Fields returned by Slack. This method has no documented response example.
67    #[serde(flatten)]
68    pub extra: serde_json::Map<String, serde_json::Value>,
69    #[serde(
70        default,
71        deserialize_with = "crate::de::opt_object",
72        skip_serializing_if = "Option::is_none"
73    )]
74    pub response_metadata: Option<ResponseMetadata>,
75    #[serde(
76        default,
77        deserialize_with = "crate::de::opt_string",
78        skip_serializing_if = "Option::is_none"
79    )]
80    pub warning: Option<String>,
81}
82
83impl SlackClient {
84    /// Calls the Slack Web API method [`blocks.validate`](https://docs.slack.dev/reference/methods/blocks.validate): Validates blocks, messages, and views Block Kit JSON payloads.
85    ///
86    /// # Errors
87    ///
88    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
89    #[doc(alias = "blocks.validate")]
90    pub async fn blocks_validate(
91        &self,
92        request: &BlocksValidateRequest,
93    ) -> Result<BlocksValidateResponse, SlackError> {
94        self.call(request).await
95    }
96}