o
    lWi6z                     @   s   d dl Z d dlmZ ddlmZ ddl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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 ddlm Z  G dd dZ!G dd dZ"dS )    N)JSONDecodeError   )ApiError)AsyncClientWrapperSyncClientWrapper)AsyncHttpResponseHttpResponse)jsonable_encoder)RequestOptions)construct_type)UnprocessableEntityError)"ConversationSignedUrlResponseModel)EvaluationSuccessResult)GetConversationResponseModel)!GetConversationsPageResponseModel)HttpValidationError)TokenResponseModel   )#ConversationsListRequestSummaryModec                (   @     e Zd ZdefddZddddedeje deje	 d	e
e fd
dZddddedeje deje	 d	e
e fddZddddddddddddddddddddeje deje deje deje deje deje deje deje deje deje deje dejejeeje f  dejejeeje f  dejejeeje f  deje deje d eje deje	 d	e
e f&d!d"Zdd#d$edeje	 d	e
e fd%d&Zdd#d$edeje	 d	e
ej fd'd(ZdS ))RawConversationsClientclient_wrapperc                C   
   || _ d S N_client_wrapperselfr    r   y/var/www/html/asistente-voz-ia/venv/lib/python3.10/site-packages/elevenlabs/conversational_ai/conversations/raw_client.py__init__      
zRawConversationsClient.__init__Ninclude_conversation_idrequest_optionsagent_idr#   r$   returnc             	   C      | j jjdd||d|d}z>d|j  krdk r/n ntttt| d}t	||dW S |jd	krGt
t|jtttt| dd
| }W n ty_   t|jt|j|jdw t|jt|j|d)a  
        Get a signed url to start a conversation with an agent with an agent that requires authorization

        Parameters
        ----------
        agent_id : str
            The id of the agent you're taking the action on.

        include_conversation_id : typing.Optional[bool]
            Whether to include a conversation_id with the response. If included, the conversation_signature cannot be used again.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[ConversationSignedUrlResponseModel]
            Successful Response
        %v1/convai/conversation/get-signed-urlGETr%   r#   methodparamsr$      ,  type_object_responsedata  headersbodystatus_coder8   r9   )r   httpx_clientrequestr;   typingcastr   r   jsonr   r   dictr8   r   r   r   textr   r%   r#   r$   	_response_data_response_jsonr   r   r   get_signed_url   D   	

z%RawConversationsClient.get_signed_urlparticipant_namer$   rJ   c             	   C   r'   )a  
        Get a WebRTC session token for real-time communication.

        Parameters
        ----------
        agent_id : str
            The id of the agent you're taking the action on.

        participant_name : typing.Optional[str]
            Optional custom participant name. If not provided, user ID will be used

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[TokenResponseModel]
            Successful Response
        v1/convai/conversation/tokenr)   r%   rJ   r+   r.   r/   r0   r3   r6   r7   r:   )r   r<   r=   r;   r>   r?   r   r   r@   r   r   rA   r8   r   r   r   rB   r   r%   rJ   r$   rD   rE   rF   r   r   r   get_webrtc_tokenW   rH   z'RawConversationsClient.get_webrtc_tokencursorr%   call_successfulcall_start_before_unixcall_start_after_unixcall_duration_min_secscall_duration_max_secs
rating_max
rating_minhas_feedback_commentuser_idevaluation_paramsdata_collection_params
tool_names	page_sizesummary_modesearchr$   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   c             	   C   s6  | j jjddi d|d|d|d|d|d|d	|d
|d|	d|
d|d|d|d|d|d|d||d}z>d|j  krJdk r_n ntttt| d}t	||dW S |jdkrwt
t|jtttt| dd| }W n ty   t|jt|j|jdw t|jt|j|d)a
  
        Get all conversations of agents that user owns. With option to restrict to a specific agent.

        Parameters
        ----------
        cursor : typing.Optional[str]
            Used for fetching next page. Cursor is returned in the response.

        agent_id : typing.Optional[str]
            The id of the agent you're taking the action on.

        call_successful : typing.Optional[EvaluationSuccessResult]
            The result of the success evaluation

        call_start_before_unix : typing.Optional[int]
            Unix timestamp (in seconds) to filter conversations up to this start date.

        call_start_after_unix : typing.Optional[int]
            Unix timestamp (in seconds) to filter conversations after to this start date.

        call_duration_min_secs : typing.Optional[int]
            Minimum call duration in seconds.

        call_duration_max_secs : typing.Optional[int]
            Maximum call duration in seconds.

        rating_max : typing.Optional[int]
            Maximum overall rating (1-5).

        rating_min : typing.Optional[int]
            Minimum overall rating (1-5).

        has_feedback_comment : typing.Optional[bool]
            Filter conversations with user feedback comments.

        user_id : typing.Optional[str]
            Filter conversations by the user ID who initiated them.

        evaluation_params : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Evaluation filters. Repeat param. Format: criteria_id:result. Example: eval=value_framing:success

        data_collection_params : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Data collection filters. Repeat param. Format: id:op:value where op is one of eq|neq|gt|gte|lt|lte|in|exists|missing. For in, pipe-delimit values.

        tool_names : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Filter conversations by tool names used during the call.

        page_size : typing.Optional[int]
            How many conversations to return at maximum. Can not exceed 100, defaults to 30.

        summary_mode : typing.Optional[ConversationsListRequestSummaryMode]
            Whether to include transcript summaries in the response.

        search : typing.Optional[str]
            Full-text or fuzzy search over transcript messages

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[GetConversationsPageResponseModel]
            Successful Response
        v1/convai/conversationsr)   rP   r%   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r+   r.   r/   r0   r3   r6   r7   r:   )r   r<   r=   r;   r>   r?   r   r   r@   r   r   rA   r8   r   r   r   rB   r   rP   r%   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r$   rD   rE   rF   r   r   r   list   s   V	


