o
    HEDi                 	   @   s  d dl Z d dlZ d dlZd dlZd dlZd dlZd dlZd dl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mZ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" ddl#m$Z$ dZ%dZ&dZ'dZ(dZ)dZ*dZ+e,dZ-e,dZ.e/ Z0e1e2Z3de4de5fddZ6deje4ej,ej7f fddZ8e8e-e. G dd  d ej9Z:G d!d" d"ej9Z;e%e&fd#ej<fd$d%Z=e%fd&d'Z>G d(d) d)Z?G d*d+ d+Z@G d,d- d-ZAG d.d/ d/ZBG d0d1 d1ZCG d2d3 d3ZDG d4d5 d5e?e@eDeAeBeCZEG d6d7 d7e?e@eAeCZFG d8d9 d9e?e@eAeCZGG d:d; d;e?e@eAeCZHG d<d= d=e?e@eAeCZIG d>d? d?e?e@eAeCZJG d@dA dAe?e@eAeCZKG dBdC dCe?e@eAeCZLG dDdE dEe?e@eAeCZMG dFdG dGe?e@eAeCZNG dHdI dIe?e@eAeCZOG dJdK dKe?e@eAeCZPG dLdM dMe?ZQG dNdO dOe?ZRG dPdQ dQe?ZSG dRdS dSe?ZTG dTdU dUe?ZUG dVdW dWe?ZVG dXdY dYe?ZWG dZd[ d[e?ZXG d\d] d]e?eAZYG d^d_ d_e?ZZG d`da dae?Z[G dbdc dce?Z\G ddde dee?eDeBZ]G dfdg dge?Z^G dhdi die?Z_G djdk dke?Z`G dldm dme?e@eAeCZaG dndo doe?ZbG dpdq dqe?ZcG drds dse?ZdG dtdu due?ZeG dvdw dwe?ZfG dxdy dye?e@eAZgG dzd{ d{e?ZhG d|d} d}e?ZiG d~d de?e@eAeCZjdS )    N)DictListOptionalUnion)webHTTPGone   )types)api)	ParseMode)BooleanFloatIntegerString)helpermarkdown)json)warn_deprecated)TimeoutWarning)prepare_argz/webhookwebhook_handlerBOT_DISPATCHER7   webhookWEBHOOK_CONNECTIONWEBHOOK_REQUESTz149.154.160.0/20z91.108.4.0/22ipreturnc                 C   s   t | }|tv S )z8
    Check IP in range

    :param ip:
    :return:
    )	ipaddressIPv4Addressallowed_ips)r   address r#   i/var/www/www-root/data/www/ovozai.pdev.uz/venv/lib/python3.10/site-packages/aiogram/dispatcher/webhook.py	_check_ip*   s   
r%   ipsc                  G   sv   | D ]6}t |tjrt| qt |trtt| qt |tjr,t|  qt	dt
| d| ddS )z9
    Allow ip address.

    :param ips:
    :return:
    zBad type of ipaddress: z ('z')N)
isinstancer   r    r!   addstrIPv4Networkupdatehosts
ValueErrortype)r&   r   r#   r#   r$   allow_ip5   s   
r/   c                   @   s`   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd ZdS )WebhookRequestHandlera  
    Simple Webhook request handler for aiohttp web server.

    You need to register that in app:

    .. code-block:: python3

        app.router.add_route('*', '/your/webhook/path', WebhookRequestHandler, name='webhook_handler')

    But first you need to configure application for getting Dispatcher instance from request handler!
    It must always be with key 'BOT_DISPATCHER'

    .. code-block:: python3

        bot = Bot(TOKEN, loop)
        dp = Dispatcher(bot)
        app['BOT_DISPATCHER'] = dp

    c                 C   sN   | j jt }zddlm}m} || ||j W |S  ty&   Y |S w )zh
        Get Dispatcher instance from environment

        :return: :class:`aiogram.Dispatcher`
        r   )Bot
Dispatcher)	requestappBOT_DISPATCHER_KEYaiogramr1   r2   set_currentbotRuntimeError)selfdpr1   r2   r#   r#   r$   get_dispatcher`   s   
z$WebhookRequestHandler.get_dispatcherc                    s"   | j  I dH }tjdi |S )z
        Read update from stream and deserialize it.

        :param bot: bot instance. You an get it from Dispatcher
        :return: :class:`aiogram.types.Update`
        Nr#   )r3   r   r
   Update)r:   r8   datar#   r#   r$   parse_updateo   s   z"WebhookRequestHandler.parse_updatec                    s   |    |  }| |jI dH }| |I dH }| |}|r&| }ntjdd}| j	j
ddr?t| j	j
d |jd< |S )z
        Process POST request

        if one of handler returns instance of :class:`aiogram.dispatcher.webhook.BaseResponse` return it to webhook.
        Otherwise do nothing (return 'ok')

        :return: :class:`aiohttp.web.Response`
        NoktextRETRY_AFTERzRetry-After)validate_ipr<   r?   r8   process_updateget_responseget_web_responser   Responser3   r4   getr)   headers)r:   
dispatcherr+   resultsresponseweb_responser#   r#   r$   posty   s   	

zWebhookRequestHandler.postc                       |    tjddS N rA   rD   r   rH   r:   r#   r#   r$   rI         zWebhookRequestHandler.getc                    rP   rQ   rS   rT   r#   r#   r$   head   rU   zWebhookRequestHandler.headc                    s   |   }t }| }|ttjj|}t	tjj|}t
|j|}|| z9z|I dH  W n tjyF   || |   w | rT| W |  S || || j W |  dS |  w )a  
        Need respond in less than 60 seconds in to webhook.

        So... If you respond greater than 55 seconds webhook automatically respond 'ok'
        and execute callback response via simple HTTP request.

        :param update:
        :return:
        N)r<   asyncioget_event_loopcreate_future
call_laterRESPONSE_TIMEOUTtasks_release_waiter	functoolspartialensure_futureupdates_handlernotifyadd_done_callbackCancelledErrorremove_done_callbackcanceldoneresultrespond_via_request)r:   r+   rK   loopwaitertimeout_handlecbfutr#   r#   r$   rE      s,   




z$WebhookRequestHandler.process_updatec              
   C   s   t dt dt |  }t }z| }W n! ty8 } z||j	
|tj | W Y d}~dS d}~ww | |}|durMt||j dS dS )zY
        Handle response after 55 second.

        :param task:
        :return:
        z3Detected slow response into webhook. (Greater than zc seconds)
Recommended to use 'async_task' decorator from Dispatcher for handler with long timeouts.N)warnr[   r   r<   rW   get_running_looprh   	Exceptioncreate_taskerrors_handlersrb   r
   r=   get_currentrF   r`   execute_responser8   )r:   taskrK   rj   rL   erM   r#   r#   r$   ri      s&   
z)WebhookRequestHandler.respond_via_requestc                 C   s4   |du rdS t j|D ]}t|tr|  S qdS )zb
        Get response object from results.

        :param results: list
        :return:
        N)	itertoolschainfrom_iterabler'   BaseResponse)r:   rL   rh   r#   r#   r$   rF      s   
z"WebhookRequestHandler.get_responsec                 C   s\   | j jdd}|r|dd }|t|fS | j jd}|dur,|\}}|t|fS dS )z`
        Check client IP. Accept requests only from telegram servers.

        :return:
        zX-Forwarded-ForN,r   peername)NF)r3   rJ   rI   splitr%   	transportget_extra_info)r:   forwarded_for	peer_namehost_r#   r#   r$   check_ip   s   zWebhookRequestHandler.check_ipc                 C   s@   | j jddr|  \}}|std|  t dS dS )z_
        Check ip if that is needed. Raise web.HTTPUnauthorized for not allowed hosts.
        r%   Fz*Blocking request from an unauthorized IP: N)r3   r4   rI   r   logwarningr   HTTPUnauthorized)r:   
ip_addressacceptr#   r#   r$   rD     s   z!WebhookRequestHandler.validate_ipN)__name__
__module____qualname____doc__r<   r?   rO   rI   rV   rE   ri   rF   r   rD   r#   r#   r#   r$   r0   K   s    
%r0   c                   @   s    e Zd ZdZdd Zdd ZdS )GoneRequestHandlerz
    If a webhook returns the HTTP error 410 Gone for all requests for more than 23 hours successively,
    it can be automatically removed.
    c                       t  Nr   rT   r#   r#   r$   rI        zGoneRequestHandler.getc                    r   r   r   rT   r#   r#   r$   rO     r   zGoneRequestHandler.postN)r   r   r   r   rI   rO   r#   r#   r#   r$   r     s    r   r4   c                 C   s    |j jd|t|d | |t< dS )a  
    You can prepare web.Application for working with webhook handler.

    :param dispatcher: Dispatcher instance
    :param app: :class:`aiohttp.web.Application`
    :param path: Path to your webhook.
    :param route_name: Name of webhook handler route
    :return:
    *)nameN)router	add_router0   r5   )rK   r4   path
