o
    ~hq/                     @   s  d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZm	Z	m
Z
mZmZmZ d dlmZ d dlmZmZmZmZmZ d dlmZ d dlmZ d d	lmZ d
dlmZmZmZm Z  d
dl!m"Z" d dl#m$Z$ d dl%m&Z& d dl'm(Z) d dl*m+Z, d dl-m.Z. ddl/m0Z0 G dd dZ1dS )    N)HTTPResponse)
SSLContext)DictUnionSequenceOptionalListAny)	HTTPError)RequesturlopenOpenerDirectorProxyHandlerHTTPSHandler)SlackRequestError)
Attachment)Block   )_build_body_build_request_headers_debug_log_responseget_user_agent)WebhookResponse)default_retry_handlers)RetryHandler)HttpRequest)HttpResponse)
RetryState   )load_http_proxy_from_envc                   @   s  e Zd ZU eed< eed< ee ed< ee ed< eeef ed< e	j
ed< ee ed< 															d$dededee dee deeeef  d
ee dee dee	j
 deee  fddZd	d	d	d	d	d	d	d	d	d	d
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 dee dee dee deeeef  deeeef  defddZd%deeef deeeef  defddZdeeef deeef defdd Zded!efd"d#Zd	S )&WebhookClienturltimeoutsslproxydefault_headersloggerretry_handlers   Nuser_agent_prefixuser_agent_suffixc
                 C   s   || _ || _|| _|| _|r|ni | _t||| jd< |dur!|ntt| _	|	dur-|	nt
 | _| jdu s?t| j dkrOt| j	}
|
durM|
| _dS dS dS )a  API client for Incoming Webhooks and `response_url`

        https://api.slack.com/messaging/webhooks

        Args:
            url: Complete URL to send data (e.g., `https://hooks.slack.com/XXX`)
            timeout: Request timeout (in seconds)
            ssl: `ssl.SSLContext` to use for requests
            proxy: Proxy URL (e.g., `localhost:9000`, `http://localhost:9000`)
            default_headers: Request headers to add to all requests
            user_agent_prefix: Prefix for User-Agent header value
            user_agent_suffix: Suffix for User-Agent header value
            logger: Custom logger
            retry_handlers: Retry handlers
        z
User-AgentNr   )r!   r"   r#   r$   r%   r   logging	getLogger__name__r&   r   r'   lenstripr   )selfr!   r"   r#   r$   r%   r)   r*   r&   r'   env_variable r2   P/var/www/html/zoom/venv/lib/python3.10/site-packages/slack_sdk/webhook/client.py__init__%   s   

zWebhookClient.__init__)
textattachmentsblocksresponse_typereplace_originaldelete_originalunfurl_linksunfurl_mediametadataheadersr5   r6   r7   r8   r9   r:   r;   r<   r=   r>   returnc       
         C   s"   | j |||||||||	d	|
dS )a  Performs a Slack API request and returns the result.

        Args:
            text: The text message
                (even when having blocks, setting this as well is recommended as it works as fallback)
            attachments: A collection of attachments
            blocks: A collection of Block Kit UI components
            response_type: The type of message (either 'in_channel' or 'ephemeral')
            replace_original: True if you use this option for response_url requests
            delete_original: True if you use this option for response_url requests
            unfurl_links: Option to indicate whether text url should unfurl
            unfurl_media: Option to indicate whether media url should unfurl
            metadata: Metadata attached to the message
            headers: Request headers to append only for this request

        Returns:
            Webhook response
        )	r5   r6   r7   r8   r9   r:   r;   r<   r=   bodyr>   )	send_dict)r0   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r2   r2   r3   sendN   s    zWebhookClient.sendrA   c                 C   s   | j t|t| j|dS )aY  Performs a Slack API request and returns the result.

        Args:
            body: JSON data structure (it's still a dict at this point),
                if you give this argument, body_params and files will be skipped
            headers: Request headers to append only for this request
        Returns:
            Webhook response
        r@   )_perform_http_requestr   r   r%   )r0   rA   r>   r2   r2   r3   rB      s   

