1+ from __future__ import annotations
2+
3+ import aiohttp
4+
5+ from livekit .protocol .connector_whatsapp import (
6+ DialWhatsAppCallRequest ,
7+ DialWhatsAppCallResponse ,
8+ DisconnectWhatsAppCallRequest ,
9+ DisconnectWhatsAppCallResponse ,
10+ ConnectWhatsAppCallRequest ,
11+ ConnectWhatsAppCallResponse ,
12+ AcceptWhatsAppCallRequest ,
13+ AcceptWhatsAppCallResponse ,
14+ )
15+ from livekit .protocol .connector_twilio import (
16+ ConnectTwilioCallRequest ,
17+ ConnectTwilioCallResponse ,
18+ )
19+ from ._service import Service
20+ from .access_token import VideoGrants
21+
22+ SVC = "Connector"
23+ """@private"""
24+
25+
26+ class ConnectorService (Service ):
27+ """Client for LiveKit Connector Service API
28+
29+ Recommended way to use this service is via `livekit.api.LiveKitAPI`:
30+
31+ ```python
32+ from livekit import api
33+ lkapi = api.LiveKitAPI()
34+ connector_service = lkapi.connector
35+ ```
36+ """
37+
38+ def __init__ (self , session : aiohttp .ClientSession , url : str , api_key : str , api_secret : str ):
39+ super ().__init__ (session , url , api_key , api_secret )
40+
41+ async def dial_whatsapp_call (self , request : DialWhatsAppCallRequest ) -> DialWhatsAppCallResponse :
42+ """
43+ Initiate an outbound WhatsApp call
44+
45+ Args:
46+ request: DialWhatsAppCallRequest containing call parameters
47+
48+ Returns:
49+ DialWhatsAppCallResponse with the WhatsApp call ID and room name
50+ """
51+ return await self ._client .request (
52+ SVC ,
53+ "DialWhatsAppCall" ,
54+ request ,
55+ self ._auth_header (VideoGrants (room_create = True )),
56+ DialWhatsAppCallResponse ,
57+ )
58+
59+ async def disconnect_whatsapp_call (self , request : DisconnectWhatsAppCallRequest ) -> DisconnectWhatsAppCallResponse :
60+ """
61+ Disconnect an active WhatsApp call
62+
63+ Args:
64+ request: DisconnectWhatsAppCallRequest containing the call ID to disconnect
65+
66+ Returns:
67+ DisconnectWhatsAppCallResponse (empty response)
68+ """
69+ return await self ._client .request (
70+ SVC ,
71+ "DisconnectWhatsAppCall" ,
72+ request ,
73+ self ._auth_header (VideoGrants (room_create = True )),
74+ DisconnectWhatsAppCallResponse ,
75+ )
76+
77+ async def connect_whatsapp_call (self , request : ConnectWhatsAppCallRequest ) -> ConnectWhatsAppCallResponse :
78+ """
79+ Connect a WhatsApp call with SDP information
80+
81+ Args:
82+ request: ConnectWhatsAppCallRequest containing call ID and SDP
83+
84+ Returns:
85+ ConnectWhatsAppCallResponse (empty response)
86+ """
87+ return await self ._client .request (
88+ SVC ,
89+ "ConnectWhatsAppCall" ,
90+ request ,
91+ self ._auth_header (VideoGrants (room_create = True )),
92+ ConnectWhatsAppCallResponse ,
93+ )
94+
95+ async def accept_whatsapp_call (self , request : AcceptWhatsAppCallRequest ) -> AcceptWhatsAppCallResponse :
96+ """
97+ Accept an inbound WhatsApp call
98+
99+ Args:
100+ request: AcceptWhatsAppCallRequest containing call parameters and SDP
101+
102+ Returns:
103+ AcceptWhatsAppCallResponse with the room name
104+ """
105+ return await self ._client .request (
106+ SVC ,
107+ "AcceptWhatsAppCall" ,
108+ request ,
109+ self ._auth_header (VideoGrants (room_create = True )),
110+ AcceptWhatsAppCallResponse ,
111+ )
112+
113+ async def connect_twilio_call (self , request : ConnectTwilioCallRequest ) -> ConnectTwilioCallResponse :
114+ """
115+ Connect a Twilio call to a LiveKit room
116+
117+ Args:
118+ request: ConnectTwilioCallRequest containing call parameters
119+
120+ Returns:
121+ ConnectTwilioCallResponse with the websocket URL for Twilio media stream
122+ """
123+ return await self ._client .request (
124+ SVC ,
125+ "ConnectTwilioCall" ,
126+ request ,
127+ self ._auth_header (VideoGrants (room_create = True )),
128+ ConnectTwilioCallResponse ,
129+ )
0 commit comments