o
    ~hY                     @   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 ddhZh d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)ListOptionalSetUnionSequenceDictAny)show_unknown_key_warning)
JsonObjectJsonValidator)Linkdangerprimary>   userschannelsconversationsc                
   @   s   e Zd ZdZh dZee Zdd Ze	de
e fddZe	dd	eeeeef d f d
ede
d  fddZ			dd	ede
e de
e de
e fddZdS )
TextObjectz:The interface for text objects (types: plain_text, mrkdwn)>   texttypeemojic                 C   s   t dt d S )Nz?subtype is deprecated since slackclient 2.6.0, use type instead)warningswarnDeprecationWarningself r   `/var/www/html/zoom/venv/lib/python3.10/site-packages/slack_sdk/models/blocks/basic_components.py_subtype_warning   s   zTextObject._subtype_warningreturnc                 C   s   | j S N)r   r   r   r   r   subtype   s   zTextObject.subtypemrkdwnr   default_typec                 C   s   |sd S t |tr|tjkrt|S t|S t |tr:t|}|d}|tjkr3tdi |S tdi |S t |t	rA|S | j
dt| d d S )Nr   zUnknown type (z$) detected when parsing a TextObjectr   )
isinstancestrPlainTextObjectr   from_strMarkdownTextObjectdictcopypopr   loggerwarning)clsr   r"   dtr   r   r   parse!   s    








zTextObject.parseNr   r    r   c                 K   s*   |r|    || _|r|n|| _|| _dS )z4Super class for new text "objects" used in Block kitN)r   r   r   r   )r   r   r   r    r   kwargsr   r   r   __init__;   s
   	
zTextObject.__init__)r!   )NNN)__name__
__module____qualname____doc__
attributeslogging	getLoggerr+   r   propertyr   r$   r    classmethodr   r   r   r0   boolr2   r   r   r   r   r      s8    
r   c                       s   e Zd ZdZdZedee f fddZddded	e	e
 f fd
dZededd fddZededeeef fddZ  ZS )r%   zplain_text typed text object
plain_textr   c                       t  jdhS )Nr   superr7   unionr   	__class__r   r   r7   Q      zPlainTextObject.attributesN)r   r   r   c                      t  j|| jd || _dS )a  A plain text object, meaning markdown characters will not be parsed as
        formatting information.
        https://api.slack.com/reference/block-kit/composition-objects#text

        Args:
            text (required): The text for the block. This field accepts any of the standard text formatting markup
                when type is mrkdwn.
            emoji: Indicates whether emojis in a text field should be escaped into the colon emoji format.
                This field is only usable when type is plain_text.
        r   r   N)r@   r2   r   r   )r   r   r   rB   r   r   r2   U   s   
zPlainTextObject.__init__c                 C   s   t | ddS )NT)r   r   )r%   r   r   r   r   r&   c   s   zPlainTextObject.from_strc                 C      t |  S )zNTransforms a string into the required object shape to act as a PlainTextObject)r%   r&   to_dictrG   r   r   r   direct_from_stringg      z"PlainTextObject.direct_from_string)r3   r4   r5   r6   r   r:   r   r$   r7   r   r<   r2   staticmethodr&   r   r   rJ   __classcell__r   r   rB   r   r%   L   s     $r%   c                
       s   e Zd ZdZdZedee f fddZddded	e	e
 f fd
dZededd fddZededeeef fddZeddededd fddZeddededeeef fddZ  ZS )r'   zmrkdwn typed text objectr!   r   c                    r>   )Nverbatimr?   r   rB   r   r   r7   r   rD   zMarkdownTextObject.attributesN)rN   r   rN   c                   rE   )a  A Markdown text object, meaning markdown characters will be parsed as
        formatting information.
        https://api.slack.com/reference/block-kit/composition-objects#text

        Args:
            text (required): The text for the block. This field accepts any of the standard text formatting markup
                when type is mrkdwn.
            verbatim: When set to false (as is default) URLs will be auto-converted into links,
                conversation names will be link-ified, and certain mentions will be automatically parsed.
                Using a value of true will skip any preprocessing of this nature,
                although you can still include manual parsing strings. This field is only usable when type is mrkdwn.
        rF   N)r@   r2   r   rN   )r   r   rN   rB   r   r   r2   v   s   
zMarkdownTextObject.__init__c                 C   s
   t | dS )QTransforms a string into the required object shape to act as a MarkdownTextObjectrG   r'   rG   r   r   r   r&      s   
zMarkdownTextObject.from_strc                 C   rH   )rO   )r'   r&   rI   rG   r   r   r   rJ      rK   z%MarkdownTextObject.direct_from_string linktitlec                 C   s    |rd| }t |  | dS )x
        Transform a Link object directly into the required object shape
        to act as a MarkdownTextObject
        z: rG   rP   rR   rS   r   r   r   	from_link   s   
zMarkdownTextObject.from_linkc                 C   s   t | | S )rT   )r'   rV   rI   rU   r   r   r   direct_from_link   s   z#MarkdownTextObject.direct_from_link)rQ   )r3   r4   r5   r6   r   r:   r   r$   r7   r   r<   r2   rL   r&   r   r   rJ   r   rV   rW   rM   r   r   rB   r   r'   m   s     	*r'   c                   @   sN  e Zd ZdZi Zee ZdZdZ	dddddde
dee
 deee
ee
ef ef  deee
ee
ef ef  d	ee
 d
ee
ef fddZede ddefddZede ddefddZede	 ddefddZedeeeee
ef d f   deed   fddZd"de
dee
ef fddZede
fd d!ZdS )#OptionzOption object used in dialogs, legacy message actions (interactivity in attachments),
    and blocks. JSON must be retrieved with an explicit option_type - the Slack API has
    different required formats in different situations
    K   N)labelr   descriptionurlvaluerZ   r   r[   r\   othersc                K   s   |rt j|tjd| _d| _nd| _|| _| jr| jjnd| _| j| _|| _t	|t
r5|| _t|| _n$t	|trF|d | _t || _nt	|t rS|j| _|| _nd| _d| _|| _t| | dS )a   
        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.
        )r   r"   Nr   )r   r0   r%   r   _text_labelr   rZ   r]   r#   r$   r[   r&   _block_descriptionr(   r\   r	   )r   r]   rZ   r   r[   r\   r^   r   r   r   r2      s0   "



zOption.__init__label attribute cannot exceed  charactersr   c                 C      | j d u pt| j | jkS r   )r`   lenlabel_max_lengthr   r   r   r   _validate_label_length      zOption._validate_label_lengthtext attribute cannot exceed c                 C   s(   | j d u p| j jd u pt| j j| jkS r   )r_   r   re   rf   r   r   r   r   _validate_text_length   s   (zOption._validate_text_lengthzvalue attribute cannot exceed c                 C   s   t | j| jkS r   )re   r]   value_max_lengthr   r   r   r   _validate_value_length  rD   zOption._validate_value_lengthoptionsc                 C   r   |d u rd S g }|D ],}t |tr!t|}|tdi | q
t |tr,|| q
| jd| d q
|S )Nz,Unknown option object detected and skipped ()r   )r#   r(   r)   appendrX   r+   r,   )r-   rm   option_objectsor.   r   r   r   	parse_all  s   


