
    qid                        d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z# ddl$m%Z% ddl&m'Z'm(Z( d	Z)	  G d
 de%      Z*y)    )annotationsN)Optional)
ListUpdate)SIPOutboundConfigSIPTrunkInfoCreateSIPInboundTrunkRequestUpdateSIPInboundTrunkRequestSIPInboundTrunkInfoSIPInboundTrunkUpdateCreateSIPOutboundTrunkRequestUpdateSIPOutboundTrunkRequestSIPOutboundTrunkInfoSIPOutboundTrunkUpdateListSIPInboundTrunkRequestListSIPInboundTrunkResponseListSIPOutboundTrunkRequestListSIPOutboundTrunkResponseDeleteSIPTrunkRequestSIPDispatchRuleSIPDispatchRuleInfoSIPDispatchRuleUpdateCreateSIPDispatchRuleRequestUpdateSIPDispatchRuleRequestListSIPDispatchRuleRequestListSIPDispatchRuleResponseDeleteSIPDispatchRuleRequestCreateSIPParticipantRequestTransferSIPParticipantRequestSIPParticipantInfoSIPTransport   )Service)VideoGrants	SIPGrantsSIPc                      e Zd ZdZd' fdZ	 	 	 	 d(dZ	 	 	 	 d(dZ	 	 	 	 	 	 d)dZ	 	 	 	 	 	 d)dZdddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d*d	Z	dddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d+d
Z
	 	 	 	 d,dZ	 	 	 	 d,dZ	 	 	 	 	 	 d-dZ	 	 	 	 	 	 d-dZdddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d.dZdddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d/dZ	 	 	 	 d0dZ	 	 	 	 d0dZ	 	 	 	 d1dZ	 	 	 	 d1dZd2dZd2dZ	 	 	 	 d3dZ	 	 	 	 d3dZ	 	 	 	 	 	 d4dZ	 	 	 	 	 	 d4dZdddddd	 	 	 	 	 	 	 	 	 	 	 	 	 d5dZdddddd	 	 	 	 	 	 	 	 	 	 	 	 	 d6dZ	 	 	 	 d7dZ	 	 	 	 d7d Z	 	 	 	 d8d!Z	 	 	 	 d8d"Z dddd#	 	 	 	 	 	 	 	 	 d9d$Z!	 	 	 	 d:d%Z"d;d&Z# xZ$S )<
SipServicezClient for LiveKit SIP Service API

    Recommended way to use this service is via `livekit.api.LiveKitAPI`:

    ```python
    from livekit import api
    lkapi = api.LiveKitAPI()
    sip_service = lkapi.sip
    ```
    c                *    t         |   ||||       y )N)super__init__)selfsessionurlapi_key
api_secret	__class__s        I/opt/pipecat/venv/lib/python3.12/site-packages/livekit/api/sip_service.pyr*   zSipService.__init__8   s    #w
;    c                   K   | j                   j                  t        d|| j                         t               d{   S 7 w)zCreate a new SIP inbound trunk.

        Args:
            create: Request containing trunk details

        Returns:
            Created SIP inbound trunk
        CreateSIPInboundTrunkN)_clientrequestSVC_admin_headersr
   r+   creates     r1   create_inbound_trunkzSipService.create_inbound_trunk;   A      \\))#!
 
 	
 
   9AA Ac                x   K   t        j                  dt        d       | j                  |       d{   S 7 w)zCreate a new SIP inbound trunk.

        .. deprecated::
           Use :meth:`create_inbound_trunk` instead.

        Args:
            create: Request containing trunk details

        Returns:
            Created SIP inbound trunk
        zHcreate_sip_inbound_trunk is deprecated, use create_inbound_trunk instead   