route_namer#   r#   r$   configure_app  s   
r   c                 C   s   t  }t| || |S )z
    Create new :class:`aiohttp.web.Application` and configure it.

    :param dispatcher: Dispatcher instance
    :param path: Path to your webhook.
    :return:
    )r   Applicationr   )rK   r   r4   r#   r#   r$   get_new_configured_app)  s   r   c                   @   st   e Zd ZdZedefddZdejfddZ	dejfddZ
d	d
 Zdd Zdd ZdddZdd Zdd ZdS )r{   z+
    Base class for webhook responses.
    r   c                 C      t )zj
        In all subclasses of that class you need to override this property

        :return: str
        NotImplementedErrorrT   r#   r#   r$   method;  s   zBaseResponse.methodc                 C   r   )z^
        You need to override this method.

        :return: response parameters dict
        r   rT   r#   r#   r$   prepareD  s   zBaseResponse.preparec                 C   s   dd |    D S )zs
        Cleanup response after preparing. Remove empty fields.

        :return: response parameters dict
        c                 S   s   i | ]\}}|d ur||qS r   r#   ).0kvr#   r#   r$   
<dictcomp>R  s    z(BaseResponse.cleanup.<locals>.<dictcomp>)r   itemsrT   r#   r#   r$   cleanupL  s   zBaseResponse.cleanupc                 C   s   d| j i|  S )z7
        Get response object

        :return:
        r   )r   r   rT   r#   r#   r$   rF   T  s   zBaseResponse.get_responsec                 C   s   t j|  tjdS )zk
        Get prepared web response with JSON data.

        :return: :class:`aiohttp.web.Response`
        )dumps)r   json_responserF   r   r   rT   r#   r#   r$   rG   \  s   zBaseResponse.get_web_responsec                    sV   t j| jt jj}t||d}|r|di |  I dH S || j|  I dH S )z
        Use this method if you want to execute response as simple HTTP request.

        :param bot: Bot instance.
        :return:
        Nr#   )r   
HelperModeapplyr   
snake_casegetattrr   r3   )r:   r8   method_namer   r#   r#   r$   ru   d  s   zBaseResponse.execute_responseNc                    s.   |d u rddl m} | }| |I d H S )Nr   r1   )r6   r1   rt   ru   )r:   r8   r1   r#   r#   r$   __call__q  s
   zBaseResponse.__call__c                    s   | S r   r#   rT   r#   r#   r$   
__aenter__w  s   zBaseResponse.__aenter__c                    s   |  I d H S r   r#   )r:   exc_typeexc_valexc_tbr#   r#   r$   	__aexit__z  s   zBaseResponse.__aexit__r   )r   r   r   r   propertyr)   r   typingr   r   r   rF   rG   ru   r   r   r   r#   r#   r#   r$   r{   6  s    
r{   c                   @   sR   e Zd ZdZdejeejf fddZ	dejejej
ejjejjf fddZdS )	ReplyToMixinzE
    Mixin for responses where from which can reply to messages.
    messagec                 C   s(   t | dt|tjr|j | S | | S )zu
        Reply to message

        :param message: :obj:`int` or  :obj:`types.Message`
        :return: self
        reply_to_message_id)setattrr'   r
   Message
message_idr:   r   r#   r#   r$   reply  s   zReplyToMixin.replytargetc                 C   sb   t |tjr|jj}nt |tjr|j}nt |ttfr|}n
tdt	| dt
| d| | S )z]
        Send to chat

        :param target: message or chat or id
        :return:
        zBad type of target. ()chat_id)r'   r
   r   chatidChatintr)   	TypeErrorr.   r   )r:   r   r   r#   r#   r$   to  s   
zReplyToMixin.toN)r   r   r   r   r   r   r   r
   r   r   r   baser   r   r   r#   r#   r#   r$   r   ~  s    ,
r   c                   @   s   e Zd Zdd ZdS )DisableNotificationMixinc                 C      t | dd | S )z8
        Disable notification

        :return:
        disable_notificationTr   rT   r#   r#   r$   without_notification     z-DisableNotificationMixin.without_notificationN)r   r   r   r   r#   r#   r#   r$   r     s    r   c                   @       e Zd Zdd Zedd ZdS )DisableWebPagePreviewMixinc                 C   r   )z<
        Disable web page preview

        :return:
        disable_web_page_previewTr   rT   r#   r#   r$   no_web_page_preview  r   z.DisableWebPagePreviewMixin.no_web_page_previewc                  C   &   ddl m}  |  }|dur|jS dS )zP
        Detect global disable web page preview value

        :return:
        r   r   N)r6   r1   rt   r   r1   r8   r#   r#   r$    _global_disable_web_page_preview  
   z;DisableWebPagePreviewMixin._global_disable_web_page_previewN)r   r   r   r   staticmethodr   r#   r#   r#   r$   r         	r   c                   @   r   )ProtectContentMixinc                 C   r   )z3
        Protect content

        :return:
        protect_contentTr   rT   r#   r#   r$   r     r   z#ProtectContentMixin.protect_contentc                  C   r   )zG
        Detect global protect content value

        :return:
        r   r   N)r6   r1   rt   r   r   r#   r#   r$   _global_protect_content  r   z+ProtectContentMixin._global_protect_contentN)r   r   r   r   r   r   r#   r#   r#   r$   r     r   r   c                   @   s(   e Zd Zdd Zdd Zedd ZdS )ParseModeMixinc                 C      t | dtj | S )z:
        Set parse_mode to HTML

        :return:
        
parse_mode)r   r   HTMLrT   r#   r#   r$   as_html     zParseModeMixin.as_htmlc                 C   r   )z>
        Set parse_mode to Markdown

        :return:
        r   )r   r   MARKDOWNrT   r#   r#   r$   as_markdown  r   zParseModeMixin.as_markdownc                  C   r   )z<
        Detect global parse mode

        :return:
        r   r   N)r6   r1   rt   r   r   r#   r#   r$   _global_parse_mode  r   z!ParseModeMixin._global_parse_modeN)r   r   r   r   r   r   r   r#   r#   r#   r$   r     s
    		r   c                   @   s   e Zd ZdZdZejjZ								dde	e
ef dedee dee dee d	ee d
ee
 dee	ejejeef  fddZdefddZddddZddddZdS )SendMessagez
    You can send message with webhook by using this instance of this object.
    All arguments is equal with Bot.send_message method.
    r   rB   r   r   r   r   r   reply_markupNr   rB   r   r   r   r   r   r   c	           	      C   sp   |du rd}|du r|   }|du r|  }|du r|  }|| _|| _|| _|| _|| _|| _|| _	|| _
dS )a  
        :param chat_id: Union[Integer, String] - Unique identifier for the target chat or username
            of the target channel (in the format @channelusername)
        :param text: String - Text of the message to be sent
        :param parse_mode: String (Optional) - Send Markdown or HTML, if you want Telegram apps to show bold,
            italic, fixed-width text or inline URLs in your bot's message.
        :param disable_web_page_preview: Boolean (Optional) - Disables link previews for links in this message
        :param disable_notification: Boolean (Optional) - Sends the message silently. Users will receive
            a notification with no sound.
        :param protect_content: Boolean (Optional) - Protects the contents of sent messages
            from forwarding and saving
        :param reply_to_message_id: Integer (Optional) - If the message is a reply, ID of the original message
        :param reply_markup: Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, Dict, String] (Optional)
            - Additional interface options. A JSON-serialized object for an inline keyboard,
            custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
        NrR   )r   r   r   r   rB   r   r   r   r   r   r   )	r:   r   rB   r   r   r   r   r   r   r#   r#   r$   __init__  s    
zSendMessage.__init__r   c              	   C   *   | j | j| j| j| j| j| jt| jdS )Nr   )	r   rB   r   r   r   r   r   r   r   rT   r#   r#   r$   r   3     zSendMessage.prepare )sepc                G   s"   |  j tj g ||R  7  _ | S )zc
        Write text to response

        :param text:
        :param sep:
        :return:
        rB   r   r:   r   rB   r#   r#   r$   write?  s   zSendMessage.writec                G   sH   | j r| j d dkr|  j d7  _ |  j tj g ||R  d 7  _ | S )zW
        Write line

        :param text:
        :param sep:
        :return:
        
r   r   r#   r#   r$   write_lnJ  s   "zSendMessage.write_lnNNNNNNNN)r   r   r   r   	__slots__r   MethodsSEND_MESSAGEr   r   r   r   r   r   r
   InlineKeyboardMarkupReplyKeyboardMarkupr   r   dictr   r   r   r#   r#   r#   r$   r     s@    