zOption.parse_allblockoption_typec                 C   s   |    |dkr| j| jdS |dks|dkr*| j| jd}| jdur(| j|d< |S | jp2t| j}| | jd}| jrE| j |d< | j	rM| j	|d< |S )	z
        Different parent classes must call this with a valid value from OptionTypes -
        either "dialog", "action", or "block", so that JSON is returned in the
        correct shape.
        dialog)rZ   r]   action
attachment)r   r]   Nr[   r\   )
validate_jsonrZ   r]   r[   r_   r%   r&   rI   ra   r\   )r   ru   jsonr   r   r   r   rI     s"   


zOption.to_dictvalue_and_labelc                 C   s   t | | dS )z>Creates a simple Option instance with the same value and label)r]   rZ   )rX   )r{   r   r   r   from_single_value0  s   zOption.from_single_valuert   )r3   r4   r5   r6   r7   r8   r9   r+   rf   rk   r$   r   r   r   r   r   r2   r   r<   rg   rj   rl   r;   r   r   rs   rI   rL   r|   r   r   r   r   rX      sD    


J4rX   c                	   @   s   e Zd ZdZi ZdZdZee Z	ddde
eeeeef ef  deeeeef ef  deeef fd	d
Zede ddd Zede ddd Zede
eeeeef d f   de
ed   fddZddedeeef fddZdS )OptionGroupz
    JSON must be retrieved with an explicit option_type - the Slack API has
    different required formats in different situations
    rY   d   N)rZ   rZ   rm   r^   c                K   s@   t j|tjd| _| jr| jjnd| _t|| _	t