stacklevelN)warningswarnDeprecationWarningr;   r9   s     r1   create_sip_inbound_trunkz#SipService.create_sip_inbound_trunkN   6      	V	

 ..v6666   1:8:c                   K   | j                   j                  t        dt        ||      | j	                         t
               d{   S 7 w)zUpdates an existing SIP inbound trunk by replacing it entirely.

        Args:
            trunk_id: ID of the SIP inbound trunk to update
            trunk: SIP inbound trunk to update with

        Returns:
            Updated SIP inbound trunk
        UpdateSIPInboundTrunksip_trunk_idreplaceN)r5   r6   r7   r	   r8   r
   r+   trunk_idtrunks      r1   update_inbound_trunkzSipService.update_inbound_trunkc   sN      \\))#(% !	
 	
 		
 	
   AAAAc                z   K   t        j                  dt        d       | j                  ||       d{   S 7 w)aM  Updates an existing SIP inbound trunk by replacing it entirely.

        .. deprecated::
           Use :meth:`update_inbound_trunk` instead.

        Args:
            trunk_id: ID of the SIP inbound trunk to update
            trunk: SIP inbound trunk to update with

        Returns:
            Updated SIP inbound trunk
        zHupdate_sip_inbound_trunk is deprecated, use update_inbound_trunk insteadr?   r@   N)rB   rC   rD   rP   rM   s      r1   update_sip_inbound_trunkz#SipService.update_sip_inbound_trunk|   s8     " 	V	

 ..x????   2;9;Nnumbersallowed_addressesallowed_numbersauth_usernameauth_passwordnamemetadatac               Z  K   t        ||||      }	|t        |t              r|	j                  j                  j                  |j                         |	j                  j                  j                  |j                         |	j                  j                  j                  |j                         n%|	j                  j                  j                  |       |t        |t              r|	j                  j                  j                  |j                         |	j                  j                  j                  |j                         |	j                  j                  j                  |j                         n%|	j                  j                  j                  |       |t        |t              r|	j                  j                  j                  |j                         |	j                  j                  j                  |j                         |	j                  j                  j                  |j                         n%|	j                  j                  j                  |       | j                  j                  t        dt        ||	      | j                         t               d{   S 7 w)zqUpdates specific fields of an existing SIP inbound trunk.

        Only provided fields will be updated.
        )rY   rZ   r[   r\   NrI   rK   update)r   
isinstancer   rV   setextendaddremoverW   rX   r5   r6   r7   r	   r8   r
   )