+r   c                   @   s|   e Zd ZdZdZejjZ					dde	e
ef de	e
ef de
dee dee f
d	d
ZdejfddZdefddZdS )ForwardMessagezP
    Use that response type for forward messages of any kind on to webhook.
    r   from_chat_idr   r   r   Nr   r   r   r   r   c                 C   s2   |du r|   }|| _|| _|| _|| _|| _dS )a  
        :param chat_id: Union[Integer, String] - Unique identifier for the target chat or username of the
            target channel (in the format @channelusername)
        :param from_chat_id: Union[Integer, String] - Unique identifier for the chat where the original
            message was sent (or channel username in the format @channelusername)
        :param disable_notification: Boolean (Optional) - Sends the message silently. Users will receive a
            notification with no sound.
        :param protect_content: Boolean (Optional) - Protects the contents of sent messages
            from forwarding and saving
        :param message_id: Integer - Message identifier in the chat specified in from_chat_id
        N)r   r   r   r   r   r   )r:   r   r   r   r   r   r#   r#   r$   r   `  s   
zForwardMessage.__init__r   c                 C   s"   t | d|jj t | d|j | S )zQ
        Select target message

        :param message:
        :return:
        r   r   )r   r   r   r   r   r#   r#   r$   r   y  s   zForwardMessage.messager   c                 C      | j | j| j| j| jdS )Nr   r   rT   r#   r#   r$   r        zForwardMessage.prepareNNNNN)r   r   r   r   r   r   r   FORWARD_MESSAGEr   r   r   r   r   r   r   r
   r   r   r   r   r#   r#   r#   r$   r   X  s(    

r   c                   @      e Zd ZdZdZejjZ					dde	e
ef dedee dee dee d	ee
 d
ee	ejejeef  fddZdd ZdS )	SendPhotoz>
    Use that response type for send photo on to webhook.
    r   photocaptionr   r   r   r   Nr   r  r  r   r   r   r   c                 C   >   |du r|   }|| _|| _|| _|| _|| _|| _|| _dS )a3  
        :param chat_id: Union[Integer, String] - Unique identifier for the target chat or username of
            the target channel (in the format @channelusername)
        :param photo: String - Photo to send. Pass a file_id as String to send
            a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for
            Telegram to get a photo from the Internet, or upload a new photo using multipart/form-data.
        :param caption: String (Optional) - Photo caption (may also be used when resending photos by file_id),
            0-1024 characters after entities parsing
        :param disable_notification: Boolean (Optional) - Sends the message silently. Users will receive
            a notification with no sound.
        :param protect_content: Boolean (Optional) - Protects the contents of sent messages
            from forwarding and saving
        :param reply_to_message_id: Integer (Optional) - If the message is a reply, ID of the original message
        :param reply_markup: Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, Dict, String] (Optional)
            - Additional interface options. A JSON-serialized object for an inline keyboard,
            custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
        N)r   r   r  r  r   r   r   r   )r:   r   r  r  r   r   r   r   r#   r#   r$   r     s   
zSendPhoto.__init__c                 C   &   | j | j| j| j| j| jt| jdS )Nr  )r   r  r  r   r   r   r   r   rT   r#   r#   r$   r        zSendPhoto.preparer   )r   r   r   r   r   r   r   
SEND_PHOTOr   r   r   r   r   r   r
   r   r   r   r   r   r#   r#   r#   r$   r    s2    
$r  c                   @   s   e Zd ZdZdZejjZ								dde	e
ef dedee dee
 dee d	ee d
ee dee dee
 dee	ejejeef  fddZdd ZdS )	SendAudioz>
    Use that response type for send audio on to webhook.
    
r   audior  duration	performertitler   r   r   r   Nr   r  r  r  r  r  r   r   r   r   c                 C   P   |du r|   }|| _|| _|| _|| _|| _|| _|| _|| _|	| _	|
| _
dS )a  
        :param chat_id: Union[Integer, String] - Unique identifier for the target chat or username
            of the target channel (in the format @channelusername)
        :param audio: String - Audio file to send. Pass a file_id as String
            to send an audio file that exists on the Telegram servers (recommended), pass an HTTP URL
            as a String for Telegram to get an audio file from the Internet, or upload a new one
            using multipart/form-data.
        :param caption: String (Optional) - Audio caption, 0-1024 characters after entities parsing
        :param duration: Integer (Optional) - Duration of the audio in seconds
        :param performer: String (Optional) - Performer
        :param title: String (Optional) - Track name
        :param disable_notification: Boolean (Optional) - Sends the message silently.
            Users will receive a notification with no sound.
        :param protect_content: Boolean (Optional) - Protects the contents of sent messages
            from forwarding and saving
        :param reply_to_message_id: Integer (Optional) - If the message is a reply, ID of the original message
        :param reply_markup: Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, Dict, String] (Optional)
            - Additional interface options. A JSON-serialized object for an inline keyboard,
            custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
        N)r   r   r  r  r  r  r  r   r   r   r   )r:   r   r  r  r  r  r  r   r   r   r   r#   r#   r$   r     s   
zSendAudio.__init__c                 C   2   | j | j| j| j| j| j| j| j| jt	| j
d
S )Nr  )r   r  r  r  r  r  r   r   r   r   r   rT   r#   r#   r$   r         zSendAudio.preparer   )r   r   r   r   r   r   r   
SEND_AUDIOr   r   r   r   r   r   r
   r   r   r   r   r   r#   r#   r#   r$   r
    sD    	
-r
  c                   @   r  )SendDocumentzA
    Use that response type for send document on to webhook.
    r   documentr  r   r   r   r   Nr   r  r  r   r   r   r   c                 C   r  )aC  
        :param chat_id: Union[Integer, String] - Unique identifier for the target chat or username
            of the target channel (in the format @channelusername)
        :param document: String - File to send. Pass a file_id as String
            to send a file that exists on the Telegram servers (recommended), pass an HTTP URL
            as a String for Telegram to get a file from the Internet, or upload a new one
            using multipart/form-data.
        :param caption: String (Optional) - Document caption
            (may also be used when resending documents by file_id), 0-1024 characters after entities parsing
        :param disable_notification: Boolean (Optional) - Sends the message silently.
            Users will receive a notification with no sound.
        :param protect_content: Boolean (Optional) - Protects the contents of sent messages
            from forwarding and saving
        :param reply_to_message_id: Integer (Optional) - If the message is a reply, ID of the original message
        :param reply_markup: Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, Dict, String] (Optional)
            - Additional interface options. A JSON-serialized object for an inline keyboard,
            custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
        N)r   r   r  r  r   r   r   r   )r:   r   r  r  r   r   r   r   r#   r#   r$   r     s   
zSendDocument.__init__c                 C   r  )Nr  )r   r  r  r   r   r   r   r   rT   r#   r#   r$   r   >  r  zSendDocument.preparer   )r   r   r   r   r   r   r   SEND_DOCUMENTr   r   r   r   r   r   r
   r   r   r   r   r   r#   r#   r#   r$   r    s2    
%r  c                   @   s   e Zd ZdZdZejjZ								dde	e
ef dedee
 dee
 dee
 d	ee d
ee dee dee
 dee	ejejeef  fddZdd ZdS )	SendVideoz>
    Use that response type for send video on to webhook.
    
r   videor  widthheightr  r   r   r   r   Nr   r  r  r  r  r  r   r   r   r   c                 C   r  )a  
        :param chat_id: Union[Integer, String] - Unique identifier for the target chat or username
            of the target channel (in the format @channelusername)
        :param video: String - Video to send. Pass a file_id as String
            to send a video that exists on the Telegram servers (recommended), pass an HTTP URL
            as a String for Telegram to get a video from the Internet, or upload a new video
            using multipart/form-data.
        :param duration: Integer (Optional) - Duration of sent video in seconds
        :param width: Integer (Optional) - Video width
        :param height: Integer (Optional) - Video height
        :param caption: String (Optional) - Video caption (may also be used when resending videos by file_id),
            0-1024 characters after entities parsing
        :param disable_notification: Boolean (Optional) - Sends the message silently.
            Users will receive a notification with no sound.
        :param protect_content: Boolean (Optional) - Protects the contents of sent messages
            from forwarding and saving
        :param reply_to_message_id: Integer (Optional) - If the message is a reply, ID of the original message
        :param reply_markup: Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, Dict, String] (Optional)
            - Additional interface options. A JSON-serialized object for an inline keyboard,
            custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
        N)r   r   r  r  r  r  r  r   r   r   r   )r:   r   r  r  r  r  r  r   r   r   r   r#   r#   r$   r   U  s    
zSendVideo.__init__c                 C   r  )Nr  )r   r  r  r  r  r  r   r   r   r   r   rT   r#   r#   r$   r     r  zSendVideo.preparer   )r   r   r   r   r   r   r   
SEND_VIDEOr   r   r   r   r   r   r
   r   r   r   r   r   r#   r#   r#   r$   r  J  sD    	
.r  c                   @   s   e Zd ZdZdZejjZ						dde	e
ef dedee dee
 dee d	ee d