zRawConversationsClient.listr$   conversation_idc             	   C   s   | j jjdt| d|d}z>d|j  krdk r0n ntttt|	 d}t
||dW S |jdkrHtt|jtttt|	 dd	|	 }W n ty`   t|jt|j|jd
w t|jt|j|d
)a  
        Get the details of a particular conversation

        Parameters
        ----------
        conversation_id : str
            The id of the conversation you're taking the action on.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[GetConversationResponseModel]
            Successful Response
        v1/convai/conversations/r)   r,   r$   r.   r/   r0   r3   r6   r7   r:   )r   r<   r=   r	   r;   r>   r?   r   r   r@   r   r   rA   r8   r   r   r   rB   r   rd   r$   rD   rE   rF   r   r   r   get  s>   

zRawConversationsClient.getc             	   C   s   | j jjdt| d|d}zP|du s|j s t|ddW S d|j  kr+dk rBn nt	tj
ttj
| d}t||dW S |jd	krZtt|jt	ttt| dd
| }W n tyr   t|jt|j|jdw t|jt|j|d)a  
        Delete a particular conversation

        Parameters
        ----------
        conversation_id : str
            The id of the conversation you're taking the action on.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[typing.Any]
            Successful Response
        re   DELETErf   Nr3   r.   r/   r0   r6   r7   r:   )r   r<   r=   r	   rB   stripr   r;   r>   r?   Anyr   r@   r   rA   r8   r   r   r   rg   r   r   r   deleteN  sB   

zRawConversationsClient.delete)__name__
__module____qualname__r   r    strr>   Optionalboolr
   r   r   rG   r   rN   r   intUnionSequencer   r   rb   r   rh   rk   rl   r   r   r   r   r          
A
@	

 

3r   c                (   @   r   ))AsyncRawConversationsClientr   c                C   r   r   r   r   r   r   r   r      r!   z$AsyncRawConversationsClient.__init__Nr"   r%   r#   r$   r&   c             	         | j jjdd||d|dI dH }z>d|j  krdk r3n ntttt| d}t	||d	W S |jd
krKt
t|jtttt| dd| }W n tyc   t|jt|j|jdw t|jt|j|d)a  
        Get a signed url to start a conversation with an agent with an agent that requires authorization

        Parameters
        ----------
        agent_id : str
            The id of the agent you're taking the action on.

        include_conversation_id : typing.Optional[bool]
            Whether to include a conversation_id with the response. If included, the conversation_signature cannot be used again.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[ConversationSignedUrlResponseModel]
            Successful Response
        r(   r)   r*   r+   Nr.   r/   r0   r3   r6   r7   r:   )r   r<   r=   r;   r>   r?   r   r   r@   r   r   rA   r8   r   r   r   rB   rC   r   r   r   rG     F   	

z*AsyncRawConversationsClient.get_signed_urlrI   rJ   c             	      rx   )a  
        Get a WebRTC session token for real-time communication.

        Parameters
        ----------
        agent_id : str
            The id of the agent you're taking the action on.

        participant_name : typing.Optional[str]
            Optional custom participant name. If not provided, user ID will be used

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[TokenResponseModel]
            Successful Response
        rK   r)   rL   r+   Nr.   r/   r0   r3   r6   r7   r:   )r   r<   r=   r;   r>   r?   r   r   r@   r   r   rA   r8   r   r   r   rB   rM   r   r   r   rN     ry   z,AsyncRawConversationsClient.get_webrtc_tokenrO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   c             	      s>  | j jjddi d|d|d|d|d|d|d	|d
|d|	d|
d|d|d|d|d|d|d||dI dH }z>d|j  krNdk rcn ntttt| d}t	||dW S |jdkr{t
t|jtttt| dd| }W n ty   t|jt|j|jdw t|jt|j|d)a
  
        Get all conversations of agents that user owns. With option to restrict to a specific agent.

        Parameters
        ----------
        cursor : typing.Optional[str]
            Used for fetching next page. Cursor is returned in the response.

        agent_id : typing.Optional[str]
            The id of the agent you're taking the action on.

        call_successful : typing.Optional[EvaluationSuccessResult]
            The result of the success evaluation

        call_start_before_unix : typing.Optional[int]
            Unix timestamp (in seconds) to filter conversations up to this start date.

        call_start_after_unix : typing.Optional[int]
            Unix timestamp (in seconds) to filter conversations after to this start date.

        call_duration_min_secs : typing.Optional[int]
            Minimum call duration in seconds.

        call_duration_max_secs : typing.Optional[int]
            Maximum call duration in seconds.

        rating_max : typing.Optional[int]
            Maximum overall rating (1-5).

        rating_min : typing.Optional[int]
            Minimum overall rating (1-5).

        has_feedback_comment : typing.Optional[bool]
            Filter conversations with user feedback comments.

        user_id : typing.Optional[str]
            Filter conversations by the user ID who initiated them.

        evaluation_params : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Evaluation filters. Repeat param. Format: criteria_id:result. Example: eval=value_framing:success

        data_collection_params : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Data collection filters. Repeat param. Format: id:op:value where op is one of eq|neq|gt|gte|lt|lte|in|exists|missing. For in, pipe-delimit values.

        tool_names : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Filter conversations by tool names used during the call.

        page_size : typing.Optional[int]
            How many conversations to return at maximum. Can not exceed 100, defaults to 30.

        summary_mode : typing.Optional[ConversationsListRequestSummaryMode]
            Whether to include transcript summaries in the response.

        search : typing.Optional[str]
            Full-text or fuzzy search over transcript messages

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[GetConversationsPageResponseModel]
            Successful Response
        r`   r)   rP   r%   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r+   Nr.   r/   r0   r3   r6   r7   r:   )r   r<   r=   r;   r>   r?   r   r   r@   r   r   rA   r8   r   r   r   rB   ra   r   r   r   rb     s   V	


