Skip to content

Views

Views are app-customized visual areas within modals and Home tabs.

See: https://api.slack.com/reference/surfaces/views.

HomeTabView

HomeTabViews are used with the views.publish Web API method.

See: https://api.slack.com/reference/surfaces/views#home.

Parameters:

Name Type Description Default
blocks Union[Block, List[Block]]

A list of blocks that defines the content of the view (max 100).

required
private_metadata Optional[str]

a string (max 3000 chars) that will be sent to your app in view_submission.

None
callback_id Optional[str]

A string that will identify submissions of this view.

None
external_id Optional[str]

A custom identifier that is unique within the views of a given Slack team.

None
Source code in slackblocks/views.py
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
class HomeTabView(View):
    """
    `HomeTabViews` are used with the `views.publish` Web API method.

    See: <https://api.slack.com/reference/surfaces/views#home>.

    Args:
        blocks: A list of blocks that defines the content of the view (max 100).
        private_metadata: a string (max 3000 chars) that will be sent to your app
            in `view_submission`.
        callback_id: A string that will identify submissions of this view.
        external_id: A custom identifier that is unique within the views of a
            given Slack team.
    """

    def __init__(
        self,
        blocks: Union[Block, List[Block]],
        private_metadata: Optional[str] = None,
        callback_id: Optional[str] = None,
        external_id: Optional[str] = None,
    ) -> "HomeTabView":
        super().__init__(
            type=ViewType.HOME,
            blocks=blocks,
            private_metadata=private_metadata,
            callback_id=callback_id,
            external_id=external_id,
        )

ModalView

Modal views are used with the views.open, views.update and views.push Slack Web API methods.

See: https://api.slack.com/reference/surfaces/views#modal

Parameters:

Name Type Description Default
title TextLike

heading that appears at the top left of the view.

required
blocks Union[Block, List[Block]]

a list of blocks (max 100) that define the content of the view.

required
close Optional[TextLike]

the text of the close button (max 24 chars) in the view. Must be Text.PLAINTEXT.

None
submit Optional[TextLike]

the text of the submit button (max 24 chars) in the view. Must be Text.PLAINTEXT.

None
private_metadata Optional[str]

a string (max 3000 chars) that will be sent to your app in view_submission.

None
callback_id Optional[str]

A string that will identify submissions of this view.

None
clear_on_close Optional[bool]

when True all views in the model will be cleared when it is closed.

False
notify_on_close Optional[bool]

when True a view_closed event will be sent when the modal is closed.

False
external_id Optional[str]

A custom identifier that is unique within the views of a given Slack team.

None
submit_disabled Optional[bool]

when True disabled submitting the form until one or more inputs have been provided. Used only for configuaration models.

False
Source code in slackblocks/views.py
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
class ModalView(View):
    """
    Modal views are used with the `views.open`, `views.update` and `views.push`
        Slack Web API methods.

    See: <https://api.slack.com/reference/surfaces/views#modal>

    Args:
        title: heading that appears at the top left of the view.
        blocks: a list of blocks (max 100) that define the content of the view.
        close: the text of the close button (max 24 chars) in the view.
            Must be `Text.PLAINTEXT`.
        submit: the text of the submit button (max 24 chars) in the view.
            Must be `Text.PLAINTEXT`.
        private_metadata: a string (max 3000 chars) that will be sent to your app
            in `view_submission`.
        callback_id: A string that will identify submissions of this view.
        clear_on_close: when `True` all views in the model will be cleared when
            it is closed.
        notify_on_close: when `True` a `view_closed` event will be sent when the
            modal is closed.
        external_id: A custom identifier that is unique within the views of a
            given Slack team.
        submit_disabled: when `True` disabled submitting the form until one or
            more inputs have been provided. Used only for
            [`configuaration models`](https://api.slack.com/reference/workflows/configuration-view).
    """

    def __init__(
        self,
        title: TextLike,
        blocks: Union[Block, List[Block]],
        close: Optional[TextLike] = None,
        submit: Optional[TextLike] = None,
        private_metadata: Optional[str] = None,
        callback_id: Optional[str] = None,
        clear_on_close: Optional[bool] = False,
        notify_on_close: Optional[bool] = False,
        external_id: Optional[str] = None,
        submit_disabled: Optional[bool] = False,
    ):
        super().__init__(
            type=ViewType.MODAL,
            blocks=blocks,
            private_metadata=private_metadata,
            callback_id=callback_id,
            external_id=external_id,
        )
        self.title = Text.to_text(title, force_plaintext=True, max_length=24)
        self.close = Text.to_text(
            close, force_plaintext=True, max_length=24, allow_none=True
        )
        self.submit = Text.to_text(
            submit, force_plaintext=True, max_length=24, allow_none=True
        )
        self.clear_on_close = clear_on_close
        self.notify_on_close = notify_on_close
        self.submit_disabled = submit_disabled

    def _resolve(self) -> Dict[str, Any]:
        modal_view = super()._resolve()
        modal_view["title"] = self.title._resolve()
        if self.close:
            modal_view["close"] = self.close._resolve()
        if self.submit:
            modal_view["submit"] = self.submit._resolve()
        if self.clear_on_close:
            modal_view["clear_on_close"] = self.clear_on_close
        if self.notify_on_close:
            modal_view["notify_on_close"] = self.notify_on_close
        if self.submit_disabled:
            modal_view["submit_disabled"] = self.submit_disabled
        return modal_view