ee
 dee	ejejeef  fddZdd ZdS )	SendVoicez>
    Use that response type for send voice on to webhook.
    r   voicer  r  r   r   r   r   Nr   r   r  r  r   r   r   r   c	           	      C   D   |du r|   }|| _|| _|| _|| _|| _|| _|| _|| _dS )a_  
        :param chat_id: Union[Integer, String] - Unique identifier for the target chat or username
            of the target channel (in the format @channelusername)
        :param voice: String - Audio file to send. Pass a file_id as String
            to send a file that exists on the Telegram servers (recommended), pass an HTTP URL
            as a String for Telegram to get a file from the Internet, or upload a new one
            using multipart/form-data.
        :param caption: String (Optional) - Voice message caption, 0-1024 characters after entities parsing
        :param duration: Integer (Optional) - Duration of the voice message in seconds
        :param disable_notification: Boolean (Optional) - Sends the message silently.
            Users will receive a notification with no sound.
        :param protect_content: Boolean (Optional) - Protects the contents of sent messages
            from forwarding and saving
        :param reply_to_message_id: Integer (Optional) - If the message is a reply, ID of the original message
        :param reply_markup: Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, Dict, String] (Optional)
            - Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard,
            instructions to remove reply keyboard or to force a reply from the user.
        N)	r   r   r   r  r  r   r   r   r   )	r:   r   r   r  r  r   r   r   r   r#   r#   r$   r     s   
zSendVoice.__init__c              	   C   r   )Nr  )	r   r   r  r  r   r   r   r   r   rT   r#   r#   r$   r     r   zSendVoice.prepareNNNNNN)r   r   r   r   r   r   r   
SEND_VOICEr   r   r   r   r   r   r
   r   r   r   r   r   r#   r#   r#   r$   r    s8    
'r  c                   @   s   e Zd ZdZdZejjZ						dde	e
ef dedee
 dee
 dee d	ee d
ee
 dee	ejejeef  fddZdd ZdS )SendVideoNotezC
    Use that response type for send video note on to webhook.
    r   
video_noter  lengthr   r   r   r   Nr   r&  r  r'  r   r   r   r   c	           	      C   r!  )a  
        :param chat_id: Union[Integer, String] - Unique identifier for the target chat or username
            of the target channel (in the format @channelusername)
        :param video_note: String - Video note to send. Pass a file_id
            as String to send a video note that exists on the Telegram servers (recommended)
            or upload a new video using multipart/form-data. Sending video notes by a URL is currently unsupported
        :param duration: Integer (Optional) - Duration of sent video in seconds
        :param length: Integer (Optional) - Video width and height
        :param disable_notification: Boolean (Optional) - Sends the message silently.
            Users will receive a notification with no sound.
        :param protect_content: Boolean (Optional) - Protects the contents of sent messages
            from forwarding and saving
        :param reply_to_message_id: Integer (Optional) - If the message is a reply, ID of the original message
        :param reply_markup: Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, Dict, String] (Optional)
            - Additional interface options. A JSON-serialized object for an inline keyboard,
            custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
        N)	r   r   r&  r  r'  r   r   r   r   )	r:   r   r&  r  r'  r   r   r   r   r#   r#   r$   r     s   
zSendVideoNote.__init__c              	   C   r   )Nr%  )	r   r&  r  r'  r   r   r   r   r   rT   r#   r#   r$   r      r   zSendVideoNote.preparer"  )r   r   r   r   r   r   r   SEND_VIDEO_NOTEr   r   r   r   r   r   r
   r   r   r   r   r   r#   r#   r#   r$   r$    s8    
&r$  c                   @   s   e Zd ZdZdZejjZ				dde	e
ef de	ejef deje dee deje
 f
d	d
Zdd ZddedefddZ		ddedede
de
de
f
ddZdS )SendMediaGroupzJ
    Use this method to send a group of photos or videos as an album.
    )r   mediar   r   r   Nr   r*  r   r   r   c                 C   sX   |du r	t  }n
t|trt |}|du r|  }|| _|| _|| _|| _|| _	dS )a-  
        Use this method to send a group of photos or videos as an album.

        Source: https://core.telegram.org/bots/api#sendmediagroup

        :param chat_id:	Unique identifier for the target chat or username of the target channel
        :type chat_id: :obj:`typing.Union[base.Integer, base.String]`
        :param media: A JSON-serialized array describing photos and videos to be sent
        :type media: :obj:`typing.Union[types.MediaGroup, typing.List]`
        :param disable_notification: Sends the message silently. Users will receive a notification with no sound.
        :type disable_notification: :obj:`typing.Optional[base.Boolean]`
        :param protect_content: Boolean (Optional) - Protects the contents of sent messages
            from forwarding and saving
        :param reply_to_message_id: If the message is a reply, ID of the original message
        :type reply_to_message_id: :obj:`typing.Optional[base.Integer]`
        :return: On success, an array of the sent Messages is returned.
        :rtype: typing.List[types.Message]
        N)
r
   
MediaGroupr'   listr   r   r*  disable_notificationsr   r   )r:   r   r*  r   r   r   r#   r#   r$   r     s   



zSendMediaGroup.__init__c                 C   s<   t | j }|rtdt| j}| j|| j| j| jdS )NzAllowed only file ID or URL's)r   r*  r-  r   r   )	r   r*  	get_filesr   r   r   r-  r   r   )r:   filesr*  r#   r#   r$   r   <  s   
zSendMediaGroup.preparer  r  c                 C   s   | j || | S )zc
        Attach photo

        :param photo:
        :param caption:
        :return: self
        )r*  attach_photo)r:   r  r  r#   r#   r$   r0  K  s   zSendMediaGroup.attach_photor  r  r  r  c                 C   s   | j j|||||d | S )z
        Attach video

        :param video:
        :param caption:
        :param width:
        :param height:
        :param duration:
        :return: self
        )r  r  r  )r*  attach_video)r:   r  r  r  r  r  r#   r#   r$   r1  V  s   zSendMediaGroup.attach_videoNNNNr   )r   r   r   r   r   r   r   SEND_MEDIA_GROUPr   r   r   r   r
   r+  r   r   r   r   r   r   r0  r1  r#   r#   r#   r$   r)    s4    
%r)  c                   @   s|   e Zd ZdZdZejjZ				dde	e
ef dededee dee d	ee
 d
ee	ejejeef  fddZdd ZdS )SendLocationzA
    Use that response type for send location on to webhook.
    r   latitude	longituder   r   r   r   Nr   r6  r7  r   r   r   r   c                 C   r  )a  
        :param chat_id: Union[Integer, String] - Unique identifier for the target chat or username
            of the target channel (in the format @channelusername)
        :param latitude: Float - Latitude of location
        :param longitude: Float - Longitude of location
        :param disable_notification: Boolean (Optional) - Sends the message silently.
            Users will receive a notification with no sound.
        :param protect_content: Boolean (Optional) - Protects the contents of sent messages
            from forwarding and saving
        :param reply_to_message_id: Integer (Optional) - If the message is a reply, ID of the original message
        :param reply_markup: Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, Dict, String] (Optional)
            - Additional interface options. A JSON-serialized object for an inline keyboard,
            custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
        N)r   r   r6  r7  r   r   r   r   )r:   r   r6  r7  r   r   r   r   r#   r#   r$   r   p  s   
zSendLocation.__init__c                 C   r  )Nr5  )r   r6  r7  r   r   r   r   r   rT   r#   r#   r$   r     r  zSendLocation.preparer2  )r   r   r   r   r   r   r   SEND_LOCATIONr   r   r   r   r   r   r   r
   r   r   r   r   r   r#   r#   r#   r$   r4  f  s0    
 r4  c                   @   s   e Zd ZdZdZejjZ					dde	e
ef dedededed	ee d
ee dee dee
 dee	ejejeef  fddZdd ZdS )	SendVenuez>
    Use that response type for send venue on to webhook.
    
r   r6  r7  r  r"   foursquare_idr   r   r   r   Nr   r6  r7  r  r"   r;  r   r   r   r   c                 C   r  )a  
        :param chat_id: Union[Integer, String] - Unique identifier for the target chat or username
            of the target channel (in the format @channelusername)
        :param latitude: Float - Latitude of the venue
        :param longitude: Float - Longitude of the venue
        :param title: String - Name of the venue
        :param address: String - Address of the venue
        :param foursquare_id: String (Optional) - Foursquare identifier of the venue
        :param disable_notification: Boolean (Optional) - Sends the message silently.
            Users will receive a notification with no sound.
        :param protect_content: Boolean (Optional) - Protects the contents of sent messages
            from forwarding and saving
        :param reply_to_message_id: Integer (Optional) - If the message is a reply, ID of the original message
        :param reply_markup: Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, Dict, String] (Optional)
            - Additional interface options. A JSON-serialized object for an inline keyboard,
            custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
        N)r   r   r6  r7  r  r"   r;  r   r   r   r   )r:   r   r6  r7  r  r"   r;  r   r   r   r   r#   r#   r$   r     s   
zSendVenue.__init__c                 C   r  )Nr:  )r   r6  r7  r  r"   r;  r   r   r   r   r   rT   r#   r#   r$   r     r  zSendVenue.preparer   )r   r   r   r   r   r   r   
SEND_VENUEr   r   r   r   r   r   r   r
   r   r   r   r   r   r#   r#   r#   r$   r9    s>    	
