
    x'h                     |    d Z dZ	 ddlZddlmZ ddl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 TeleBot.run_webhooks() function.
Fastapi is required to run this script.
T    N)JSONResponse)RequestF)Update)Optionalc                   z    e Zd Z	 	 	 	 ddedee   dee   dee   dee   ddfdZed	        Z	d
 Z
dedefdZd Zy)SyncWebhookListenerNsecret_tokenhostportssl_contexturl_pathreturnc                     | j                          t        j                         | _        || _        || _        || _        || _        || _        || _	        | j                          y)a
  
        Synchronous implementation of webhook listener
        for synchronous version of telebot.
        Not supposed to be used manually by user.
        Use TeleBot.run_webhooks() instead.

        :param bot: TeleBot instance.
        :type bot: telebot.TeleBot

        :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          Q/var/www/flask-api/venv/lib/python3.12/site-packages/telebot/ext/sync/webhooks.py__init__zSyncWebhookListener.__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#   s    r   r   z'SyncWebhookListener._check_dependenciesG   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*SyncWebhookListener._prepare_endpoint_urlsR   s)    (;(;$..[aZbcr   requestupdatec                 B   |j                   j                  d      | j                  k7  rt        dddi      S |j                   j                  d      dk(  r<| j                  j                  t        j                  |      g       t        dd	
      S t        dddi      S )z<
        Processes updates.

        :meta private:
        zX-Telegram-Bot-Api-Secret-Tokeni  error	Forbidden)status_codecontentzcontent-typezapplication/json    )r2   )headersgetr   r   r   process_new_updatesr   de_json)r   r-   r.   s      r   r+   z"SyncWebhookListener.process_updateV   s     ??@ATEWEWWC';9OPP??~.2DDII))6>>&+A*BC44g{5KLLr   c                     t        j                  | j                  | j                  | j                  | j
                  d   | j
                  d          y)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)uvicornrunr   r   r   r   r,   s    r   run_appzSyncWebhookListener.run_appg   s@     	**1-))!,		
r   )z	127.0.0.1i  NN)__name__
__module____qualname__strr   inttupler   staticmethodr   r   r   dictr+   r@    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   r>   r"   telebot.typesr   typingr   r   rI   r   r   <module>rO      sN     .( ! ^
 ^
  s   1 ;;