|
| 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( |
| 42 | + self, request: DialWhatsAppCallRequest |
| 43 | + ) -> DialWhatsAppCallResponse: |
| 44 | + """ |
| 45 | + Initiate an outbound WhatsApp call |
| 46 | +
|
| 47 | + Args: |
| 48 | + request: DialWhatsAppCallRequest containing call parameters |
| 49 | +
|
| 50 | + Returns: |
| 51 | + DialWhatsAppCallResponse with the WhatsApp call ID and room name |
| 52 | + """ |
| 53 | + return await self._client.request( |
| 54 | + SVC, |
| 55 | + "DialWhatsAppCall", |
| 56 | + request, |
| 57 | + self._auth_header(VideoGrants(room_create=True)), |
| 58 | + DialWhatsAppCallResponse, |
| 59 | + ) |
| 60 | + |
| 61 | + async def disconnect_whatsapp_call( |
| 62 | + self, request: DisconnectWhatsAppCallRequest |
| 63 | + ) -> DisconnectWhatsAppCallResponse: |
| 64 | + """ |
| 65 | + Disconnect an active WhatsApp call |
| 66 | +
|
| 67 | + Args: |
| 68 | + request: DisconnectWhatsAppCallRequest containing the call ID to disconnect |
| 69 | +
|
| 70 | + Returns: |
| 71 | + DisconnectWhatsAppCallResponse (empty response) |
| 72 | + """ |
| 73 | + return await self._client.request( |
| 74 | + SVC, |
| 75 | + "DisconnectWhatsAppCall", |
| 76 | + request, |
| 77 | + self._auth_header(VideoGrants(room_create=True)), |
| 78 | + DisconnectWhatsAppCallResponse, |
| 79 | + ) |
| 80 | + |
| 81 | + async def connect_whatsapp_call( |
| 82 | + self, request: ConnectWhatsAppCallRequest |
| 83 | + ) -> ConnectWhatsAppCallResponse: |
| 84 | + """ |
| 85 | + Connect a WhatsApp call with SDP information |
| 86 | +
|
| 87 | + Args: |
| 88 | + request: ConnectWhatsAppCallRequest containing call ID and SDP |
| 89 | +
|
| 90 | + Returns: |
| 91 | + ConnectWhatsAppCallResponse (empty response) |
| 92 | + """ |
| 93 | + return await self._client.request( |
| 94 | + SVC, |
| 95 | + "ConnectWhatsAppCall", |
| 96 | + request, |
| 97 | + self._auth_header(VideoGrants(room_create=True)), |
| 98 | + ConnectWhatsAppCallResponse, |
| 99 | + ) |
| 100 | + |
| 101 | + async def accept_whatsapp_call( |
| 102 | + self, request: AcceptWhatsAppCallRequest |
| 103 | + ) -> AcceptWhatsAppCallResponse: |
| 104 | + """ |
| 105 | + Accept an inbound WhatsApp call |
| 106 | +
|
| 107 | + Args: |
| 108 | + request: AcceptWhatsAppCallRequest containing call parameters and SDP |
| 109 | +
|
| 110 | + Returns: |
| 111 | + AcceptWhatsAppCallResponse with the room name |
| 112 | + """ |
| 113 | + return await self._client.request( |
| 114 | + SVC, |
| 115 | + "AcceptWhatsAppCall", |
| 116 | + request, |
| 117 | + self._auth_header(VideoGrants(room_create=True)), |
| 118 | + AcceptWhatsAppCallResponse, |
| 119 | + ) |
| 120 | + |
| 121 | + async def connect_twilio_call( |
| 122 | + self, request: ConnectTwilioCallRequest |
| 123 | + ) -> ConnectTwilioCallResponse: |
| 124 | + """ |
| 125 | + Connect a Twilio call to a LiveKit room |
| 126 | +
|
| 127 | + Args: |
| 128 | + request: ConnectTwilioCallRequest containing call parameters |
| 129 | +
|
| 130 | + Returns: |
| 131 | + ConnectTwilioCallResponse with the websocket URL for Twilio media stream |
| 132 | + """ |
| 133 | + return await self._client.request( |
| 134 | + SVC, |
| 135 | + "ConnectTwilioCall", |
| 136 | + request, |
| 137 | + self._auth_header(VideoGrants(room_create=True)), |
| 138 | + ConnectTwilioCallResponse, |
| 139 | + ) |
0 commit comments