*r9  c                   @   s   e Zd ZdZdZejjZ					dde	e
ef dededee dee d	ee d
ee
 dee	ejejeef  fddZdd ZdS )SendContactz@
    Use that response type for send contact on to webhook.
    r   phone_number
first_name	last_namer   r   r   r   Nr   r?  r@  rA  r   r   r   r   c	           	      C   r!  )a"  
        :param chat_id: Union[Integer, String] - Unique identifier for the target chat or
            username of the target channel (in the format @channelusername)
        :param phone_number: String - Contact's phone number
        :param first_name: String - Contact's first name
        :param last_name: String (Optional) - Contact's last name
        :param disable_notification: Boolean (Optional) - Sends the message silently.
            Users will receive a notification with no sound.
        :param protect_content: Boolean (Optional) - Protects the contents of sent messages
            from forwarding and saving
        :param reply_to_message_id: Integer (Optional) - If the message is a reply, ID of the original message
        :param reply_markup: Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, Dict, String] (Optional)
            - Additional interface options. A JSON-serialized object for an inline keyboard,
            custom reply keyboard, instructions to remove keyboard or to force a reply from the user.
        N)	r   r   r?  r@  rA  r   r   r   r   )	r:   r   r?  r@  rA  r   r   r   r   r#   r#   r$   r     s   
zSendContact.__init__c              	   C   r   )Nr>  )	r   r?  r@  rA  r   r   r   r   r   rT   r#   r#   r$   r     r   zSendContact.preparer   )r   r   r   r   r   r   r   SEND_CONTACTr   r   r   r   r   r   r
   r   r   r   r   r   r#   r#   r#   r$   r=    s6    
$r=  c                   @   >   e Zd ZdZdZejjZde	e
ef defddZdd Zd	S )
SendChatActionzD
    Use that response type for send chat action on to webhook.
    r   actionr   rF  c                 C      || _ || _dS )aR  
        :param chat_id: Union[Integer, String] - Unique identifier for the target chat or username
            of the target channel (in the format @channelusername)
        :param action: String - Type of action to broadcast. Choose one, depending on what the user is about to receive:
            typing for text messages, upload_photo for photos, record_video or upload_video for videos,
            record_audio or upload_audio for audio files, upload_document for general files,
            find_location for location data, record_video_note or upload_video_note for video notes.
        NrE  )r:   r   rF  r#   r#   r$   r   %  s   	
zSendChatAction.__init__c                 C      | j | jdS )NrE  rE  rT   r#   r#   r$   r   1     zSendChatAction.prepareN)r   r   r   r   r   r   r   SEND_CHAT_ACTIONr   r   r   r   r   r   r#   r#   r#   r$   rD    s    rD  c                   @   sX   e Zd ZdZdZejjZ	dde	e
ef de
dee	e
ejejf  fddZd	d
 ZdS )KickChatMemberzD
    Use that response type for kick chat member on to webhook.
    r   user_id
until_dateNr   rM  rN  c                 C      || _ || _|| _dS )a  
        :param chat_id: Union[Integer, String] - Unique identifier for the target group or username
            of the target supergroup or channel (in the format @channelusername)
        :param user_id: Integer - Unique identifier of the target user
        :param until_date: Integer - Date when the user will be unbanned, unix time. If user is banned for
            more than 366 days or less than 30 seconds from the current time they are considered to be banned forever
        NrL  )r:   r   rM  rN  r#   r#   r$   r   A  s   
zKickChatMember.__init__c                 C   s   | j | jt| jdS )NrL  )r   rM  r   rN  rT   r#   r#   r$   r   P  s   zKickChatMember.preparer   )r   r   r   r   r   r   r   KICK_CHAT_MEMBERr   r   r   r   r   datetime	timedeltar   r   r#   r#   r#   r$   rK  8  s    
rK  c                   @   >   e Zd ZdZdZejjZde	e
ef de
fddZdd Zd	S )
UnbanChatMemberzE
    Use that response type for unban chat member on to webhook.
    r   rM  r   rM  c                 C   rG  )z
        :param chat_id: Union[Integer, String] - Unique identifier for the target group or
            username of the target supergroup or channel (in the format @username)
        :param user_id: Integer - Unique identifier of the target user
        NrU  )r:   r   rM  r#   r#   r$   r   a     
zUnbanChatMember.__init__c                 C   rH  )NrU  rU  rT   r#   r#   r$   r   j  rI  zUnbanChatMember.prepareN)r   r   r   r   r   r   r   UNBAN_CHAT_MEMBERr   r   r   r   r   r   r#   r#   r#   r$   rT  X      	rT  c                   @   s   e Zd ZdZdZejjZ					dde	e
ef de
dee	e
ejejf  dee dee d	ee d
ee fddZdd ZdS )RestrictChatMemberzH
    Use that response type for restrict chat member on to webhook.
    r   rM  rN  can_send_messagescan_send_media_messagescan_send_other_messagescan_add_web_page_previewsNr   rM  rN  r[  r\  r]  r^  c                 C   .   || _ || _|| _|| _|| _|| _|| _dS )a  
        :param chat_id: Union[Integer, String] - Unique identifier for the target chat
            or username of the target supergroup (in the format @supergroupusername)
        :param user_id: Integer - Unique identifier of the target user
        :param until_date: Integer - Date when restrictions will be lifted for the user, unix time.
            If user is restricted for more than 366 days or less than 30 seconds from the current time,
            they are considered to be restricted forever
        :param can_send_messages: Boolean - Pass True, if the user can send text messages, contacts,
            locations and venues
        :param can_send_media_messages: Boolean - Pass True, if the user can send audios, documents,
            photos, videos, video notes and voice notes, implies can_send_messages
        :param can_send_other_messages: Boolean - Pass True, if the user can send animations, games,
            stickers and use inline bots, implies can_send_media_messages
        :param can_add_web_page_previews: Boolean - Pass True, if the user may add web page previews
            to their messages, implies can_send_media_messages
        NrZ  )r:   r   rM  rN  r[  r\  r]  r^  r#   r#   r$   r   {  s   
zRestrictChatMember.__init__c                 C   s&   | j | jt| j| j| j| j| jdS )NrZ  )r   rM  r   rN  r[  r\  r]  r^  rT   r#   r#   r$   r     s   zRestrictChatMember.preparer   )r   r   r   r   r   r   r   RESTRICT_CHAT_MEMBERr   r   r   r   r   rQ  rR  r   r   r   r#   r#   r#   r$   rY  q  s.    
rY  c                   @   s   e Zd ZdZdZejjZ									dde	e
ef de
dee dee dee d	ee d
ee dee dee dee dee fddZdd ZdS )PromoteChatMemberzG
    Use that response type for promote chat member on to webhook.
    r   rM  can_change_infocan_post_messagescan_edit_messagescan_delete_messagescan_invite_userscan_restrict_memberscan_pin_messagescan_manage_topicscan_promote_membersNr   rM  rc  rd  re  rf  rg  rh  ri  rj  rk  c                 C   sF   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	|| _
dS )a  
        :param chat_id: Union[Integer, String] - Unique identifier for the target chat
            or username of the target channel (in the format @channelusername)
        :param user_id: Integer - Unique identifier of the target user
        :param can_change_info: Boolean - Pass True, if the administrator can change chat title,
            photo and other settings
        :param can_post_messages: Boolean - Pass True, if the administrator can create channel posts, channels only
        :param can_edit_messages: Boolean - Pass True, if the administrator can edit messages of other users,
            channels only
        :param can_delete_messages: Boolean - Pass True, if the administrator can delete messages of other users
        :param can_invite_users: Boolean - Pass True, if the administrator can invite new users to the chat
        :param can_restrict_members: Boolean - Pass True, if the administrator can restrict, ban or unban chat members
        :param can_pin_messages: Boolean - Pass True, if the administrator can pin messages, supergroups only
        :param can_manage_topics: Boolean - Pass True if the user is allowed to create, rename, close, and reopen forum
            topics, supergroups only
        :param can_promote_members: Boolean - Pass True, if the administrator can add new administrators
            with a subset of his own privileges or demote administrators that he has promoted,
            directly or indirectly (promoted by administrators that were appointed by him)
        Nrb  )r:   r   rM  rc  rd  re  rf  rg  rh  ri  rj  rk  r#   r#   r$   r     s   
zPromoteChatMember.__init__c                 C   s2   | j | j| j| j| j| j| j| j| j| j	| j
dS )Nrb  rb  rT   r#   r#   r$   r     s   zPromoteChatMember.prepare)	NNNNNNNNN)r   r   r   r   r   r   r   PROMOTE_CHAT_MEMBERr   r   r   r   r   r   r   r   r#   r#   r#   r$   ra    sF    	

*ra  c                   @   :   e Zd ZdZdZejjZde	e
ef fddZdd ZdS )	DeleteChatPhotozE
    Use that response type for delete chat photo on to webhook.
    r   r   c                 C   
   || _ dS )z
        :param chat_id: Union[Integer, String] - Unique identifier for the target chat
            or username of the target channel (in the format @channelusername)
        Nro  r:   r   r#   r#   r$   r        