| | dS )al  
        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.
        r"   N)r   r0   r%   r   r`   r   rZ   rX   rs   rm   r	   )r   rZ   rm   r^   r   r   r   r2   A  s   zOptionGroup.__init__rb   rc   c                 C   rd   r   )rZ   re   rf   r   r   r   r   rg   _  rh   z"OptionGroup._validate_label_lengthz options attribute cannot exceed z	 elementsc                 C   rd   r   )rm   re   options_max_lengthr   r   r   r   _validate_options_lengthc  rh   z$OptionGroup._validate_options_lengthoption_groupsr   c                 C   rn   )Nz2Unknown option group object detected and skipped (ro   r   )r#   r(   r)   rp   r~   r+   r,   )r-   r   option_group_objectsrr   r.   r   r   r   rs   g  s   


zOptionGroup.parse_allrt   ru   c                    sX   |     fdd| jD } dkr| j|dS  dkr"| j|dS | j }||dS )Nc                    s   g | ]}|  qS r   )rI   ).0rr   ru   r   r   
<listcomp>z  s    z'OptionGroup.to_dict.<locals>.<listcomp>rv   )rZ   rm   rw   )r   rm   )ry   rm   rZ   r`   rI   )r   ru   dict_options
dict_labelr   r   r   rI   x  s   
zOptionGroup.to_dictr}   )r3   r4   r5   r6   r7   rf   r   r8   r9   r+   r   r   r$   r   r   r   r   rX   r2   r   rg   r   r;   r   rs   rI   r   r   r   r   r~   6  s2    





 r~   c                   @   s`  e Zd Zi ZdZdZdZdZede	d e
eef f fddZddd	d
de	ee
eef ef de	ee
eef ef de	ee
eef ef de	ee
eef ef dee f
ddZede ddefddZede ddefddZede ddefddZede ddefddZeddefd d!Zd&d#ede
eef fd$d%Zd	S )'ConfirmObjectr   i,     confirmc                 C   2   |rt |tr	|S t |trtdi |S d S d S Nr   )r#   r   r(   )r-   r   r   r   r   r0        

zConfirmObject.parseYesNoN)r   denystylerS   r   r   r   c                C   s   t j|tjd| _t j|tjd| _t j|tjd| _t j|tjd| _|| _	| jr.| jj
nd| _| jr8| jj
nd| _
| jrB| jj
nd| _| jrL| jj
nd| _| j	| _dS )a*  
        An object that defines a dialog that provides a confirmation step to any
        interactive element. This dialog will ask the user to confirm their action by
        offering a confirm and deny button.
        https://api.slack.com/reference/block-kit/composition-objects#confirm
        r   N)r   r0   r%   r   _titler'   r_   _confirm_deny_styler   rS   r   r   r   )r   rS   r   r   r   r   r   r   r   r2     s   zConfirmObject.__init__ztitle attribute cannot exceed rc   r   c                 C      | j d u pt| j j| jkS r   )r   re   r   title_max_lengthr   r   r   r   title_length     zConfirmObject.title_lengthri   c                 C   r   r   )r_   re   r   text_max_lengthr   r   r   r   text_length  r   zConfirmObject.text_lengthz confirm attribute cannot exceed c                 C   r   r   )r   re   r   confirm_max_lengthr   r   r   r   confirm_length  r   zConfirmObject.confirm_lengthzdeny attribute cannot exceed c                 C   r   r   )r   re   r   deny_max_lengthr   r   r   r   deny_length  r   zConfirmObject.deny_lengthz6style for confirm must be either "primary" or "danger"c                 C   s   | j d u p	| j dv S )N)r   r   )r   r   r   r   r   _validate_confirm_style  s   z%ConfirmObject._validate_confirm_stylert   ru   c                 C   s   |dkr7| j r| j jdkr| j jnd| jr| jjdkr| jjndd}| jr,| jj|d< | jr5| jj|d< |S |   i }| jrG| j |d< | jrQ| j |d< | j r[| j  |d	< | jre| j |d
< | jrm| j|d< |S )Nrw   r   Okayr   Cancel)ok_textdismiss_textrS   r   r   r   r   )r   r   r   r   r_   ry   rI   r   )r   ru   rz   r   r   r   rI     s,   
zConfirmObject.to_dictr}   )r3   r4   r5   r7   r   r   r   r   r;   r   r   r$   r   r0   r%   r   r   r2   r   r<   r   r   r   r   r   rI   r   r   r   r   r     sB     
 r   c                   @   sf   e Zd ZdhZeded eeef f fddZ	ddde
ee  fddZd	eeef fd
dZdS )DispatchActionConfigtrigger_actions_onconfigc                 C   r   r   )r#   r   r(   )r-   r   r   r   r   r0     r   zDispatchActionConfig.parseN)r   c                C   s   |pg | _ dS )z
        Determines when a plain-text input element will return a block_actions interaction payload.
        https://api.slack.com/reference/block-kit/composition-objects#dispatch_action_config
        N)_trigger_actions_on)r   r   r   r   r   r2     s   	zDispatchActionConfig.__init__r   c                 C   s    |    i }| jr| j|d< |S )Nr   )ry   r   r   rz   r   r   r   rI   	  s
   
zDispatchActionConfig.to_dict)r3   r4   r5   r7   r;   r   r   r$   r   r0   r   r   r2   rI   r   r   r   r   r     s     

r   c                	   @   sP   e Zd ZdhZdddedeeeeef   fddZdeee	f fd	d
Z
dS )WorkflowTriggertriggerN)customizable_input_parametersr\   r   c                C   s   || _ || _d S r   )_url_customizable_input_parameters)r   r\   r   r   r   r   r2     s   
zWorkflowTrigger.__init__r   c                 C   s0   |    d| ji}| jd ur|d| ji |S )Nr\   r   )ry   r   r   updater   r   r   r   rI     s
   

zWorkflowTrigger.to_dict)r3   r4   r5   r7   r$   r   r   r   r2   r   rI   r   r   r   r   r     s    (r   c                   @   s>   e Zd ZdhZdeeef fddZdee	e
f fddZdS )Workflowr   c                C   s
   || _ d S r   )_trigger)r   r   r   r   r   r2   #  s   
zWorkflow.__init__r   c                 C   s8   |    i }t| jtr| j |d< |S | j|d< |S )Nr   )ry   r#   r   r   rI   r   r   r   r   rI   *  s   
zWorkflow.to_dictN)r3   r4   r5   r7   r   r   r(   r2   r   r$   r   rI   r   r   r   r   r      s    

r   c                   @   sL   e Zd ZddhZddddee dee fddZdeeef fdd	Z	dS )
	SlackFileidr\   N)r   r\   c                C   s   || _ || _dS )a>  An object containing Slack file information to be used in an image block or image element.
        https://api.slack.com/reference/block-kit/composition-objects#slack_file

        Args:
            id: Slack ID of the file.
            url: This URL can be the url_private or the permalink of the Slack file.
        N)_idr   )r   r   r\   r   r   r   r2   7  s   
zSlackFile.__init__r   c                 C   s8   |    i }| jd ur| j|d< | jd ur| j|d< |S )Nr   r\   )ry   r   r   r   r   r   r   rI   G  s   



zSlackFile.to_dict)
r3   r4   r5   r7   r   r$   r2   r   r   rI   r   r   r   r   r   4  s    
r   )r)   r8   r   typingr   r   r   r   r   r   r   slack_sdk.modelsr	   slack_sdk.models.basic_objectsr
   r   slack_sdk.models.messagesr   ButtonStylesDynamicSelectElementTypesr   r%   r'   rX   r~   r   r   r   r   r   r   r   r   r   <module>   s(    $;!6 Wb"