o
    ~h}h                     @   s  d dl Z d dlZd dlZd dlmZmZmZmZmZm	Z	m
Z
 d dlmZ d dlmZmZ ddlmZmZ ddlmZ ddlmZ dd	lmZmZ dd
lmZ ddlmZ ddlmZ ddlmZ G dd deZG dd deZG dd deZG dd deZ G dd deZ!G dd deZ"G dd deZ#G dd deZ$G dd  d eZ%G d!d" d"eZ&G d#d$ d$eZ'G d%d& d&eZ(dS )'    N)DictSequenceOptionalSetUnionAnyList)show_unknown_key_warning)
JsonObjectJsonValidator   )MarkdownTextObject	SlackFile)PlainTextObject)
TextObject)BlockElementRichTextElement)ImageElement)InputInteractiveElement)InteractiveElement   )SlackObjectFormationErrorc                   @   s   e Zd ZdZddhZdZee Zdd Z	e
dee fdd	Zd
d
d
ddee dee dee fddZede ddd Zedeed f ded  fddZedeeeed f   ded  fddZd
S )BlockzBlocks are a series of components that can be combined
    to create visually rich and compellingly interactive messages.
    https://api.slack.com/reference/block-kit/blocks
    block_idtype   c                 C   s   t dt d S )Nz?subtype is deprecated since slackclient 2.6.0, use type instead)warningswarnDeprecationWarningself r!   V/var/www/html/zoom/venv/lib/python3.10/site-packages/slack_sdk/models/blocks/blocks.py_subtype_warning$   s   zBlock._subtype_warningreturnc                 C   s   | j S N)r   r   r!   r!   r"   subtype*   s   zBlock.subtypeN)r   r&   r   r&   c                C   s*   |r|    |r
|n|| _|| _d | _d S r%   )r#   r   r   color)r    r   r&   r   r!   r!   r"   __init__.   s
   
zBlock.__init__zblock_id cannot exceed  charactersc                 C      | j d u pt| j | jkS r%   )r   lenblock_id_max_lengthr   r!   r!   r"   _validate_block_id_length;      zBlock._validate_block_id_lengthblockc                 C   sb  |d u rd S t |tr|S d|v r|d }|tjkr!tdi |S |tjkr-tdi |S |tjkr9tdi |S |tjkrEtdi |S |tjkrQtdi |S |tjkr]tdi |S |t	jkrit	di |S |t
jkrut
di |S |tjkrtdi |S |tjkrtdi |S |tjkrtdi |S | jd| d d S | jd| d d S )Nr   z$Unknown block detected and skipped ()r!   )
isinstancer   SectionBlockr   DividerBlock
ImageBlockActionsBlockContextBlock
InputBlock	FileBlock	CallBlockHeaderBlock
VideoBlockRichTextBlockloggerwarning)clsr/   r   r!   r!   r"   parse?   s@   











zBlock.parseblocksc                    s    fdd|pg D S )Nc                    s   g | ]}  |qS r!   )r@   ).0br?   r!   r"   
<listcomp>g   s    z#Block.parse_all.<locals>.<listcomp>r!   )r?   rA   r!   rD   r"   	parse_alle   s   zBlock.parse_all)__name__
__module____qualname____doc__
attributesr,   logging	getLoggerr=   r#   propertyr   strr&   r(   r   r-   classmethodr   dictr@   r   r   rF   r!   r!   r!   r"   r      s0    


 %,r   c                       s   e Zd ZdZdZdZedee f fddZ	dddddd	e
e d
e
eeeef  de
eeeeef   de
eeef  def
 fddZeddd Zede ddd Zede ddd Z  ZS )r2   section
     r$   c                       t  jh dS )N>   textfields	accessorysuperrK   unionr   	__class__r!   r"   rK   t      zSectionBlock.attributesN)r   rV   rW   rX   r   rV   rW   rX   othersc          
         s   t  j| j|d t| | t|| _g }|pg D ]R}t|tr*|	t
| qt|tr5|	| qt|trcd|v rct|}|d}	|	t
jkrX|	t
di | q|	tdi | q| jd|  q|| _t|| _dS )a*  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.
        r   r   r   z'Unsupported filed detected and skipped Nr!   )rZ   r(   r   r	   r   r@   rV   r1   rO   appendr   from_strrQ   copypopr   r=   r>   rW   r   rX   )
r    r   rV   rW   rX   r_   field_objectsfdtr\   r!   r"   r(   x   s$   