zDeleteChatPhoto.__init__c                 C   
   d| j iS Nr   ro  rT   r#   r#   r$   r        zDeleteChatPhoto.prepareN)r   r   r   r   r   r   r   DELETE_CHAT_PHOTOr   r   r   r   r   r   r#   r#   r#   r$   rn        rn  c                   @   rC  )
SetChatTitlezB
    Use that response type for set chat title on to webhook.
    r   r  r   r  c                 C   rG  )z
        :param chat_id: Union[Integer, String] - Unique identifier for the target chat or username
            of the target channel (in the format @channelusername)
        :param title: String - New chat title, 1-255 characters
        Nry  )r:   r   r  r#   r#   r$   r   
  rV  zSetChatTitle.__init__c                 C   rH  )Nry  ry  rT   r#   r#   r$   r     rI  zSetChatTitle.prepareN)r   r   r   r   r   r   r   SET_CHAT_TITLEr   r   r   r   r   r   r#   r#   r#   r$   rx    rX  rx  c                   @   rC  )
SetChatDescriptionzH
    Use that response type for set chat description on to webhook.
    r   descriptionr   r}  c                 C   rG  )z
        :param chat_id: Union[Integer, String] - Unique identifier for the target chat
            or username of the target channel (in the format @channelusername)
        :param description: String - New chat description, 0-255 characters
        Nr|  )r:   r   r}  r#   r#   r$   r   #  rV  zSetChatDescription.__init__c                 C   rH  )Nr|  r|  rT   r#   r#   r$   r   ,  rI  zSetChatDescription.prepareN)r   r   r   r   r   r   r   SET_CHAT_DESCRIPTIONr   r   r   r   r   r   r#   r#   r#   r$   r{    rX  r{  c                   @   sJ   e Zd ZdZdZejjZ	dde	e
ef de
dee fddZd	d
 ZdS )PinChatMessagezD
    Use that response type for pin chat message on to webhook.
    r   r   r   Nr   r   r   c                 C   rO  )a  
        :param chat_id: Union[Integer, String] - Unique identifier for the target chat
            or username of the target supergroup (in the format @supergroupusername)
        :param message_id: Integer - Identifier of a message to pin
        :param disable_notification: Boolean - Pass True, if it is not necessary to send a notification
            to all group members about the new pinned message
        Nr  )r:   r   r   r   r#   r#   r$   r   <  s   	
zPinChatMessage.__init__c                 C      | j | j| jdS )Nr  r  rT   r#   r#   r$   r   I     zPinChatMessage.preparer   )r   r   r   r   r   r   r   PIN_CHAT_MESSAGEr   r   r   r   r   r   r   r   r#   r#   r#   r$   r  3  s    
r  c                   @   rm  )	UnpinChatMessagezF
    Use that response type for unpin chat message on to webhook.
    ro  r   c                 C   rp  )z
        :param chat_id: Union[Integer, String] - Unique identifier for the target chat or
            username of the target supergroup (in the format @supergroupusername)
        Nro  rq  r#   r#   r$   r   Z  rr  zUnpinChatMessage.__init__c                 C   rs  rt  ro  rT   r#   r#   r$   r   a  ru  zUnpinChatMessage.prepareN)r   r   r   r   r   r   r   UNPIN_CHAT_MESSAGEr   r   r   r   r   r   r#   r#   r#   r$   r  Q  rw  r  c                   @   rm  )		LeaveChatz>
    Use that response type for leave chat on to webhook.
    ro  r   c                 C   rp  )z
        :param chat_id: Union[Integer, String] - Unique identifier for the target chat
            or username of the target supergroup or channel (in the format @channelusername)
        Nro  rq  r#   r#   r$   r   p  rr  zLeaveChat.__init__c                 C   rs  rt  ro  rT   r#   r#   r$   r   w  ru  zLeaveChat.prepareN)r   r   r   r   r   r   r   
LEAVE_CHATr   r   r   r   r   r   r#   r#   r#   r$   r  g  rw  r  c                   @   s\   e Zd ZdZdZejjZ				dde	de
e	 de
e de
e	 de
e f
d	d
Zdd ZdS )AnswerCallbackQueryzI
    Use that response type for answer callback query on to webhook.
    callback_query_idrB   
show_alerturl
cache_timeNr  rB   r  r  r  c                 C   "   || _ || _|| _|| _|| _dS )uM  
        :param callback_query_id: String - Unique identifier for the query to be answered
        :param text: String (Optional) - Text of the notification. If not specified, nothing will be shown to the user,
            0-200 characters
        :param show_alert: Boolean (Optional) - If true, an alert will be shown by the client instead
            of a notification at the top of the chat screen. Defaults to false.
        :param url: String (Optional) - URL that will be opened by the user's client.
            If you have created a Game and accepted the conditions via @Botfather,
            specify the URL that opens your game – note that this will only work
            if the query comes from a callback_game button.
            Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.
        :param cache_time: Integer (Optional) - The maximum amount of time in seconds that the result
            of the callback query may be cached client-side. Telegram apps will support
            caching starting in version 3.14. Defaults to 0.
        Nr  )r:   r  rB   r  r  r  r#   r#   r$   r     s
   
zAnswerCallbackQuery.__init__c                 C   r   )Nr  r  rT   r#   r#   r$   r     r   zAnswerCallbackQuery.preparer2  )r   r   r   r   r   r   r   ANSWER_CALLBACK_QUERYr   r   r   r   r   r   r   r#   r#   r#   r$   r  }  s$    
r  c                   @   sz   e Zd ZdZdZejjZ						dde	de
eee	f  de
e de
e	 de
e	 d	e
e d
e
ej fddZdd ZdS )EditMessageTextzE
    Use that response type for edit message text on to webhook.
    r   r   inline_message_idrB   r   r   r   NrB   r   r   r  r   r   r   c                 C   sN   |du r|   }|du r|  }|| _|| _|| _|| _|| _|| _|| _dS )a  
        :param chat_id: Union[Integer, String] (Optional) - Required if inline_message_id
            is not specified. Unique identifier for the target chat or username of the target channel
            (in the format @channelusername)
        :param message_id: Integer (Optional) - Required if inline_message_id is not specified.
            Identifier of the sent message
        :param inline_message_id: String (Optional) - Required if chat_id and message_id are not specified.
            Identifier of the inline message
        :param text: String - New text of the message
        :param parse_mode: String (Optional) - Send Markdown or HTML, if you want Telegram apps to show bold,
            italic, fixed-width text or inline URLs in your bot's message.
        :param disable_web_page_preview: Boolean (Optional) - Disables link previews for links in this message
        :param reply_markup: types.InlineKeyboardMarkup (Optional) - A JSON-serialized object for
            an inline keyboard.
        N)	r   r   r   r   r  rB   r   r   r   )r:   rB   r   r   r  r   r   r   r#   r#   r$   r     s   
zEditMessageText.__init__c                 C   r  )Nr  )r   r   r  rB   r   r   r   r   rT   r#   r#   r$   r     r  zEditMessageText.preparer"  )r   r   r   r   r   r   r   EDIT_MESSAGE_TEXTr   r   r   r   r   r   r
   r   r   r   r#   r#   r#   r$   r    s0    
#r  c                   @   sl   e Zd ZdZdZejjZ					dde	e
eef  de	e de	e de	e de	ej f
d	d
Zdd ZdS )EditMessageCaptionzH
    Use that response type for edit message caption on to webhook.
    r   r   r  r  r   Nr   r   r  r  r   c                 C   r  )a  
        :param chat_id: Union[Integer, String] (Optional) - Required if inline_message_id
            is not specified. Unique identifier for the target chat or username of the target channel
            (in the format @channelusername)
        :param message_id: Integer (Optional) - Required if inline_message_id is not specified.
            Identifier of the sent message
        :param inline_message_id: String (Optional) - Required if chat_id and message_id are not specified.
            Identifier of the inline message
        :param caption: String (Optional) - New caption of the message
        :param reply_markup: types.InlineKeyboardMarkup (Optional) - A JSON-serialized object for an inline keyboard.
        Nr  )r:   r   r   r  r  r   r#   r#   r$   r     
   
zEditMessageCaption.__init__c                 C      | j | j| j| jt| jdS )Nr  )r   r   r  r  r   r   rT   r#   r#   r$   r        zEditMessageCaption.preparer   )r   r   r   r   r   r   r   EDIT_MESSAGE_CAPTIONr   r   r   r   r   r
   r   r   r   r#   r#   r#   r$   r    s&    
r  c                
   @   sb   e Zd ZdZdZejjZ				dde	e