zWebhookClient.send_dictc                C   s"  t |}d|d< | jjtjkr | jd| j d| d|  | j}td||	d|d}d }d }t
 }d	}|d
k r|d7 }d|_z	| ||}|W S  ty }	 z|	j p[d}
|	 |
}t|	j }t||	j||d}|	jdkrd|jvrd|jv r|jd |jd< d|jvrd|jv r|jd |jd< t| j| t|}t|	jdd |	j D |d ur|	dnd d}| jD ]4}|j||||	dr| jjtjkr| jdt|j d|j d|j  d|	  |j!||||	d  nq|jdu r|W  Y d }	~	S W Y d }	~	nxd }	~	w t"y } zg|}| j#d|  t|}| jD ]E}|j||d |dro| jjtjkrV| jdt|j d|j d|j  d|  |j!||d |d | jd|j d|j    nq+|jdu ry|W Y d }~nd }~ww |d
k s<|d ur|S |)Nzapplication/json;charset=utf-8zContent-TypezSending a request - url: z, body: z, headers: POSTutf-8)methodr!   datar>   r   d   r   Fr!   status_coderA   r>   i  zretry-afterzRetry-Afterc                 S   s   i | ]\}}||gqS r2   r2   ).0kvr2   r2   r3   
<dictcomp>   s    z7WebhookClient._perform_http_request.<locals>.<dictcomp>)rK   r>   rH   )staterequestresponseerrorzA retry handler found: z for  z - z.Failed to send a request to Slack API server: z!Going to retry the same request: )$jsondumpsr&   levelr+   DEBUGdebugr!   r   encoder   next_attempt_requested_perform_http_request_internalr
   r>   get_content_charsetreaddecodedictitemsr   coder   RetryHttpRequestfrom_urllib_http_requestRetryHttpResponser'   	can_retryinfotyper-   rG   full_urlprepare_for_next_attempt	ExceptionrS   )r0   rA   r>   r!   reqresp
last_errorretry_statecounter_for_safetyecharsetresponse_bodyresponse_headersretry_requestretry_responsehandlererrr2   r2   r3   rD      s   
 



$

$
Xz#WebhookClient._perform_http_requestrl   c                 C   s   d }|  dr1| jd ur0t| jtr'tjt| j| jdt	| j
d}ntd| j dntd| d }|rE|j|| jd}n	t|| j
| jd}|j pTd	}| |}t||j||jd
}t| j| |S )Nhttp)ry   https)contextzInvalid proxy detected: z must be a str valuezInvalid URL detected: )r"   )r{   r"   rF   rJ   )lower
startswithr$   
isinstancestrurllibrQ   build_openerr   r   r#   r   openr"   r   r>   r]   r^   r_   r   statusr   r&   )r0   r!   rl   opener	http_resprr   rs   rm   r2   r2   r3   r\      s2   

	z,WebhookClient._perform_http_request_internal)r(   NNNNNNN)N)r-   
__module____qualname__r   __annotations__intr   r   r   r+   Loggerr   r   r4   r   r   r	   r   r   boolr   rC   rB   rD   r   r\   r2   r2   r2   r3   r       s   
 
	


,	

,1&lr    )2rU   r+   r   http.clientr   r#   r   typingr   r   r   r   r   r	   urllib.errorr
   urllib.requestr   r   r   r   r   slack_sdk.errorsr   slack_sdk.models.attachmentsr   slack_sdk.models.blocksr   internal_utilsr   r   r   r   webhook_responser   slack_sdk.http_retryr   slack_sdk.http_retry.handlerr   slack_sdk.http_retry.requestr   rc   slack_sdk.http_retry.responser   re   slack_sdk.http_retry.stater   proxy_env_variable_loaderr   r    r2   r2   r2   r3   <module>   s(     