zSectionBlock.__init__z*text or fields attribute must be specifiedc                 C   s   | j d up| jS r%   )rV   rW   r   r!   r!   r"   "_validate_text_or_fields_populated      z/SectionBlock._validate_text_or_fields_populatedzfields attribute cannot exceed z itemsc                 C   r*   r%   )rW   r+   fields_max_lengthr   r!   r!   r"   _validate_fields_length   r.   z$SectionBlock._validate_fields_lengthtext attribute cannot exceed r)   c                 C      | j d u pt| j j | jkS r%   rV   r+   text_max_lengthr   r!   r!   r"   _validate_alt_text_length      z&SectionBlock._validate_alt_text_length)rG   rH   rI   r   rk   rp   rN   r   rO   rK   r   r   rQ   r   r   r   r(   r   ri   rl   rq   __classcell__r!   r!   r\   r"   r2   o   s6    2

r2   c                       s4   e Zd ZdZdddee def fddZ  ZS )r3   dividerNr   r   r_   c                   s    t  j| j|d t| | dS )ap  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.
        r`   N)rZ   r(   r   r	   )r    r   r_   r\   r!   r"   r(      s   zDividerBlock.__init__)	rG   rH   rI   r   r   rO   rQ   r(   rs   r!   r!   r\   r"   r3      s    r3   c                       s   e Zd ZdZedee f fddZdZdZ	dZ
dddddd	ed
ee deeeeef ef  deeeeef  dee def fddZede ddd Zede	 ddd Zede
 ddd Z  ZS )r4   imager$   c                    rU   )N>   titlealt_text	image_url
slack_filerY   r   r\   r!   r"   rK      r^   zImageBlock.attributesrT     N)ry   rz   rw   r   rx   ry   rz   rw   r   r_   c                   s   t  j| j|d t| | || _|| _d}|durZt|tr%t|d}n5t|t	rI|
dtjkr<td|
d t|
d|
dd}nt|trQ|}n	tdt| |durq|du sgt|tri|ntd	i || _|| _dS )
a,  A simple image block, designed to make those cat photos really pop.
        https://api.slack.com/reference/block-kit/blocks#image

        Args:
            alt_text (required): A plain-text summary of the image. This should not contain any markup.
                Maximum length for this field is 2000 characters.
            image_url: The URL of the image to be displayed.
                Maximum length for this field is 3000 characters.
            slack_file: A Slack image file object that defines the source of the image.
            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.
        r`   NrV   r   z.Unsupported type for title in an image block: rV   emoji)rV   r}   r!   )rZ   r(   r   r	   ry   rx   r1   rO   r   rQ   getr   r   rz   rw   )r    rx   ry   rz   rw   r   r_   parsed_titler\   r!   r"   r(      s&   



"
zImageBlock.__init__z"image_url attribute cannot exceed r)   c                 C   r*   r%   )ry   r+   image_url_max_lengthr   r!   r!   r"   _validate_image_url_length
  r.   z%ImageBlock._validate_image_url_lengthz!alt_text attribute cannot exceed c                 C   s   t | j| jkS r%   )r+   rx   alt_text_max_lengthr   r!   r!   r"   rq     rj   z$ImageBlock._validate_alt_text_lengthtitle attribute cannot exceed c                 C   (   | j d u p| j jd u pt| j j| jkS r%   )rw   rV   r+   title_max_lengthr   r!   r!   r"   _validate_title_length     (z!ImageBlock._validate_title_length)rG   rH   rI   r   rN   r   rO   rK   r   r   r   r   r   r   r   r   rQ   r   r(   r   r   rq   r   rs   r!   r!   r\   r"   r4      s<    1

r4   c                       sz   e Zd ZdZdZedee f fddZddde	e
eef  d	ee d
ef fddZede ddd Z  ZS )r5   actions   r$   c                       t  jdhS NelementsrY   r   r\   r!   r"   rK     rj   zActionsBlock.attributesNru   r   r   r_   c                   ,   t  j| j|d t| | t|| _dS )a2  A block that is used to hold interactive elements.
        https://api.slack.com/reference/block-kit/blocks#actions

        Args:
            elements (required): An array of interactive element objects - buttons, select menus, overflow menus,
                or date pickers. There is a maximum of 25 elements in each action block.
            block_id: A string acting as a unique identifier for a block.
                If not specified, a block_id 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.
        r`   NrZ   r(   r   r	   r   rF   r   r    r   r   r_   r\   r!   r"   r(     s   
zActionsBlock.__init__!elements attribute cannot exceed 	 elementsc                 C   r*   r%   r   r+   elements_max_lengthr   r!   r!   r"   _validate_elements_length8  r.   z&ActionsBlock._validate_elements_length)rG   rH   rI   r   r   rN   r   rO   rK   r   r   rQ   r   r   r(   r   r   rs   r!   r!   r\   r"   r5     s    r5   c                       s|   e Zd ZdZdZedee f fddZddde	e
eeef  d	ee d
ef fddZede ddd Z  ZS )r6   contextrS   r$   c                    r   r   rY   r   r\   r!   r"   rK   A  rj   zContextBlock.attributesNru   r   r   r_   c                   r   )aT  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.
        r`   Nr   r   r\   r!   r"   r(   E  s   