eef  de	e de	e de	ej fdd	Zd
d ZdS )EditMessageReplyMarkupzM
    Use that response type for edit message reply markup on to webhook.
    r   r   r  r   Nr   r   r  r   c                 C      || _ || _|| _|| _dS )a  
        :param chat_id: Union[Integer, String] (Optional) - Required if inline_message_id is not specified.
            Unique identifier for the target chat or username of the target channel (in the format @channelusername)
        :param message_id: Integer (Optional) - Required if inline_message_id is not specified.
            Identifier of the sent message
        :param inline_message_id: String (Optional) - Required if chat_id and message_id are not specified.
            Identifier of the inline message
        :param reply_markup: types.InlineKeyboardMarkup (Optional) - A JSON-serialized object for an inline keyboard.
        Nr  )r:   r   r   r  r   r#   r#   r$   r     s   
zEditMessageReplyMarkup.__init__c                 C   s   | j | j| jt| jdS )Nr  )r   r   r  r   r   rT   r#   r#   r$   r   '  s
   zEditMessageReplyMarkup.preparer2  )r   r   r   r   r   r   r   EDIT_MESSAGE_REPLY_MARKUPr   r   r   r   r   r
   r   r   r   r#   r#   r#   r$   r    s     
r  c                   @   rS  )
DeleteMessagezB
    Use that response type for delete message on to webhook.
    r   r   r   r   c                 C   rG  )z
        :param chat_id: Union[Integer, String] - Unique identifier for the target chat or username
            of the target channel (in the format @channelusername)
        :param message_id: Integer - Identifier of the message to delete
        Nr  )r:   r   r   r#   r#   r$   r   9  rV  zDeleteMessage.__init__c                 C   rH  )Nr  r  rT   r#   r#   r$   r   B  rI  zDeleteMessage.prepareN)r   r   r   r   r   r   r   DELETE_MESSAGEr   r   r   r   r   r   r#   r#   r#   r$   r  0  rX  r  c                   @   sx   e Zd ZdZdZejjZ				dde	e
ef dedee dee dee
 d	ee	ejejeef  fd
dZdd ZdS )SendStickerz@
    Use that response type for send sticker on to webhook.
    r   stickerr   r   r   r   Nr   r  r   r   r   r   c                 C   8   |du r|   }|| _|| _|| _|| _|| _|| _dS )u  
        :param chat_id: Union[Integer, String] - Unique identifier for the target chat or username
            of the target channel (in the format @channelusername)
        :param sticker: String - Sticker to send. Pass a file_id
            as String to send a file that exists on the Telegram servers (recommended),
            pass an HTTP URL as a String for Telegram to get a .webp file from the Internet,
            or upload a new one using multipart/form-data. More info on Sending Files »
        :param disable_notification: Boolean (Optional) - Sends the message silently.
            Users will receive a notification with no sound.
        :param protect_content: Boolean (Optional) - Protects the contents of sent messages
            from forwarding and saving
        :param reply_to_message_id: Integer (Optional) - If the message is a reply, ID of the original message
        :param reply_markup: Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, Dict, String] (Optional) -
            Additional interface options. A JSON-serialized object for an inline keyboard,
            custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
        N)r   r   r  r   r   r   r   )r:   r   r  r   r   r   r   r#   r#   r$   r   S  s   
zSendSticker.__init__c                 C   "   | j | j| j| j| jt| jdS )Nr  )r   r  r   r   r   r   r   rT   r#   r#   r$   r   u     zSendSticker.preparer2  )r   r   r   r   r   r   r   SEND_STICKERr   r   r   r   r   r   r
   r   r   r   r   r   r#   r#   r#   r$   r  I  s0    
"r  c                   @   sZ   e Zd ZdZdZejjZ		dde	de
de
de
de
d	ee d
eej fddZdd ZdS )CreateNewStickerSetzJ
    Use that response type for create new sticker set on to webhook.
    rM  r   r  png_stickeremojiscontains_masksmask_positionNrM  r   r  r  r  r  r  c                 C   r_  )u  
        :param user_id: Integer - User identifier of created sticker set owner
        :param name: String - Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g., animals).
            Can contain only english letters, digits and underscores. Must begin with a letter,
            can't contain consecutive underscores and must end in “_by_<bot username>”. <bot_username>
            is case insensitive. 1-64 characters.
        :param title: String - Sticker set title, 1-64 characters
        :param png_sticker: String - Png image with the sticker,
            must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width
            or height must be exactly 512px. Pass a file_id as a String to send a file that
            already exists on the Telegram servers, pass an HTTP URL
            as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data.
        :param emojis: String - One or more emoji corresponding to the sticker
        :param contains_masks: Boolean (Optional) - Pass True, if a set of mask stickers should be created
        :param mask_position: types.MaskPosition (Optional) - Position where the mask should be placed on faces
        Nr  )r:   rM  r   r  r  r  r  r  r#   r#   r$   r     s   
zCreateNewStickerSet.__init__c                 C   s"   | j | j| j| j| j| j| jdS )Nr  r  rT   r#   r#   r$   r     s   zCreateNewStickerSet.prepareNN)r   r   r   r   r   r   r   CREATE_NEW_STICKER_SETr   r   r   r   r   r
   MaskPositionr   r   r#   r#   r#   r$   r    s(    
r  c                   @   sL   e Zd ZdZdZejjZ	dde	de
de
de
deej f
d	d
Zdd ZdS )AddStickerToSetzF
    Use that response type for add sticker to set on to webhook.
    rM  r   r  r  r  NrM  r   r  r  r  c                 C   r  )a  
        :param user_id: Integer - User identifier of sticker set owner
        :param name: String - Sticker set name
        :param png_sticker: String - Png image with the sticker,
            must be up to 512 kilobytes in size, dimensions must not exceed 512px,
            and either width or height must be exactly 512px. Pass a file_id as a String
            to send a file that already exists on the Telegram servers, pass an HTTP URL
            as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data.
        :param emojis: String - One or more emoji corresponding to the sticker
        :param mask_position: types.MaskPosition (Optional) - Position where the mask should be placed on faces
        Nr  )r:   rM  r   r  r  r  r#   r#   r$   r     r  zAddStickerToSet.__init__c                 C   r  )Nr  )rM  r   r  r  r   r  rT   r#   r#   r$   r     r  zAddStickerToSet.preparer   )r   r   r   r   r   r   r   ADD_STICKER_TO_SETr   r   r   r   r
   r  r   r   r#   r#   r#   r$   r    s    
r  c                   @   s6   e Zd ZdZdZejjZde	de
fddZdd Zd	S )
SetStickerPositionInSetzO
    Use that response type for set sticker position in set on to webhook.
    r  positionr  r  c                 C   rG  )z
        :param sticker: String - File identifier of the sticker
        :param position: Integer - New sticker position in the set, zero-based
        Nr  )r:   r  r  r#   r#   r$   r     s   
z SetStickerPositionInSet.__init__c                 C   rH  )Nr  r  rT   r#   r#   r$   r     rI  zSetStickerPositionInSet.prepareN)r   r   r   r   r   r   r   SET_STICKER_POSITION_IN_SETr   r   r   r   r   r#   r#   r#   r$   r    s    r  c                   @   s2   e Zd ZdZdZejjZde	fddZ
dd ZdS )	DeleteStickerFromSetzK
    Use that response type for delete sticker from set on to webhook.
    r  r  c                 C   rp  )zI
        :param sticker: String - File identifier of the sticker
        Nr  )r:   r  r#   r#   r$   r     s   
zDeleteStickerFromSet.__init__c                 C   rs  )Nr  r  rT   r#   r#   r$   r     ru  zDeleteStickerFromSet.prepareN)r   r   r   r   r   r   r   DELETE_STICKER_FROM_SETr   r   r   r   r#   r#   r#   r$   r    s    r  c                   @   sn   e Zd ZdZdZejjZ					dde	de
jgdee dee dee	 d	ee	 d
ee	 fddZdd ZdS )AnswerInlineQueryzG
    Use that response type for answer inline query on to webhook.
    inline_query_idrL   r  is_personalnext_offsetswitch_pm_textswitch_pm_parameterNr  rL   r  r  r  r  r  c                 C   r_  )u/  
        :param inline_query_id: String - Unique identifier for the answered query
        :param results: [types.InlineQueryResult] - A JSON-serialized array of results for the inline query
        :param cache_time: Integer (Optional) - The maximum amount of time in seconds that the result
            of the inline query may be cached on the server. Defaults to 300.
        :param is_personal: Boolean (Optional) - Pass True, if results may be cached on the server side
            only for the user that sent the query. By default, results may be returned
            to any user who sends the same query
        :param next_offset: String (Optional) - Pass the offset that a client should send in the
            next query with the same text to receive more results.
            Pass an empty string if there are no more results or if you don‘t support pagination.
            Offset length can’t exceed 64 bytes.
        :param switch_pm_text: String (Optional) - If passed, clients will display a button with specified text
            that switches the user to a private chat with the bot and sends the bot a start
            message with the parameter switch_pm_parameter
        :param switch_pm_parameter: String (Optional) - Deep-linking parameter for the /start message
            sent to the bot when user presses the switch button. 1-64 characters,
            only A-Z, a-z, 0-9, _ and - are allowed.
            Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their
            YouTube account to adapt search results accordingly. To do this,
            it displays a ‘Connect your YouTube account’ button above the results, or even before showing any.
            The user presses the button, switches to a private chat with the bot and,
            in doing so, passes a start parameter that instructs the bot to return an oauth link.
            Once done, the bot can offer a switch_inline button so that the user can easily return
            to the chat where they wanted to use the bot's inline capabilities.
        Nr  )r:   r  rL   r  r  r  r  r  r#   r#   r$   r     s   !
