o
    lWi                     @   s|   d dl Z d dlZd dlZd dlZd dlmZmZ ddlmZ ddl	m
Z
 ddlmZmZ G dd deZG d	d
 d
eZdS )    N)AnyDict   )BadRequestErrorBody)BadRequestError)WebhooksClientAsyncWebhooksClientc                   @   *   e Zd ZdZdedededefddZdS )	r   z
    A client to handle ElevenLabs webhook-related functionality
    Extends the autogenerated client to include custom webhook methods
    rawBody
sig_headersecretreturnc                 C     |s
t tddd|st tddd|d}d}d}|D ]}|dr-|dd }q|d	r4|}q|r9|sAt td
ddt|d }tt d d }	||	k r]t tddd| d| }
d	t|d|
dt	j
  }||krt tdddt|S a  
        Constructs a webhook event object from a payload and signature.
        Verifies the webhook signature to ensure the event came from ElevenLabs.

        Args:
            rawBody: The webhook request body. Must be the raw body, not a JSON object
            sig_header: The signature header from the request
            secret: Your webhook secret

        Returns:
            The verified webhook event

        Raises:
            BadRequestError: If the signature is invalid or missing
        zMissing signature header)error)bodyzWebhook secret not configured,Nzt=   zv0=z/No signature hash found with expected scheme v0i  i@w z$Timestamp outside the tolerance zone.zutf-8zESignature hash does not match the expected signature hash for payloadr   r   split
startswithinttimehmacnewencodehashlibsha256	hexdigestjsonloadsselfr
   r   r   headers	timestamp	signatureheaderreq_timestamp	tolerancemessagedigest r,   ^/var/www/html/asistente-voz-ia/venv/lib/python3.10/site-packages/elevenlabs/webhooks_custom.pyconstruct_event   @   



zWebhooksClient.construct_eventN__name__
__module____qualname____doc__strr   r.   r,   r,   r,   r-   r      s    r   c                   @   r	   )	r   zU
    Async version of WebhooksClient that extends the autogenerated async client
    r
   r   r   r   c                 C   r   r   r   r"   r,   r,   r-   r.   Q   r/   z#AsyncWebhooksClient.construct_eventNr0   r,   r,   r,   r-   r   L   s    r   )r    r   r   r   typingr   r   types.bad_request_error_bodyr   errorsr   webhooks.clientr   AutogeneratedWebhooksClientr    AutogeneratedAsyncWebhooksClientr,   r,   r,   r-   <module>   s    A