def __init__( self, *, action_id: Optional[str] = None, options: Sequence[Union[Option]], confirm: Optional[Union[dict, ConfirmObject]] = None, **others: dict, ): """ This is like a cross between a button and a select menu - when a user clicks on this overflow button, they will be presented with a list of options to choose from. Unlike the select menu, there is no typeahead field, and the button always appears with an ellipsis ("…") rather than customisable text. As such, it is usually used if you want a more compact layout than a select menu, or to supply a list of less visually important actions after a row of buttons. You can also specify simple URL links as overflow menu options, instead of actions. https://api.slack.com/reference/block-kit/block-elements#overflow """ super().__init__(action_id=action_id, type=self.type) show_unknown_key_warning(self, others) self.options = options self.confirm = ConfirmObject.parse(confirm)
def __init__( self, *, placeholder: Optional[Union[str, dict, TextObject]] = None, action_id: Optional[str] = None, initial_conversations: Optional[Sequence[str]] = None, confirm: Optional[Union[dict, ConfirmObject]] = None, max_selected_items: Optional[int] = None, default_to_current_conversation: Optional[bool] = None, filter: Optional[Union[ dict, ConversationFilter]] = None, # skipcq: PYL-W0622 **others: dict, ): """ This multi-select menu will populate its options with a list of public and private channels, DMs, and MPIMs visible to the current user in the active workspace. https://api.slack.com/reference/block-kit/block-elements#conversation_multi_select """ super().__init__( type=self.type, action_id=action_id, placeholder=TextObject.parse(placeholder, PlainTextObject.type), confirm=ConfirmObject.parse(confirm), ) show_unknown_key_warning(self, others) self.initial_conversations = initial_conversations self.max_selected_items = max_selected_items self.default_to_current_conversation = default_to_current_conversation self.filter = ConversationFilter.parse(filter)
def __init__( self, *, label: Optional[Union[str, dict, TextObject]] = None, options: Sequence[Union[dict, Option]], **others: dict, ): """ Create a group of Option objects - pass in a label (that will be part of the UI) and a list of Option objects. Blocks: https://api.slack.com/reference/block-kit/composition-objects#option-group Dialogs: https://api.slack.com/dialogs#select_elements Legacy interactive attachments: https://api.slack.com/legacy/interactive-message-field-guide#option_groups_to_place_within_message_menu_actions Args: label: Text to display at the top of this group of options. options: A list of no more than 100 Option objects. """ # noqa prevent flake8 blowing up on the long URL # default_type=PlainTextObject.type is for backward-compatibility self._label: Optional[TextObject] = TextObject.parse( label, default_type=PlainTextObject.type) self.label: Optional[str] = self._label.text if self._label else None self.options = Option.parse_all(options) # compatible with version 2.5 show_unknown_key_warning(self, others)
def __init__( self, *, placeholder: Optional[Union[str, dict, TextObject]] = None, action_id: Optional[str] = None, min_query_length: Optional[int] = None, initial_options: Optional[Sequence[Union[dict, Option]]] = None, confirm: Optional[Union[dict, ConfirmObject]] = None, max_selected_items: Optional[int] = None, **others: dict, ): """ This select menu will load its options from an external data source, allowing for a dynamic list of options. https://api.slack.com/reference/block-kit/block-elements#external-select """ super().__init__( type=self.type, action_id=action_id, placeholder=TextObject.parse(placeholder, PlainTextObject.type), confirm=ConfirmObject.parse(confirm), ) show_unknown_key_warning(self, others) self.min_query_length = min_query_length self.initial_options = Option.parse_all(initial_options) self.max_selected_items = max_selected_items
def __init__( self, *, action_id: Optional[str] = None, placeholder: Optional[Union[str, dict, TextObject]] = None, confirm: Optional[Union[dict, ConfirmObject]] = None, initial_value: Optional[str] = None, multiline: Optional[bool] = None, min_length: Optional[int] = None, max_length: Optional[int] = None, dispatch_action_config: Optional[Union[dict, DispatchActionConfig]] = None, **others: dict, ): """ An element which lets users easily select a date from a calendar style UI. Date picker elements can be used inside of SectionBlocks and ActionsBlocks. https://api.slack.com/reference/block-kit/block-elements#datepicker """ super().__init__( type=self.type, action_id=action_id, placeholder=TextObject.parse(placeholder, PlainTextObject.type), confirm=ConfirmObject.parse(confirm), ) show_unknown_key_warning(self, others) self.initial_value = initial_value self.multiline = multiline self.min_length = min_length self.max_length = max_length self.dispatch_action_config = dispatch_action_config
def __init__( self, *, image_url: str, alt_text: str, title: Optional[Union[str, dict, TextObject]] = None, block_id: Optional[str] = None, **others: dict, ): """A simple image block, designed to make those cat photos really pop. https://api.slack.com/reference/block-kit/blocks#image Args: image_url (required): The URL of the image to be displayed. Maximum length for this field is 3000 characters. alt_text (required): A plain-text summary of the image. This should not contain any markup. Maximum length for this field is 2000 characters. title: An optional title for the image in the form of a text object that can only be of type: plain_text. Maximum length for the text in this field is 2000 characters. block_id: A string acting as a unique identifier for a block. If not specified, one will be generated. Maximum length for this field is 255 characters. block_id should be unique for each message and each iteration of a message. If a message is updated, use a new block_id. """ super().__init__(type=self.type, block_id=block_id) show_unknown_key_warning(self, others) self.image_url = image_url self.alt_text = alt_text self.title = TextObject.parse(title)
def __init__( self, *, action_id: Optional[str] = None, placeholder: Optional[str] = None, options: Optional[Sequence[Option]] = None, option_groups: Optional[Sequence[OptionGroup]] = None, initial_option: Optional[Option] = None, confirm: Optional[Union[dict, ConfirmObject]] = None, **others: dict, ): """This is the simplest form of select menu, with a static list of options passed in when defining the element. https://api.slack.com/reference/block-kit/block-elements#static_select """ super().__init__( type=self.type, action_id=action_id, placeholder=TextObject.parse(placeholder, PlainTextObject.type), confirm=ConfirmObject.parse(confirm), ) show_unknown_key_warning(self, others) self.options = options self.option_groups = option_groups self.initial_option = initial_option
def __init__( self, *, block_id: Optional[str] = None, text: Union[str, dict, TextObject] = None, fields: Sequence[Union[str, dict, TextObject]] = None, accessory: Optional[Union[dict, BlockElement]] = None, **others: dict, ): """A section is one of the most flexible blocks available. https://api.slack.com/reference/block-kit/blocks#section """ super().__init__(type=self.type, block_id=block_id) show_unknown_key_warning(self, others) self.text = TextObject.parse(text) field_objects = [] for f in fields or []: if isinstance(f, str): field_objects.append(MarkdownTextObject.from_str(f)) elif isinstance(f, TextObject): field_objects.append(f) elif isinstance(f, dict) and "type" in f: d = copy.copy(f) t = d.pop("type") if t == MarkdownTextObject.type: field_objects.append(MarkdownTextObject(**d)) else: field_objects.append(PlainTextObject(**d)) else: self.logger.warning( f"Unsupported filed detected and skipped {f}") self.fields = field_objects self.accessory = BlockElement.parse(accessory)
def __init__( self, *, action_id: Optional[str] = None, placeholder: Optional[Union[str, dict, TextObject]] = None, confirm: Optional[Union[dict, ConfirmObject]] = None, initial_value: Optional[str] = None, multiline: Optional[bool] = None, min_length: Optional[int] = None, max_length: Optional[int] = None, dispatch_action_config: Optional[Union[dict, DispatchActionConfig]] = None, **others: dict, ): """ A plain-text input, similar to the HTML <input> tag, creates a field where a user can enter freeform data. It can appear as a single-line field or a larger textarea using the multiline flag. Plain-text input elements can be used inside of SectionBlocks and ActionsBlocks. https://api.slack.com/reference/block-kit/block-elements#input """ super().__init__( type=self.type, action_id=action_id, placeholder=TextObject.parse(placeholder, PlainTextObject.type), confirm=ConfirmObject.parse(confirm), ) show_unknown_key_warning(self, others) self.initial_value = initial_value self.multiline = multiline self.min_length = min_length self.max_length = max_length self.dispatch_action_config = dispatch_action_config
def __init__( self, *, placeholder: Optional[Union[str, dict, TextObject]] = None, action_id: Optional[str] = None, initial_channels: Optional[Sequence[str]] = None, confirm: Optional[Union[dict, ConfirmObject]] = None, max_selected_items: Optional[int] = None, **others: dict, ): """ This multi-select menu will populate its options with a list of public channels visible to the current user in the active workspace. https://api.slack.com/reference/block-kit/block-elements#channel_multi_select """ super().__init__( type=self.type, action_id=action_id, placeholder=TextObject.parse(placeholder, PlainTextObject.type), confirm=ConfirmObject.parse(confirm), ) show_unknown_key_warning(self, others) self.initial_channels = initial_channels self.max_selected_items = max_selected_items
def __init__( self, *, type: Optional[str] = None, # skipcq: PYL-W0622 subtype: Optional[str] = None, **others: dict, ): if subtype: self._subtype_warning() self.type = type if type else subtype show_unknown_key_warning(self, others)
def __init__( self, *, value: str, label: Optional[str] = None, text: Optional[Union[str, dict, TextObject]] = None, # Block Kit description: Optional[str] = None, url: Optional[str] = None, **others: dict, ): """ An object that represents a single selectable item in a block element ( SelectElement, OverflowMenuElement) or dialog element (StaticDialogSelectElement) Blocks: https://api.slack.com/reference/block-kit/composition-objects#option Dialogs: https://api.slack.com/dialogs#select_elements Legacy interactive attachments: https://api.slack.com/legacy/interactive-message-field-guide#option_fields Args: label: A short, user-facing string to label this option to users. Cannot exceed 75 characters. value: A short string that identifies this particular option to your application. It will be part of the payload when this option is selected . Cannot exceed 75 characters. description: A user-facing string that provides more details about this option. Only supported in legacy message actions, not in blocks or dialogs. """ if text: self._text: Optional[TextObject] = TextObject.parse(text) self._label: Optional[str] = None else: self._text: Optional[TextObject] = None self._label: Optional[str] = label # for backward-compatibility with version 2.0-2.5, the following fields return str values self.text: Optional[str] = self._text.text if self._text else None self.label: Optional[str] = self._label self.value: str = value self.description: Optional[str] = description # A URL to load in the user's browser when the option is clicked. # The url attribute is only available in overflow menus. # Maximum length for this field is 3000 characters. # If you're using url, you'll still receive an interaction payload # and will need to send an acknowledgement response. self.url: Optional[str] = url show_unknown_key_warning(self, others)
def __init__( self, *, block_id: Optional[str] = None, **others: dict, ): """A content divider, like an <hr>, to split up different blocks inside of a message. https://api.slack.com/reference/block-kit/blocks#divider """ super().__init__(type=self.type, block_id=block_id) show_unknown_key_warning(self, others)
def __init__( self, *, block_id: Optional[str] = None, text: Union[str, dict, TextObject] = None, **others: dict, ): """A header is a plain-text block that displays in a larger, bold font. https://api.slack.com/reference/block-kit/blocks#header """ super().__init__(type=self.type, block_id=block_id) show_unknown_key_warning(self, others) self.text = TextObject.parse(text, default_type=PlainTextObject.type)
def __init__( self, *, action_id: Optional[str] = None, type: Optional[str] = None, # skipcq: PYL-W0622 subtype: Optional[str] = None, **others: dict, ): if subtype: self._subtype_warning() super().__init__(type=type or subtype) show_unknown_key_warning(self, others) self.action_id = action_id
def __init__( self, *, elements: Sequence[Union[dict, ImageBlock, TextObject]], block_id: Optional[str] = None, **others: dict, ): """Displays message context, which can include both images and text. https://api.slack.com/reference/block-kit/blocks#context """ super().__init__(type=self.type, block_id=block_id) show_unknown_key_warning(self, others) self.elements = BlockElement.parse_all(elements)
def __init__( self, *, elements: Sequence[Union[dict, InteractiveElement]], block_id: Optional[str] = None, **others: dict, ): """A block that is used to hold interactive elements. https://api.slack.com/reference/block-kit/blocks#actions """ super().__init__(type=self.type, block_id=block_id) show_unknown_key_warning(self, others) self.elements = elements
def __init__( self, *, block_id: Optional[str] = None, text: Optional[Union[str, dict, TextObject]] = None, fields: Optional[Sequence[Union[str, dict, TextObject]]] = None, accessory: Optional[Union[dict, BlockElement]] = None, **others: dict, ): """A section is one of the most flexible blocks available. https://api.slack.com/reference/block-kit/blocks#section Args: block_id (required): A string acting as a unique identifier for a block. If not specified, one will be generated. You can use this block_id when you receive an interaction payload to identify the source of the action. Maximum length for this field is 255 characters. block_id should be unique for each message and each iteration of a message. If a message is updated, use a new block_id. text (preferred): The text for the block, in the form of a text object. Maximum length for the text in this field is 3000 characters. This field is not required if a valid array of fields objects is provided instead. fields (required if no text is provided): Required if no text is provided. An array of text objects. Any text objects included with fields will be rendered in a compact format that allows for 2 columns of side-by-side text. Maximum number of items is 10. Maximum length for the text in each item is 2000 characters. accessory: One of the available element objects. """ super().__init__(type=self.type, block_id=block_id) show_unknown_key_warning(self, others) self.text = TextObject.parse(text) field_objects = [] for f in fields or []: if isinstance(f, str): field_objects.append(MarkdownTextObject.from_str(f)) elif isinstance(f, TextObject): field_objects.append(f) elif isinstance(f, dict) and "type" in f: d = copy.copy(f) t = d.pop("type") if t == MarkdownTextObject.type: field_objects.append(MarkdownTextObject(**d)) else: field_objects.append(PlainTextObject(**d)) else: self.logger.warning( f"Unsupported filed detected and skipped {f}") self.fields = field_objects self.accessory = BlockElement.parse(accessory)
def __init__( self, *, external_id: str, source: str = "remote", block_id: Optional[str] = None, **others: dict, ): """Displays a remote file. https://api.slack.com/reference/block-kit/blocks#file """ super().__init__(type=self.type, block_id=block_id) show_unknown_key_warning(self, others) self.external_id = external_id self.source = source
def __init__( self, *, image_url: Optional[str] = None, alt_text: Optional[str] = None, **others: dict, ): """An element to insert an image - this element can be used in section and context blocks only. If you want a block with only an image in it, you're looking for the image block. https://api.slack.com/reference/block-kit/block-elements#image """ super().__init__(type=self.type) show_unknown_key_warning(self, others) self.image_url = image_url self.alt_text = alt_text
def __init__( self, *, image_url: str, alt_text: str, title: Optional[Union[str, dict, TextObject]] = None, block_id: Optional[str] = None, **others: dict, ): """A simple image block, designed to make those cat photos really pop. https://api.slack.com/reference/block-kit/blocks#image """ super().__init__(type=self.type, block_id=block_id) show_unknown_key_warning(self, others) self.image_url = image_url self.alt_text = alt_text self.title = TextObject.parse(title)
def __init__( self, *, action_id: Optional[str] = None, placeholder: Union[str, TextObject] = None, type: Optional[str] = None, # skipcq: PYL-W0622 subtype: Optional[str] = None, confirm: Optional[Union[dict, ConfirmObject]] = None, **others: dict, ): """InteractiveElement that is usable in input blocks""" if subtype: self._subtype_warning() super().__init__(action_id=action_id, type=type or subtype) show_unknown_key_warning(self, others) self.placeholder = TextObject.parse(placeholder) self.confirm = ConfirmObject.parse(confirm)
def __init__( self, *, block_id: Optional[str] = None, **others: dict, ): """A content divider, like an <hr>, to split up different blocks inside of a message. https://api.slack.com/reference/block-kit/blocks#divider Args: block_id: A string acting as a unique identifier for a block. If not specified, one will be generated. You can use this block_id when you receive an interaction payload to identify the source of the action. Maximum length for this field is 255 characters. block_id should be unique for each message and each iteration of a message. If a message is updated, use a new block_id. """ super().__init__(type=self.type, block_id=block_id) show_unknown_key_warning(self, others)
def __init__( self, *, call_id: str, api_decoration_available: Optional[bool] = None, call: Optional[Dict[str, Dict[str, Any]]] = None, block_id: Optional[str] = None, **others: dict, ): """Displays a call information https://api.slack.com/reference/block-kit/blocks#call """ super().__init__(type=self.type, block_id=block_id) show_unknown_key_warning(self, others) self.call_id = call_id self.api_decoration_available = api_decoration_available self.call = call
def __init__( self, *, elements: Sequence[Union[dict, ImageElement, TextObject]], block_id: Optional[str] = None, **others: dict, ): """Displays message context, which can include both images and text. https://api.slack.com/reference/block-kit/blocks#context Args: elements (required): An array of image elements and text objects. Maximum number of items is 10. block_id: A string acting as a unique identifier for a block. If not specified, one will be generated. Maximum length for this field is 255 characters. block_id should be unique for each message and each iteration of a message. If a message is updated, use a new block_id. """ super().__init__(type=self.type, block_id=block_id) show_unknown_key_warning(self, others) self.elements = BlockElement.parse_all(elements)
def __init__( self, *, label: Union[str, dict, PlainTextObject], element: Union[str, dict, InputInteractiveElement], block_id: Optional[str] = None, hint: Optional[Union[str, dict, PlainTextObject]] = None, dispatch_action: Optional[bool] = None, optional: Optional[bool] = None, **others: dict, ): """A block that collects information from users - it can hold a plain-text input element, a select menu element, a multi-select menu element, or a datepicker. https://api.slack.com/reference/block-kit/blocks#input Args: label (required): A label that appears above an input element in the form of a text object that must have type of plain_text. Maximum length for the text in this field is 2000 characters. element (required): An plain-text input element, a checkbox element, a radio button element, a select menu element, a multi-select menu element, or a datepicker. block_id: A string acting as a unique identifier for a block. If not specified, one will be generated. Maximum length for this field is 255 characters. block_id should be unique for each message or view and each iteration of a message or view. If a message or view is updated, use a new block_id. hint: An optional hint that appears below an input element in a lighter grey. It must be a text object with a type of plain_text. Maximum length for the text in this field is 2000 characters. dispatch_action: A boolean that indicates whether or not the use of elements in this block should dispatch a block_actions payload. Defaults to false. optional: A boolean that indicates whether the input element may be empty when a user submits the modal. Defaults to false. """ super().__init__(type=self.type, block_id=block_id) show_unknown_key_warning(self, others) self.label = TextObject.parse(label, default_type=PlainTextObject.type) self.element = BlockElement.parse(element) self.hint = TextObject.parse(hint, default_type=PlainTextObject.type) self.dispatch_action = dispatch_action self.optional = optional
def __init__( self, *, action_id: Optional[str] = None, placeholder: Optional[Union[str, dict, TextObject]] = None, initial_time: Optional[str] = None, confirm: Optional[Union[dict, ConfirmObject]] = None, **others: dict, ): """ An element which allows selection of a time of day. https://api.slack.com/reference/block-kit/block-elements#timepicker """ super().__init__( type=self.type, action_id=action_id, placeholder=TextObject.parse(placeholder, PlainTextObject.type), confirm=ConfirmObject.parse(confirm), ) show_unknown_key_warning(self, others) self.initial_time = initial_time
def __init__( self, *, block_id: Optional[str] = None, text: Optional[Union[str, dict, TextObject]] = None, **others: dict, ): """A header is a plain-text block that displays in a larger, bold font. https://api.slack.com/reference/block-kit/blocks#header Args: block_id: A string acting as a unique identifier for a block. If not specified, one will be generated. Maximum length for this field is 255 characters. block_id should be unique for each message and each iteration of a message. If a message is updated, use a new block_id. text (required): The text for the block, in the form of a plain_text text object. Maximum length for the text in this field is 150 characters. """ super().__init__(type=self.type, block_id=block_id) show_unknown_key_warning(self, others) self.text = TextObject.parse(text, default_type=PlainTextObject.type)
def __init__( self, *, action_id: Optional[str] = None, placeholder: Optional[str] = None, options: Optional[Sequence[Union[dict, Option]]] = None, initial_options: Optional[Sequence[Union[dict, Option]]] = None, confirm: Optional[Union[dict, ConfirmObject]] = None, **others: dict, ): """A checkbox group that allows a user to choose multiple items from a list of possible options. https://api.slack.com/reference/block-kit/block-elements#checkboxes """ super().__init__( type=self.type, action_id=action_id, placeholder=TextObject.parse(placeholder, PlainTextObject.type), confirm=ConfirmObject.parse(confirm), ) show_unknown_key_warning(self, others) self.options = Option.parse_all(options) self.initial_options = Option.parse_all(initial_options)
def __init__( self, *, action_id: Optional[str] = None, placeholder: Optional[Union[str, dict, TextObject]] = None, initial_date: Optional[str] = None, confirm: Optional[Union[dict, ConfirmObject]] = None, **others: dict, ): """ An element which lets users easily select a date from a calendar style UI. Date picker elements can be used inside of SectionBlocks and ActionsBlocks. https://api.slack.com/reference/block-kit/block-elements#datepicker """ super().__init__( type=self.type, action_id=action_id, placeholder=TextObject.parse(placeholder, PlainTextObject.type), confirm=ConfirmObject.parse(confirm), ) show_unknown_key_warning(self, others) self.initial_date = initial_date