zAnswerInlineQuery.__init__c                 C   s&   | j t| j| j| j| j| j| jdS )Nr  )r  r   rL   r  r  r  r  r  rT   r#   r#   r$   r   <  s   zAnswerInlineQuery.preparer   )r   r   r   r   r   r   r   ANSWER_INLINE_QUERYr   r   r
   InlineQueryResultr   r   r   r   r   r#   r#   r#   r$   r  	  s.    
)r  c                0   @   s   e Zd ZdZdZejjZ															dde	de
de
de
de
d	e
d
e
dejgdee
 dee	 dee	 dee	 dee dee dee dee dee dee dee dee dee dee	 deej f.ddZdd ZdS ) SendInvoicez@
    Use that response type for send invoice on to webhook.
    r   r  r}  payloadprovider_tokenstart_parametercurrencyprices	photo_url
photo_sizephoto_widthphoto_height	need_nameneed_phone_number
need_emailneed_shipping_addresssend_phone_number_to_providersend_email_to_provideris_flexibler   r   r   r   Nr   r  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   c                 C   s   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	|| _
|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _dS )a  
        :param chat_id: Integer - Unique identifier for the target private chat
        :param title: String - Product name, 1-32 characters
        :param description: String - Product description, 1-255 characters
        :param payload: String - Bot-defined invoice payload, 1-128 bytes.
            This will not be displayed to the user, use for your internal processes.
        :param provider_token: String - Payments provider token, obtained via Botfather
        :param start_parameter: String - Unique deep-linking parameter that can be used to
            generate this invoice when used as a start parameter
        :param currency: String - Three-letter ISO 4217 currency code, see more on currencies
        :param prices: [types.LabeledPrice] - Price breakdown, a list of components
            (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
        :param photo_url: String (Optional) - URL of the product photo for the invoice.
            Can be a photo of the goods or a marketing image for a service.
            People like it better when they see what they are paying for.
        :param photo_size: Integer (Optional) - Photo size
        :param photo_width: Integer (Optional) - Photo width
        :param photo_height: Integer (Optional) - Photo height
        :param need_name: Boolean (Optional) - Pass True, if you require the user's full name to complete the order
        :param need_phone_number: Boolean (Optional) - Pass True, if you require
            the user's phone number to complete the order
        :param need_email: Boolean (Optional) - Pass True, if you require the user's email to complete the order
        :param need_shipping_address: Boolean (Optional) - Pass True, if you require the user's
            shipping address to complete the order
        :param send_phone_number_to_provider: Boolean (Optional) - Pass True, if user's phone number should be sent
            to provider
        :param send_email_to_provider: Boolean (Optional) - Pass True, if user's email address should be sent 
            to provider
        :param is_flexible: Boolean (Optional) - Pass True, if the final price depends on the shipping method
        :param disable_notification: Boolean (Optional) - Sends the message silently.
            Users will receive a notification with no sound.
        :param protect_content: Boolean (Optional) - Protects the contents of sent messages
            from forwarding and saving
        :param reply_to_message_id: Integer (Optional) - If the message is a reply, ID of the original message
        :param reply_markup: types.InlineKeyboardMarkup (Optional) - A JSON-serialized object for an inline keyboard.
            If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button.
        Nr  )r:   r   r  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r#   r#   r$   r   U  s.   <
zSendInvoice.__init__c                 C   s   i d| j d| jd| jd| jd| jd| jd| jdt| jd	| j	d
| j
d| jd| jd| jd| jd| jd| jd| j| j| j| j| j| jt| jdS )Nr   r  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  )r  r  r   r   r   r   )r   r  r}  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   rT   r#   r#   r$   r     sT   
	
zSendInvoice.prepare)NNNNNNNNNNNNNNN)r   r   r   r   r   r   r   SEND_INVOICEr   r   r   r
   LabeledPricer   r   r   r   r   r#   r#   r#   r$   r  H  s    
	

Tr  c                
   @   sT   e Zd ZdZdZejjZ		dde	de
deejej  dee	 fdd	Zd
d ZdS )AnswerShippingQueryzI
    Use that response type for answer shipping query on to webhook.
    shipping_query_idr@   shipping_optionserror_messageNr  r@   r  r  c                 C   r  )a  
        :param shipping_query_id: String - Unique identifier for the query to be answered
        :param ok: Boolean - Specify True if delivery to the specified address is possible and
            False if there are any problems (for example, if delivery to the specified address is not possible)
        :param shipping_options: [types.ShippingOption] (Optional) - Required if ok is True.
            A JSON-serialized array of available shipping options.
        :param error_message: String (Optional) - Required if ok is False.
            Error message in human readable form that explains why it is impossible to complete the order
            (e.g. "Sorry, delivery to your desired address is unavailable').
            Telegram will display this message to the user.
        Nr  )r:   r  r@   r  r  r#   r#   r$   r     s   
zAnswerShippingQuery.__init__c                 C   s   | j | jt| j| jdS )Nr  )r  r@   r   r  r  rT   r#   r#   r$   r     s
   zAnswerShippingQuery.preparer  )r   r   r   r   r   r   r   ANSWER_SHIPPING_QUERYr   r   r   r   r   r   r
   ShippingOptionr   r   r#   r#   r#   r$   r    s    
r  c                   @   sB   e Zd ZdZdZejjZ	dde	de
dee	 fddZd	d
 ZdS )AnswerPreCheckoutQueryzM
    Use that response type for answer pre checkout query on to webhook.
    pre_checkout_query_idr@   r  Nr  r@   r  c                 C   rO  )a  
        :param pre_checkout_query_id: String - Unique identifier for the query to be answered
        :param ok: Boolean - Specify True if everything is alright (goods are available, etc.)
            and the bot is ready to proceed with the order. Use False if there are any problems.
        :param error_message: String (Optional) - Required if ok is False.
            Error message in human readable form that explains the reason for failure to proceed with the checkout
            (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy
            filling out your payment details. Please choose a different color or garment!").
            Telegram will display this message to the user.
        Nr  )r:   r  r@   r  r#   r#   r$   r     s   
zAnswerPreCheckoutQuery.__init__c                 C   r  )Nr  r  rT   r#   r#   r$   r   	  r  zAnswerPreCheckoutQuery.preparer   )r   r   r   r   r   r   r   ANSWER_PRE_CHECKOUT_QUERYr   r   r   r   r   r   r#   r#   r#   r$   r    s    
r  c                   @   sb   e Zd ZdZdZejjZ				dde	de
dee dee dee	 d	eej fd
dZdd ZdS )SendGamez=
    Use that response type for send game on to webhook.
    r   game_short_namer   r   r   r   Nr   r  r   r   r   r   c                 C   r  )uc  
        :param chat_id: Integer - Unique identifier for the target chat
        :param game_short_name: String - Short name of the game, serves as the unique identifier for the game.
            Set up your games via Botfather.
        :param disable_notification: Boolean (Optional) - Sends the message silently.
            Users will receive a notification with no sound.
        :param protect_content: Boolean (Optional) - Protects the contents of sent messages
            from forwarding and saving
        :param reply_to_message_id: Integer (Optional) - If the message is a reply, ID of the original message
        :param reply_markup: types.InlineKeyboardMarkup (Optional) - A JSON-serialized object for an inline keyboard.
            If empty, one ‘Play game_title’ button will be shown. If not empty, the first button must launch the game.
        N)r   r   r  r   r   r   r   )r:   r   r  r   r   r   r   r#   r#   r$   r   	  s   
zSendGame.__init__c                 C   r  )Nr  )r   r  r   r   r   r   r   rT   r#   r#   r$   r   3	  r  zSendGame.preparer2  )r   r   r   r   r   r   r   	SEND_GAMEr   r   r   r   r   r
   r   r   r   r#   r#   r#   r$   r  	  s(    
r  )krW   asyncio.tasksrQ  r^   r   rx   r   loggingr   r   r   r   aiohttpr   aiohttp.web_exceptionsr   rR   r
   r8   r   r   
types.baser   r   r   r   utilsr   r   r   utils.deprecatedr   ro   utils.exceptionsr   utils.payloadr   DEFAULT_WEB_PATHDEFAULT_ROUTE_NAMEr5   r[   WEBHOOKr   r   r*   TELEGRAM_SUBNET_1TELEGRAM_SUBNET_2setr!   	getLoggerr   r   r)   boolr%   r    r/   Viewr0   r   r   r   r   r{   r   r   r   r   r   r   r   r  r
  r  r  r  r$  r)  r4  r9  r=  rD  rK  rT  rY  ra  rn  rx  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r#   r#   r#   r$   <module>   s    



 DH# ^6:G;H>=Y6E; 5E-9)$73)?}&"