z AsyncRawConversationsClient.listrc   rd   c             	      s   | j jjdt| d|dI dH }z>d|j  krdk r4n ntttt|	 d}t
||dW S |jd	krLtt|jtttt|	 dd
|	 }W n tyd   t|jt|j|jdw t|jt|j|d)a  
        Get the details of a particular conversation

        Parameters
        ----------
        conversation_id : str
            The id of the conversation you're taking the action on.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[GetConversationResponseModel]
            Successful Response
        re   r)   rf   Nr.   r/   r0   r3   r6   r7   r:   )r   r<   r=   r	   r;   r>   r?   r   r   r@   r   r   rA   r8   r   r   r   rB   rg   r   r   r   rh     s@   

zAsyncRawConversationsClient.getc             	      s  | j jjdt| d|dI dH }zP|du s|j s$t|ddW S d|j  kr/dk rFn nt	tj
ttj
| d}t||dW S |jd	kr^tt|jt	ttt| dd
| }W n tyv   t|jt|j|jdw t|jt|j|d)a  
        Delete a particular conversation

        Parameters
        ----------
        conversation_id : str
            The id of the conversation you're taking the action on.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[typing.Any]
            Successful Response
        re   ri   rf   Nr3   r.   r/   r0   r6   r7   r:   )r   r<   r=   r	   rB   rj   r   r;   r>   r?   rk   r   r@   r   rA   r8   r   r   r   rg   r   r   r   rl     sD   

z"AsyncRawConversationsClient.delete)rm   rn   ro   r   r    rp   r>   rq   rr   r
   r   r   rG   r   rN   r   rs   rt   ru   r   r   rb   r   rh   rk   rl   r   r   r   r   rw     rv   rw   )#r>   json.decoderr   core.api_errorr   core.client_wrapperr   r   core.http_responser   r   core.jsonable_encoderr	   core.request_optionsr
   core.unchecked_base_modelr   !errors.unprocessable_entity_errorr   ,types.conversation_signed_url_response_modelr   types.evaluation_success_resultr   %types.get_conversation_response_modelr   +types.get_conversations_page_response_modelr   types.http_validation_errorr   types.token_response_modelr   -types.conversations_list_request_summary_moder   r   rw   r   r   r   r   <module>   s(     o