r+   rN   rV   rW   rX   rY   rZ   r[   r\   r_   s
             r1   update_inbound_trunk_fieldsz&SipService.update_inbound_trunk_fields   s      '''	
 ':.""))'++6""))'++6%%,,W^^<""))'2(+Z8((,,334E4I4IJ((,,334E4I4IJ((//667H7O7OP((,,334EF&/:6&&**11/2E2EF&&**11/2E2EF&&--44_5K5KL&&**11/B\\))#(% !	
 	
 		
 	
s   J"J+$J)%J+c          
        K   t        j                  dt        d       | j                  ||||||||       d{   S 7 w)zUpdates specific fields of an existing SIP inbound trunk.

        .. deprecated::
           Use :meth:`update_inbound_trunk_fields` instead.

        Only provided fields will be updated.
        zVupdate_sip_inbound_trunk_fields is deprecated, use update_inbound_trunk_fields insteadr?   r@   rU   N)rB   rC   rD   re   )	r+   rN   rV   rW   rX   rY   rZ   r[   r\   s	            r1   update_sip_inbound_trunk_fieldsz*SipService.update_sip_inbound_trunk_fields   sY     & 	d	

 55/+'' 6 	
 	
 		
 	
r=   c                   K   | j                   j                  t        d|| j                         t               d{   S 7 w)zCreate a new SIP outbound trunk.

        Args:
            create: Request containing trunk details

        Returns:
            Created SIP outbound trunk
        CreateSIPOutboundTrunkN)r5   r6   r7   r8   r   r9   s     r1   create_outbound_trunkz SipService.create_outbound_trunk   sA      \\))$! 
 
 	
 
r=   c                x   K   t        j                  dt        d       | j                  |       d{   S 7 w)zCreate a new SIP outbound trunk.

        .. deprecated::
           Use :meth:`create_outbound_trunk` instead.

        Args:
            create: Request containing trunk details

        Returns:
            Created SIP outbound trunk
        zJcreate_sip_outbound_trunk is deprecated, use create_outbound_trunk insteadr?   r@   N)rB   rC   rD   rj   r9   s     r1   create_sip_outbound_trunkz$SipService.create_sip_outbound_trunk  s6      	X	

 //7777rG   c                   K   | j                   j                  t        dt        ||      | j	                         t
               d{   S 7 w)a  Updates an existing SIP outbound trunk by replacing it entirely.

        Args:
            trunk_id: ID of the SIP outbound trunk to update
            trunk: SIP outbound trunk to update with

        Returns:
            Updated SIP outbound trunk
        UpdateSIPOutboundTrunkrJ   N)r5   r6   r7   r   r8   r   rM   s      r1   update_outbound_trunkz SipService.update_outbound_trunk  sN      \\))$)% ! 	
 	
 		
 	
rQ   c                z   K   t        j                  dt        d       | j                  ||       d{   S 7 w)aR  Updates an existing SIP outbound trunk by replacing it entirely.

        .. deprecated::
           Use :meth:`update_outbound_trunk` instead.

        Args:
            trunk_id: ID of the SIP outbound trunk to update
            trunk: SIP outbound trunk to update with

        Returns:
            Updated SIP outbound trunk
        zJupdate_sip_outbound_trunk is deprecated, use update_outbound_trunk insteadr?   r@   N)rB   rC   rD   ro   rM   s      r1   update_sip_outbound_trunkz$SipService.update_sip_outbound_trunk/  s8     " 	X	

 //%@@@@rT   address	transportrV   rY   rZ   r[   r\   c               J  K   t        ||||||      }	|t        |t              r|	j                  j                  j                  |j                         |	j                  j                  j                  |j                         |	j                  j                  j                  |j                         n%|	j                  j                  j                  |       | j                  j                  t        dt        ||	      | j                         t               d{   S 7 w)zrUpdates specific fields of an existing SIP outbound trunk.

        Only provided fields will be updated.
        )rs   rt   rY   rZ   r[   r\   Nrn   r^   )r   r`   r   rV   ra   rb   rc   rd   r5   r6   r7   r   r8   r   )
r+   rN   rs   rt   rV   rY   rZ   r[   r\   r_   s
             r1   update_outbound_trunk_fieldsz'SipService.update_outbound_trunk_fieldsG  s       (''
 ':.""))'++6""))'++6%%,,W^^<""))'2\\))$)% ! 	
 	
 		
 	
s   DD#D!D#c          
        K   t        j                  dt        d       | j                  ||||||||       d{   S 7 w)zUpdates specific fields of an existing SIP outbound trunk.

        .. deprecated::
           Use :meth:`update_outbound_trunk_fields` instead.

        Only provided fields will be updated.
        zXupdate_sip_outbound_trunk_fields is deprecated, use update_outbound_trunk_fields insteadr?   r@   rr   N)rB   rC   rD   rv   )	r+   rN   rs   rt   rV   rY   rZ   r[   r\   s	            r1    update_sip_outbound_trunk_fieldsz+SipService.update_sip_outbound_trunk_fieldsr  sY     & 	f	

 66'' 7 	
 	
 		
 	
r=   c                   K   | j                   j                  t        d|| j                         t               d{   S 7 w)zList SIP inbound trunks with optional filtering.

        Args:
            list: Request with optional filtering parameters

        Returns:
            Response containing list of SIP inbound trunks
        ListSIPInboundTrunkN)r5   r6   r7   r8   r   r+   lists     r1   list_inbound_trunkzSipService.list_inbound_trunk  A      \\))!!'
 
 	
 
r=   c                x   K   t        j                  dt        d       | j                  |       d{   S 7 w)a  List SIP inbound trunks with optional filtering.

        .. deprecated::
           Use :meth:`list_inbound_trunk` instead.

        Args:
            list: Request with optional filtering parameters

        Returns:
            Response containing list of SIP inbound trunks
        zDlist_sip_inbound_trunk is deprecated, use list_inbound_trunk insteadr?   r@   N)rB   rC   rD   r}   r{   s     r1   list_sip_inbound_trunkz!SipService.list_sip_inbound_trunk  6      	R	

 ,,T2222rG   c                   K   | j                   j                  t        d|| j                         t               d{   S 7 w)zList SIP outbound trunks with optional filtering.

        Args:
            list: Request with optional filtering parameters

        Returns:
            Response containing list of SIP outbound trunks
        ListSIPOutboundTrunkN)r5   r6   r7   r8   r   r{   s     r1   list_outbound_trunkzSipService.list_outbound_trunk  sA      \\))"!(
 
 	
 
r=   c                x   K   t        j                  dt        d       | j                  |       d{   S 7 w)a!  List SIP outbound trunks with optional filtering.

        .. deprecated::
           Use :meth:`list_outbound_trunk` instead.

        Args:
            list: Request with optional filtering parameters

        Returns:
            Response containing list of SIP outbound trunks
        zFlist_sip_outbound_trunk is deprecated, use list_outbound_trunk insteadr?   r@   N)rB   rC   rD   r   r{   s     r1   list_sip_outbound_trunkz"SipService.list_sip_outbound_trunk  s6      	T	

 --d3333rG   c                   K   | j                   j                  t        d|| j                         t               d{   S 7 w)zDelete a SIP trunk.

        Args:
            delete: Request containing trunk ID to delete

        Returns:
            Deleted trunk information
        DeleteSIPTrunkN)r5   r6   r7   r8   r   r+   deletes     r1   delete_trunkzSipService.delete_trunk  sA      \\))!
 
 	
 
r=   c                x   K   t        j                  dt        d       | j                  |       d{   S 7 w)zDelete a SIP trunk.

        .. deprecated::
           Use :meth:`delete_trunk` instead.

        Args:
            delete: Request containing trunk ID to delete

        Returns:
            Deleted trunk information
        z8delete_sip_trunk is deprecated, use delete_trunk insteadr?   r@   N)rB   rC   rD   r   r   s     r1   delete_sip_trunkzSipService.delete_sip_trunk  s6      	F	

 &&v....rG   c                   K   | j                   j                  t        d|| j                         t               d{   S 7 w)zCreate a new SIP dispatch rule.

        Args:
            create: Request containing rule details

        Returns:
            Created SIP dispatch rule
        CreateSIPDispatchRuleNr5   r6   r7   r8   r   r9   s     r1   create_dispatch_rulezSipService.create_dispatch_rule	  r<   r=   c                x   K   t        j                  dt        d       | j                  |       d{   S 7 w)zCreate a new SIP dispatch rule.

        .. deprecated::
           Use :meth:`create_dispatch_rule` instead.

        Args:
            create: Request containing rule details

        Returns:
            Created SIP dispatch rule
        zHcreate_sip_dispatch_rule is deprecated, use create_dispatch_rule insteadr?   r@   N)rB   rC   rD   r   r9   s     r1   create_sip_dispatch_rulez#SipService.create_sip_dispatch_rule  rF   rG   c                   K   | j                   j                  t        dt        ||      | j	                         t
               d{   S 7 w)zUpdates an existing SIP dispatch rule by replacing it entirely.

        Args:
            rule_id: ID of the SIP dispatch rule to update
            rule: SIP dispatch rule to update with

        Returns:
            Updated SIP dispatch rule
        UpdateSIPDispatchRule)sip_dispatch_rule_idrL   N)r5   r6   r7   r   r8   r   r+   rule_idrules      r1   update_dispatch_rulezSipService.update_dispatch_rule1  sH      \\))#(gtT!
 
 	
 
rQ   c                z   K   t        j                  dt        d       | j                  ||       d{   S 7 w)aK  Updates an existing SIP dispatch rule by replacing it entirely.

        .. deprecated::
           Use :meth:`update_dispatch_rule` instead.

        Args:
            rule_id: ID of the SIP dispatch rule to update
            rule: SIP dispatch rule to update with

        Returns:
            Updated SIP dispatch rule
        zHupdate_sip_dispatch_rule is deprecated, use update_dispatch_rule insteadr?   r@   N)rB   rC   rD   r   r   s      r1   update_sip_dispatch_rulez#SipService.update_sip_dispatch_ruleG  s8     " 	V	

 ..w====rT   	trunk_idsr   r[   r\   
attributesc               F  K   t        ||||      }|t        |t              r|j                  j                  j                  |j                         |j                  j                  j                  |j                         |j                  j                  j                  |j                         n%|j                  j                  j                  |       | j                  j                  t        dt        ||      | j                         t               d{   S 7 w)zqUpdates specific fields of an existing SIP dispatch rule.

        Only provided fields will be updated.
        )r[   r\   r   r   Nr   )r   r_   )r   r`   r   r   ra   rb   rc   rd   r5   r6   r7   r   r8   r   )r+   r   r   r   r[   r\   r   r_   s           r1   update_dispatch_rule_fieldsz&SipService.update_dispatch_rule_fields_  s      '!	
  )Z0  $$++IMM:  $$++IMM:  ''..y/?/?@  $$++I6\\))#(gfU!
 
 	
 
s   DD!DD!c                  K   t        j                  dt        d       | j                  ||||||       d{   S 7 w)zUpdates specific fields of an existing SIP dispatch rule.

        .. deprecated::
           Use :meth:`update_dispatch_rule_fields` instead.

        Only provided fields will be updated.
        zVupdate_sip_dispatch_rule_fields is deprecated, use update_dispatch_rule_fields insteadr?   r@   r   N)rB   rC   rD   r   )r+   r   r   r   r[   r\   r   s          r1   update_sip_dispatch_rule_fieldsz*SipService.update_sip_dispatch_rule_fields  sS     " 	d	

 55! 6 
 
 	
 
s   7A >A c                   K   | j                   j                  t        d|| j                         t               d{   S 7 w)zList SIP dispatch rules with optional filtering.

        Args:
            list: Request with optional filtering parameters

        Returns:
            Response containing list of SIP dispatch rules
        ListSIPDispatchRuleN)r5   r6   r7   r8   r   r{   s     r1   list_dispatch_rulezSipService.list_dispatch_rule  r~   r=   c                x   K   t        j                  dt        d       | j                  |       d{   S 7 w)a  List SIP dispatch rules with optional filtering.

        .. deprecated::
           Use :meth:`list_dispatch_rule` instead.

        Args:
            list: Request with optional filtering parameters

        Returns:
            Response containing list of SIP dispatch rules
        zDlist_sip_dispatch_rule is deprecated, use list_dispatch_rule insteadr?   r@   N)rB   rC   rD   r   r{   s     r1   list_sip_dispatch_rulez!SipService.list_sip_dispatch_rule  r   rG   c                   K   | j                   j                  t        d|| j                         t               d{   S 7 w)zDelete a SIP dispatch rule.

        Args:
            delete: Request containing rule ID to delete

        Returns:
            Deleted rule information
        DeleteSIPDispatchRuleNr   r   s     r1   delete_dispatch_rulezSipService.delete_dispatch_rule  r<   r=   c                x   K   t        j                  dt        d       | j                  |       d{   S 7 w)zDelete a SIP dispatch rule.

        .. deprecated::
           Use :meth:`delete_dispatch_rule` instead.

        Args:
            delete: Request containing rule ID to delete

        Returns:
            Deleted rule information
        zHdelete_sip_dispatch_rule is deprecated, use delete_dispatch_rule insteadr?   r@   N)rB   rC   rD   r   r   s     r1   delete_sip_dispatch_rulez#SipService.delete_sip_dispatch_rule  rF   rG   )timeoutrN   outbound_trunk_configc               B  K   d}|rt        j                  |      }n|j                  r| j                  j                  j
                  rm| j                  j                  j
                  j                  rC| j                  j                  j
                  j                  dk  rt        j                  d      }|r||_        |r||_        | j                  j                  t        d|| j                  t               t        d            t        |       d{   S 7 w)	a  Create a new SIP participant.

        Args:
            create: Request containing participant details
            timeout: Optional request timeout in seconds
            trunk_id: Optional SIP trunk ID to use for the participant
            outbound_trunk_config: Optional outbound trunk configuration for the participant

        Returns:
            Created SIP participant

        Raises:
            SIPError: If the SIP operation fails
        N)total   CreateSIPParticipantTcallsip)r   )aiohttpClientTimeoutwait_until_answeredr5   _sessionr   r   rK   rO   r6   r7   _auth_headerr#   r$   r   )r+   r:   r   rN   r   client_timeouts         r1   create_sip_participantz!SipService.create_sip_participant  s     , ;?$22AN'' %%--LL))1177LL))1177"<!(!6!6R!@"*F 0FL\\))"km1EF" * 
 
 	
 
s   DDDDc                   K   | j                   j                  t        d|| j                  t	        d|j
                        t        d            t               d{   S 7 w)zTransfer a SIP participant to a different room.

        Args:
            transfer: Request containing transfer details

        Returns:
            Updated SIP participant information
        TransferSIPParticipantT)
room_adminroomr   r   N)r5   r6   r7   r   r#   	room_namer$   r   )r+   transfers     r1   transfer_sip_participantz#SipService.transfer_sip_participant$  sh      \\))$#!++ 4(   
 
 	
 
s   AA$A"A$c                L    | j                  t               t        d            S )NT)adminr   )r   r#   r$   )r+   s    r1   r8   zSipService._admin_headers=  s      ID4I JJr2   )r,   zaiohttp.ClientSessionr-   strr.   r   r/   r   )r:   r   returnr
   )rN   r   rO   r
   r   r
   )rN   r   rV    Optional[ListUpdate | list[str]]rW   r   rX   r   rY   Optional[str]rZ   r   r[   r   r\   r   r   r
   )rN   r   rV   Optional[list[str]]rW   r   rX   r   rY   r   rZ   r   r[   r   r\   r   r   r
   )r:   r   r   r   )rN   r   rO   r   r   r   )rN   r   rs   
str | Nonert   SIPTransport | NonerV   r   rY   r   rZ   r   r[   r   r\   r   r   r   )rN   r   rs   r   rt   r   rV   zlist[str] | NonerY   r   rZ   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   Optional[SIPDispatchRule]r[   r   r\   r   r   Optional[dict[str, str]]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   zOptional[float]rN   r   r   zOptional[SIPOutboundConfig]r   r   )r   r   r   r   )r   zdict[str, str])%__name__
__module____qualname____doc__r*   r;   rE   rP   rS   re   rg   rj   rl   ro   rq   rv   rx   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r8   __classcell__)r0   s   @r1   r'   r'   ,   s   	<
2
	
&727	7*

 #
 
	
2@@ #@ 
	@8 59>B<@'+'+""&5
5
 2	5

 <5
 :5
 %5
 %5
 5
  5
 
5
v (,15/3'+'+""&!
!
 %	!

 /!
 -!
 %!
 %!
 !
  !
 
!
F
3
	
&838	8*

 $
 
	
2AA $A 
	A8 #)-48$($(#)
)
 	)

 ')
 2)
 ")
 ")
 )
 )
 
)
^ #)-$($($(#!
!
 	!

 '!
 "!
 "!
 "!
 !
 !
 
!
F
.
	$
&3.3	$3*
/
	%
&4/4	%4*
"/&
2
	
&727	7*

 "
 
	
,>> "> 
	>8 7;*.""&/3"
"
 4	"

 ("
 "
  "
 -"
 
"
P *.*.""&/3

 '	

 (
 
  
 -
 

>
.
	$
&3.3	$3*
2
	
&727	72 $("&=A0
+0
 !	0

  0
  ;0
 
0
d
5
	
2Kr2   r'   )+
__future__r   r   rB   typingr   livekit.protocol.modelsr   livekit.protocol.sipr   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    _servicer"   access_tokenr#   r$   r7   r'    r2   r1   <module>r      s\    "    .       :  0 RK RKr2   