slackline/view
This module is generated by gleam run -m slackline_codegen/generate. Do not edit it by hand.
Views: modals and App Home tabs, plus the state Slack reports back for their input elements.
One View record covers both surfaces. view_type says which. Fields
that Slack only adds in responses and payloads (id, hash, state,
…) are optional. Use modal and home to build views with the fields
that each surface requires.
Reference: https://docs.slack.dev/reference/views
Types
An optional field of a view, for modal and home.
Modals and Home tabs share one View record, but some fields only work on
modals. kind records which surface an attribute is for, so a modal-only
attribute on a Home tab does not compile. callback_id and the other
shared attributes work on both. submit, close and the other modal
attributes only work on modal.
pub opaque type Attr(kind)
A modal or Home tab view. https://docs.slack.dev/reference/views/modal-views https://docs.slack.dev/reference/views/home-tab-views
pub type View {
View(
view_type: ViewType,
blocks: List(block.Block),
title: option.Option(block.PlainText),
close: option.Option(block.PlainText),
submit: option.Option(block.PlainText),
private_metadata: option.Option(String),
callback_id: option.Option(String),
clear_on_close: option.Option(Bool),
notify_on_close: option.Option(Bool),
external_id: option.Option(String),
submit_disabled: option.Option(Bool),
id: option.Option(String),
team_id: option.Option(String),
state: option.Option(ViewState),
hash: option.Option(String),
previous_view_id: option.Option(String),
root_view_id: option.Option(String),
app_id: option.Option(String),
bot_id: option.Option(String),
app_installed_team_id: option.Option(String),
)
}
Constructors
-
View( view_type: ViewType, blocks: List(block.Block), title: option.Option(block.PlainText), close: option.Option(block.PlainText), submit: option.Option(block.PlainText), private_metadata: option.Option(String), callback_id: option.Option(String), clear_on_close: option.Option(Bool), notify_on_close: option.Option(Bool), external_id: option.Option(String), submit_disabled: option.Option(Bool), id: option.Option(String), team_id: option.Option(String), state: option.Option(ViewState), hash: option.Option(String), previous_view_id: option.Option(String), root_view_id: option.Option(String), app_id: option.Option(String), bot_id: option.Option(String), app_installed_team_id: option.Option(String), )Arguments
- view_type
-
modalorhome. - blocks
-
The content of the view. Maximum 100 blocks.
- title
-
Modal title, top left. Required for modals. Maximum 24 characters.
- close
-
Modal close button text. Maximum 24 characters.
- submit
-
Modal submit button text. Required when
blockscontains an input block. Maximum 24 characters. - private_metadata
-
Sent back to your app in
view_submissionandblock_actionspayloads. Maximum 3000 characters. - callback_id
-
Identifies interactions with this view. Maximum 255 characters.
- clear_on_close
-
Modals: close clears every view in the stack. Defaults to
false. - notify_on_close
-
Modals: send a
view_closedevent on close. Defaults tofalse. - external_id
-
A custom identifier, unique per team.
- submit_disabled
-
Configuration modals: disable submit until inputs are completed.
- id
-
The view ID. Set by Slack.
- team_id
-
The workspace the view belongs to. Set by Slack.
- state
-
Current values of the input elements. Set by Slack.
- hash
-
Pass to
views.updateto avoid race conditions. Set by Slack. - previous_view_id
-
The view this one was pushed on top of. Set by Slack.
- root_view_id
-
The first view of the modal stack. Set by Slack.
- app_id
-
The app that owns the view. Set by Slack.
- bot_id
-
The bot user of the app. Set by Slack.
- app_installed_team_id
-
The workspace the app is installed on. Set by Slack.
The state of a view’s input elements.
pub type ViewState {
ViewState(
values: dict.Dict(String, dict.Dict(String, ViewStateValue)),
)
}
Constructors
-
ViewState( values: dict.Dict(String, dict.Dict(String, ViewStateValue)), )Arguments
- values
-
block_idtoaction_idto the element’s value.
The value of one input element in a view’s state. Which field is set depends on the element type. https://docs.slack.dev/reference/interaction-payloads/view-interactions-payload
pub type ViewStateValue {
StatePlainTextInput(value: option.Option(String))
StateEmailTextInput(value: option.Option(String))
StateUrlTextInput(value: option.Option(String))
StateNumberInput(value: option.Option(String))
StateStaticSelect(
selected_option: option.Option(block.SelectOption),
)
StateExternalSelect(
selected_option: option.Option(block.SelectOption),
)
StateMultiStaticSelect(
selected_options: option.Option(List(block.SelectOption)),
)
StateMultiExternalSelect(
selected_options: option.Option(List(block.SelectOption)),
)
StateUsersSelect(selected_user: option.Option(String))
StateMultiUsersSelect(
selected_users: option.Option(List(String)),
)
StateConversationsSelect(
selected_conversation: option.Option(String),
)
StateMultiConversationsSelect(
selected_conversations: option.Option(List(String)),
)
StateChannelsSelect(selected_channel: option.Option(String))
StateMultiChannelsSelect(
selected_channels: option.Option(List(String)),
)
StateDatepicker(selected_date: option.Option(String))
StateTimepicker(
selected_time: option.Option(String),
timezone: option.Option(String),
)
StateDatetimepicker(selected_date_time: option.Option(Int))
StateCheckboxes(
selected_options: option.Option(List(block.SelectOption)),
)
StateRadioButtons(
selected_option: option.Option(block.SelectOption),
)
StateRichTextInput(
rich_text_value: option.Option(block.RichText),
)
StateFileInput(files: option.Option(List(value.Value)))
UnknownViewStateValue(type_: String, raw: value.Value)
}
Constructors
-
StatePlainTextInput(value: option.Option(String)) -
StateEmailTextInput(value: option.Option(String)) -
StateUrlTextInput(value: option.Option(String)) -
StateNumberInput(value: option.Option(String))The number as typed, for example
"4.5". -
StateStaticSelect( selected_option: option.Option(block.SelectOption), ) -
StateExternalSelect( selected_option: option.Option(block.SelectOption), ) -
StateMultiStaticSelect( selected_options: option.Option(List(block.SelectOption)), ) -
StateMultiExternalSelect( selected_options: option.Option(List(block.SelectOption)), ) -
StateUsersSelect(selected_user: option.Option(String)) -
StateMultiUsersSelect( selected_users: option.Option(List(String)), ) -
StateConversationsSelect( selected_conversation: option.Option(String), ) -
StateMultiConversationsSelect( selected_conversations: option.Option(List(String)), ) -
StateChannelsSelect(selected_channel: option.Option(String)) -
StateMultiChannelsSelect( selected_channels: option.Option(List(String)), ) -
StateDatepicker(selected_date: option.Option(String))YYYY-MM-DD. -
StateTimepicker( selected_time: option.Option(String), timezone: option.Option(String), )HH:mm, with the timezone configured on the element. -
StateDatetimepicker(selected_date_time: option.Option(Int))A UNIX timestamp in seconds.
-
StateCheckboxes( selected_options: option.Option(List(block.SelectOption)), ) -
StateRadioButtons( selected_option: option.Option(block.SelectOption), ) -
StateRichTextInput( rich_text_value: option.Option(block.RichText), ) -
StateFileInput(files: option.Option(List(value.Value)))The uploaded files, as file objects (raw json, since the file module comes later in the dependency order).
-
UnknownViewStateValue(type_: String, raw: value.Value)A
typethat this version of slackline does not know.rawholds the full json.
Values
pub fn callback_id(callback_id: String) -> Attr(kind)
Identifies interactions with the view, such as its view_submission.
Maximum 255 characters.
pub fn clear_on_close(clear_on_close: Bool) -> Attr(Modal)
Whether closing the modal clears every view in the stack.
pub fn external_id(external_id: String) -> Attr(kind)
A custom identifier, unique per team.
pub fn home(
blocks blocks: List(block.Block),
with attrs: List(Attr(Home)),
) -> View
An App Home tab view, for views.publish.
pub fn input(
view: View,
block_id block_id: String,
action_id action_id: String,
) -> option.Option(ViewStateValue)
The value of the element with action_id in the block with block_id,
in a submitted view.
view.input(submission.view, block_id: "due", action_id: "due")
|> option.then(view.selected_value)
pub fn input_text(
view: View,
block_id block_id: String,
action_id action_id: String,
) -> option.Option(String)
The text typed into an input in a submitted view.
view.input_text(submission.view, block_id: "thoughts", action_id: "thoughts")
pub fn modal(
title title: String,
blocks blocks: List(block.Block),
with attrs: List(Attr(Modal)),
) -> View
A modal with a plain text title (maximum 24 characters). Set submit
when the blocks contain an input block:
view.modal(
"Feedback",
[block.input("Thoughts", element.plain_text_input("thoughts", []), [])],
[view.callback_id("feedback"), view.submit("Send")],
)
pub fn notify_on_close(notify_on_close: Bool) -> Attr(Modal)
Whether closing the modal sends a view_closed payload.
pub fn private_metadata(private_metadata: String) -> Attr(kind)
Sent back to your app in view_submission and block_actions payloads.
Maximum 3000 characters.
pub fn selected_value(
value: ViewStateValue,
) -> option.Option(String)
The selected value of a single-select menu, radio buttons, a user,
channel or conversation select, or a date, time or datetime picker. An
option gives its value. A datetime picker gives its Unix timestamp as
a string. Use selected_values for checkboxes and multi-select menus.
pub fn selected_values(value: ViewStateValue) -> List(String)
The selected values of checkboxes or a multi-select menu. An option gives
its value. A user, channel or conversation select gives its IDs. Other
elements give an empty list.
pub fn state_value(
state: ViewState,
block_id block_id: String,
action_id action_id: String,
) -> Result(ViewStateValue, Nil)
Looks up the value of the element with action_id in the block with
block_id.
pub fn submit(text: String) -> Attr(Modal)
The submit button text. Required when the blocks contain an input block. Maximum 24 characters.
pub fn submit_disabled(submit_disabled: Bool) -> Attr(Modal)
For configuration modals: disables submit until the user completes the inputs.
pub fn text_value(value: ViewStateValue) -> option.Option(String)
The text of a plain-text, email, URL or number input, if it has one.
pub fn view_state_decoder() -> decode.Decoder(ViewState)
Decodes ViewState from json.
pub fn view_state_value_decoder() -> decode.Decoder(
ViewStateValue,
)
Decodes ViewStateValue from json. The type field selects the variant.
pub fn view_state_value_to_json(it: ViewStateValue) -> json.Json
Encodes ViewStateValue as json.
pub fn view_type_decoder() -> decode.Decoder(ViewType)
Decodes ViewType from a json string.
pub fn view_type_from_string(string: String) -> ViewType
Parses ViewType from its json string.
pub fn view_type_to_string(it: ViewType) -> String
The json string of ViewType.