
    x'h                         d Z dZ	 ddlZddlmZ ddlmZ ddlmZm	Z	 ddlZddlmZ dd	lmZ  G d
 d      Zy# e
$ r dZY $w xY w)z
This file is used by AsyncTeleBot.run_webhooks() function.

Fastapi and starlette(0.20.2+) libraries are required to run this script.
T    N)JSONResponse)Request)ServerConfigF)Update)Optionalc                   p    e Zd Z	 	 	 	 ddedee   dee   dee   dee   ddfdZd	 Zd
 Z	de
defdZd Zy)AsyncWebhookListenerNsecret_tokenhostportssl_contexturl_pathreturnc                     | j                          t        j                         | _        || _        || _        || _        || _        || _        || _	        | j                          y)a(  
        Aynchronous implementation of webhook listener
        for asynchronous version of telebot.
        Not supposed to be used manually by user.
        Use AsyncTeleBot.run_webhooks() instead.

        :param bot: AsyncTeleBot instance.
        :type bot: telebot.async_telebot.AsyncTeleBot

        :param secret_token: Telegram secret token
        :type secret_token: str

        :param host: Webhook host
        :type host: str

        :param port: Webhook port
        :type port: int

        :param ssl_context: SSL context
        :type ssl_context: tuple

        :param url_path: Webhook url path
        :type url_path: str

        :raises ImportError: If FastAPI or uvicorn is not installed.
        :raises ImportError: If Starlette version is too old.

        :return: None
        N)_check_dependenciesfastapiFastAPIapp_secret_token_bot_port_host_ssl_context	_url_path_prepare_endpoint_urls)selfbotr   r   r   r   r   s          P/var/www/flask-api/venv/lib/python3.12/site-packages/telebot/ext/aio/webhooks.py__init__zAsyncWebhookListener.__init__   sW    H 	  "??$)	

'!##%    c                 b    t         st        d      dd l}|j                  dk  rt        d      y )Nz?Fastapi or uvicorn is not installed. Please install it via pip.r   z0.20.2zLStarlette version is too old. Please upgrade it: `pip3 install starlette -U`)fastapi_installedImportError	starlette__version__)r   r%   s     r   r   z(AsyncWebhookListener._check_dependenciesK   s1     _``  8+lmmr!   c                 j    | j                   j                  | j                  | j                  dg       y )NPOST)endpointpathmethods)r   add_api_routeprocess_updater   )r   s    r   r   z+AsyncWebhookListener._prepare_endpoint_urlsU   s)    (;(;$..[aZbcr!   requestupdatec                 t  K   |j                   j                  d      | j                  k7  rt        dddi      S |j                   j                  d      dk(  rQ|}t	        j
                  | j                  j                  t        j                  |      g             t        dd	
      S t        dddi      S w)z<
        Processes updates.

        :meta private:
        zX-Telegram-Bot-Api-Secret-Tokeni  error	Forbidden)status_codecontentzcontent-typezapplication/json    )r3   )
headersgetr   r   asynciocreate_taskr   process_new_updatesr   de_json)r   r.   r/   json_strings       r   r-   z#AsyncWebhookListener.process_updateY   s      ??@ATEWEWWC';9OPP??~.2DD K		 = =v~~k?Z>[ \]44g{5KLLs   B6B8c                 .  K   t        | j                  | j                  | j                  | j                  d   | j                  d         }t        |      }|j                          d{    | j                  j                          d{    y7 '7 w)z
        Run app with the given parameters to init.
        Not supposed to be used manually by user.

        :return: None
        r      )r   r   r   ssl_certfilessl_keyfileN)	r   r   r   r   r   r   server   close_session)r   configservers      r   run_appzAsyncWebhookListener.run_appk   s{      DHH**1-))!,	
 llnii%%''' 	's$   A'B)B*!BBBB)z	127.0.0.1i  NN)__name__
__module____qualname__strr   inttupler    r   r   r   dictr-   rF    r!   r   r
   r
      s     %0$'-1(,-&!-&sm-& sm-& &e_	-&
 #3--& -&`dMG MT M$(r!   r
   )__doc__r#   r   fastapi.responsesr   fastapi.requestsr   uvicornr   r   r$   r9   telebot.typesr   typingr   r
   rN   r!   r   <module>rU      sU     .(&  ! a( a(  s   9 AA