zContextBlock.__init__r   r   c                 C   r*   r%   r   r   r!   r!   r"   r   [  r.   z&ContextBlock._validate_elements_length)rG   rH   rI   r   r   rN   r   rO   rK   r   r   rQ   r   r   r   r(   r   r   rs   r!   r!   r\   r"   r6   =  s    r6   c                       s   e Zd ZdZdZdZedee f fddZ	dddddde
eeef d	e
eeef d
ee dee
eeef  dee dee def fddZede ddd Zede ddd Zeddd Z  ZS )r7   inputr{   r$   c                    rU   )N>   hintlabelelementoptionaldispatch_actionrY   r   r\   r!   r"   rK   e  r^   zInputBlock.attributesN)r   r   r   r   r   r   r   r   r   r   r_   c                   s\   t  j| j|d t| | tj|tjd| _t|| _	tj|tjd| _
|| _|| _dS )a,  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.
        r`   default_typeN)rZ   r(   r   r	   r   r@   r   r   r   r   r   r   r   )r    r   r   r   r   r   r   r_   r\   r!   r"   r(   i  s    

zInputBlock.__init__zlabel attribute cannot exceed r)   c                 C   r   r%   )r   rV   r+   label_max_lengthr   r!   r!   r"   _validate_label_length  r   z!InputBlock._validate_label_lengthzhint attribute cannot exceed c                 C   r   r%   )r   rV   r+   r   r   r!   r!   r"   _validate_hint_length  r   z InputBlock._validate_hint_lengthzelement attribute must be a string, select element, multi-select element, or a datepicker. (Sub-classes of InputInteractiveElement)c                 C   s   | j d u pt| j ttfS r%   )r   r1   rO   r   r   r!   r!   r"   _validate_element_type  s   z!InputBlock._validate_element_type)rG   rH   rI   r   r   hint_max_lengthrN   r   rO   rK   r   rQ   r   r   r   boolr(   r   r   r   r   rs   r!   r!   r\   r"   r7   `  sB    	)

r7   c                	       sX   e Zd ZdZedee f fddZdddded	ed
ee de	f fddZ
  ZS )r8   filer$   c                    s   t  jddhS )Nexternal_idsourcerY   r   r\   r!   r"   rK     r^   zFileBlock.attributesremoteN)r   r   r   r   r   r_   c                   s,   t  j| j|d t| | || _|| _dS )ab  Displays a remote file.
        https://api.slack.com/reference/block-kit/blocks#file

        Args:
            external_id (required): The external unique ID for this file.
            source (required): At the moment, source will always be remote for a remote file.
            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.
        r`   N)rZ   r(   r   r	   r   r   )r    r   r   r   r_   r\   r!   r"   r(     s   

zFileBlock.__init__)rG   rH   rI   r   rN   r   rO   rK   r   rQ   r(   rs   r!   r!   r\   r"   r8     s    r8   c                       sv   e Zd ZdZedee f fddZdddddedee	 dee
ee
eef f  d	ee d
ef
 fddZ  ZS )r9   callr$   c                    rU   )N>   r   call_idapi_decoration_availablerY   r   r\   r!   r"   rK     r^   zCallBlock.attributesN)r   r   r   r   r   r   r_   c                   s2   t  j| j|d t| | || _|| _|| _dS )zbDisplays a call information
        https://api.slack.com/reference/block-kit/blocks#call
        r`   N)rZ   r(   r   r	   r   r   r   )r    r   r   r   r   r_   r\   r!   r"   r(     s
   

