o
    aqe                     @   s   d dl Z d dlZd dlmZ d dlmZmZmZmZ d dl	Z	d dl	m
Z
mZ d dlmZ ddl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 G dd dZdS )    N)
SSLContext)DictUnionListOptional)	BasicAuthClientSession)SlackApiError   )_debug_log_response_build_request_headers_build_body)WebhookResponse   )get_user_agent)
Attachment)Blockc                   @   sH  e Zd Zee Z									ddededee	 dee dee
 d	ed
ee deeeef  dee dee fddZ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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S ) AsyncWebhookClient   NFurltimeoutsslproxysessiontrust_env_in_sessionauthdefault_headersuser_agent_prefixuser_agent_suffixc                 C   sL   || _ || _|| _|| _|| _|| _|| _|r|ni | _t|	|
| jd< dS )a  API client for Incoming Webhooks and response_url
        :param url: a complete URL to send data (e.g., https://hooks.slack.com/XXX)
        :param timeout: request timeout (in seconds)
        :param ssl: ssl.SSLContext to use for requests
        :param proxy: proxy URL (e.g., localhost:9000, http://localhost:9000)
        :param session: a complete aiohttp.ClientSession
        :param trust_env_in_session: True/False for aiohttp.ClientSession
        :param auth: Basic auth info for aiohttp.ClientSession
        :param default_headers: request headers to add to all requests
        :param user_agent_prefix: prefix for User-Agent header value
        :param user_agent_suffix: suffix for User-Agent header value
        z
User-AgentN)	r   r   r   r   r   r   r   r   r   )selfr   r   r   r   r   r   r   r   r   r    r    [/var/www/html/humari/django-venv/lib/python3.10/site-packages/slack/webhook/async_client.py__init__   s   zAsyncWebhookClient.__init__)textattachmentsblocksresponse_typeheadersr#   r$   r%   r&   r'   returnc                   s    | j ||||d|dI dH S )a  Performs a Slack API request and returns the result.
        :param text: the text message (even when having blocks, setting this as well is recommended as it works as fallback)
        :param attachments: a collection of attachments
        :param blocks: a collection of Block Kit UI components
        :param response_type: the type of message (either 'in_channel' or 'ephemeral')
        :param headers: request headers to append only for this request
        :return: API response
        )r#   r$   r%   r&   bodyr'   N)	send_dict)r   r#   r$   r%   r&   r'   r    r    r!   send9   s   zAsyncWebhookClient.sendr*   c                    s"   | j t|t| j|dI dH S )a<  Performs a Slack API request and returns the result.
        :param body: json data structure (it's still a dict at this point),
            if you give this argument, body_params and files will be skipped
        :param headers: request headers to append only for this request
        :return: API response
        r)   N)_perform_http_requestr   r   r   )r   r*   r'   r    r    r!   r+   T   s
   	
zAsyncWebhookClient.send_dictc                   s  t |}d|d< | jjtjkr!| jd| j d| d|  d}| jo*| jj	 }|r1| j}nt
jt
j| jd| j| jd}z||| j| jd	}|jd
| jfi |4 I dH c}i }z	| I dH }W n. t
jyz   | jd| j d Y n t jjy } zdt| }	t|	|d}~ww t| j|j||jd}
t| j|
 |
W  d  I dH  W |s| I dH  S S 1 I dH sw   Y  W |s| I dH  dS dS |s| I dH  w w )a  Performs an HTTP request and parses the response.
        :param url: a complete URL to send data (e.g., https://hooks.slack.com/XXX)
        :param body: request body data
        :param headers: complete set of request headers
        :return: API response
        zapplication/json;charset=utf-8zContent-TypezSending a request - url: z, body: z, headers: N)total)r   r   	trust_env)r'   datar   r   POSTz7No response data returned from the following API call: .z#Failed to parse the response body: )r   status_coder*   r'   )jsondumpsloggerlevelloggingDEBUGdebugr   r   closedaiohttpr   ClientTimeoutr   r   r   r   r   requestr#   ContentTypeError_loggerdecoderJSONDecodeErrorstrr	   r   statusr'   r   close)r   r*   r'   r   use_running_sessionrequest_kwargsresresponse_bodyemessagerespr    r    r!   r-   b   sj   
	 
z(AsyncWebhookClient._perform_http_request)	r   NNNFNNNN)N)__name__
__module____qualname__r8   	getLoggerr6   rC   intr   r   r   boolr   r   r"   r   r   anyr   r   r   r,   r+   r-   r    r    r    r!   r      s    
	

(




r   )r4   r8   r   r   typingr   r   r   r   r<   r   r   slack.errorsr	   internal_utilsr   r   r   webhook_responser   webr   web.classes.attachmentsr   web.classes.blocksr   r   r    r    r    r!   <module>   s    