zCallBlock.__init__)rG   rH   rI   r   rN   r   rO   rK   r   r   r   r   rQ   r(   rs   r!   r!   r\   r"   r9     s$    r9   c                	       s   e Zd ZdZdZedee f fddZdddde	e d	e	e
eeef  d
ef fddZeddd Zede ddd Z  ZS )r:   header   r$   c                    r   )NrV   rY   r   r\   r!   r"   rK     rj   zHeaderBlock.attributesN)r   rV   r   rV   r_   c                   s2   t  j| j|d t| | tj|tjd| _dS )a  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.
        r`   r   N)rZ   r(   r   r	   r   r@   r   rV   )r    r   rV   r_   r\   r!   r"   r(     s   
zHeaderBlock.__init__z text attribute must be specifiedc                 C   
   | j d uS r%   r|   r   r!   r!   r"   _validate_text     
zHeaderBlock._validate_textrm   r)   c                 C   rn   r%   ro   r   r!   r!   r"   rq     rr   z%HeaderBlock._validate_alt_text_length)rG   rH   rI   r   rp   rN   r   rO   rK   r   r   rQ   r   r(   r   r   rq   rs   r!   r!   r\   r"   r:     s$    
r:   c                       s4  e Zd ZdZdZdZedee f fddZ	ddddddddddd
d	e
e d
e
e de
e de
e de
eeeef  de
e de
eeeef  de
e de
e de
e def fddZeddd Zeddd Zeddd Zedd d! Zed"e d#d$d% Zed&e d#d'd( Z  ZS ))r;   video   2   r$   c                    rU   )N>	   rw   rx   	title_url	video_urlauthor_namedescriptionprovider_namethumbnail_urlprovider_icon_urlrY   r   r\   r!   r"   rK     s   zVideoBlock.attributesN)
r   rx   r   r   rw   r   r   r   r   r   r   rx   r   r   rw   r   r   r   r   r   r_   c       
            sn   t  j| j|d t| | || _|| _|| _tj|t	jd| _
|| _tj|t	jd| _|| _|	| _|
| _dS )u  A video block is designed to embed videos in all app surfaces
        (e.g. link unfurls, messages, modals, App Home) —
        anywhere you can put blocks! To use the video block within your app,
        you must have the links.embed:write scope.
        https://api.slack.com/reference/block-kit/blocks#video

        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.
            alt_text (required): A tooltip for the video. Required for accessibility
            video_url (required): The URL to be embedded. Must match any existing unfurl domains within the app
                and point to a HTTPS URL.
            thumbnail_url (required): The thumbnail image URL
            title (required): Video title in plain text format. Must be less than 200 characters.
            title_url: Hyperlink for the title text. Must correspond to the non-embeddable URL for the video.
                Must go to an HTTPS URL.
            description: Description for video in plain text format.
            provider_icon_url: Icon for the video provider - ex. Youtube icon
            provider_name: The originating application or domain of the video ex. Youtube
            author_name: Author name to be displayed. Must be less than 50 characters.
        r`   r   N)rZ   r(   r   r	   rx   r   r   r   r@   r   rw   r   r   r   r   r   )r    r   rx   r   r   rw   r   r   r   r   r   r_   r\   r!   r"   r(     s   &

zVideoBlock.__init__z$alt_text attribute must be specifiedc                 C   r   r%   )rx   r   r!   r!   r"   _validate_alt_textP  r   zVideoBlock._validate_alt_textz%video_url attribute must be specifiedc                 C   r   r%   )r   r   r!   r!   r"   _validate_video_urlT  r   zVideoBlock._validate_video_urlz)thumbnail_url attribute must be specifiedc                 C   r   r%   )r   r   r!   r!   r"   _validate_thumbnail_urlX  r   z"VideoBlock._validate_thumbnail_urlz!title attribute must be specifiedc                 C   r   r%   )rw   r   r!   r!   r"   _validate_title\  r   zVideoBlock._validate_titler   r)   c                 C   s   | j d u pt| j j| jk S r%   )rw   r+   rV   r   r   r!   r!   r"   r   `  rr   z!VideoBlock._validate_title_lengthz$author_name attribute cannot exceed c                 C   s   | j d u pt| j | jk S r%   )r   r+   author_name_max_lengthr   r!   r!   r"   _validate_author_name_lengthd  r.   z'VideoBlock._validate_author_name_length)rG   rH   rI   r   r   r   rN   r   rO   rK   r   r   rQ   r   r(   r   r   r   r   r   r   r   rs   r!   r!   r\   r"   r;     sf    	
3




r;   c                       s^   e Zd ZdZedee f fddZdddee	e
ef  dee d	e
f fd
dZ  ZS )r<   	rich_textr$   c                    r   r   rY   r   r\   r!   r"   rK   l  rj   zRichTextBlock.attributesNru   r   r   r_   c                   r   )a{  A block that is used to hold interactive elements.
        https://api.slack.com/reference/block-kit/blocks#rich_text

        Args:
            elements (required): An array of rich text objects -
                rich_text_section, rich_text_list, rich_text_quote, rich_text_preformatted
            block_id: 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.
        r`   Nr   r   r\   r!   r"   r(   p  s   
zRichTextBlock.__init__)rG   rH   rI   r   rN   r   rO   rK   r   r   rQ   r   r   r(   rs   r!   r!   r\   r"   r<   i  s    r<   ))rc   rL   r   typingr   r   r   r   r   r   r   slack_sdk.modelsr	   slack_sdk.models.basic_objectsr
   r   basic_componentsr   r   r   r   block_elementsr   r   r   r   r   errorsr   r   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r!   r!   r!   r"   <module>   s4    $UHI&#D!(a