| | | 1 | | using System.Net.Http; |
| | | 2 | | using System.Threading.Tasks; |
| | | 3 | | |
| | | 4 | | namespace Livekit.Server.Sdk.Dotnet |
| | | 5 | | { |
| | | 6 | | /// <summary> |
| | | 7 | | /// A client for interacting with the Connector service, which connects WhatsApp and Twilio |
| | | 8 | | /// calls to LiveKit rooms. Only available in LiveKit Cloud. |
| | | 9 | | /// </summary> |
| | | 10 | | public class ConnectorServiceClient : BaseService |
| | | 11 | | { |
| | | 12 | | /// <summary> |
| | | 13 | | /// Creates the client. |
| | | 14 | | /// </summary> |
| | | 15 | | /// <param name="host">URL of the LiveKit server, <c>http(s)://</c> or <c>ws(s)://</c>; a subpath such as <c>htt |
| | | 16 | | /// <param name="apiKey">API key; the <c>LIVEKIT_API_KEY</c> environment variable when omitted.</param> |
| | | 17 | | /// <param name="apiSecret">API secret; the <c>LIVEKIT_API_SECRET</c> environment variable when omitted.</param> |
| | | 18 | | /// <param name="client">Optional <see cref="HttpClient"/> to send the requests with. The SDK never modifies it, |
| | | 19 | | public ConnectorServiceClient( |
| | | 20 | | string host, |
| | | 21 | | string apiKey = null, |
| | | 22 | | string apiSecret = null, |
| | | 23 | | HttpClient client = null |
| | | 24 | | ) |
| | 15 | 25 | | : base(host, apiKey, apiSecret, client) { } |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Starts an outbound WhatsApp call. |
| | | 29 | | /// </summary> |
| | | 30 | | /// <param name="request">WhatsApp phone number ID, API key, the number to call and the room to connect the call |
| | | 31 | | /// <returns>The WhatsApp call ID and the room.</returns> |
| | | 32 | | public async Task<DialWhatsAppCallResponse> DialWhatsAppCall( |
| | | 33 | | DialWhatsAppCallRequest request |
| | | 34 | | ) |
| | 1 | 35 | | { |
| | 1 | 36 | | return await SendAsync( |
| | 1 | 37 | | Twirp.Routes.Connector.DialWhatsAppCall, |
| | 1 | 38 | | request, |
| | 1 | 39 | | DialWhatsAppCallResponse.Parser, |
| | 1 | 40 | | AuthHeader(new VideoGrants { RoomCreate = true }) |
| | 1 | 41 | | ) |
| | 1 | 42 | | .ConfigureAwait(false); |
| | 1 | 43 | | } |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// Disconnects an active WhatsApp call. |
| | | 47 | | /// </summary> |
| | | 48 | | /// <param name="request">WhatsApp call ID and the reason.</param> |
| | | 49 | | /// <returns>Empty response.</returns> |
| | | 50 | | public async Task<DisconnectWhatsAppCallResponse> DisconnectWhatsAppCall( |
| | | 51 | | DisconnectWhatsAppCallRequest request |
| | | 52 | | ) |
| | 1 | 53 | | { |
| | 1 | 54 | | return await SendAsync( |
| | 1 | 55 | | Twirp.Routes.Connector.DisconnectWhatsAppCall, |
| | 1 | 56 | | request, |
| | 1 | 57 | | DisconnectWhatsAppCallResponse.Parser, |
| | 1 | 58 | | AuthHeader(new VideoGrants { RoomCreate = true }) |
| | 1 | 59 | | ) |
| | 1 | 60 | | .ConfigureAwait(false); |
| | 1 | 61 | | } |
| | | 62 | | |
| | | 63 | | /// <summary> |
| | | 64 | | /// Connects an established WhatsApp call, for business-initiated calls. |
| | | 65 | | /// </summary> |
| | | 66 | | /// <param name="request">WhatsApp call ID and the SDP of the call; optionally wait until it is answered.</param |
| | | 67 | | /// <returns>The connection details of the call.</returns> |
| | | 68 | | public async Task<ConnectWhatsAppCallResponse> ConnectWhatsAppCall( |
| | | 69 | | ConnectWhatsAppCallRequest request |
| | | 70 | | ) |
| | 1 | 71 | | { |
| | 1 | 72 | | return await SendAsync( |
| | 1 | 73 | | Twirp.Routes.Connector.ConnectWhatsAppCall, |
| | 1 | 74 | | request, |
| | 1 | 75 | | ConnectWhatsAppCallResponse.Parser, |
| | 1 | 76 | | AuthHeader(new VideoGrants { RoomCreate = true }) |
| | 1 | 77 | | ) |
| | 1 | 78 | | .ConfigureAwait(false); |
| | 1 | 79 | | } |
| | | 80 | | |
| | | 81 | | /// <summary> |
| | | 82 | | /// Accepts an inbound WhatsApp call. |
| | | 83 | | /// </summary> |
| | | 84 | | /// <param name="request">WhatsApp phone number ID, API key and the ID of the incoming call to accept.</param> |
| | | 85 | | /// <returns>The accepted call.</returns> |
| | | 86 | | public async Task<AcceptWhatsAppCallResponse> AcceptWhatsAppCall( |
| | | 87 | | AcceptWhatsAppCallRequest request |
| | | 88 | | ) |
| | 1 | 89 | | { |
| | 1 | 90 | | return await SendAsync( |
| | 1 | 91 | | Twirp.Routes.Connector.AcceptWhatsAppCall, |
| | 1 | 92 | | request, |
| | 1 | 93 | | AcceptWhatsAppCallResponse.Parser, |
| | 1 | 94 | | AuthHeader(new VideoGrants { RoomCreate = true }) |
| | 1 | 95 | | ) |
| | 1 | 96 | | .ConfigureAwait(false); |
| | 1 | 97 | | } |
| | | 98 | | |
| | | 99 | | /// <summary> |
| | | 100 | | /// Connects a Twilio call to a LiveKit room. |
| | | 101 | | /// </summary> |
| | | 102 | | /// <param name="request">Twilio call direction and the room to connect the call to.</param> |
| | | 103 | | /// <returns>The URL Twilio must connect the call to.</returns> |
| | | 104 | | public async Task<ConnectTwilioCallResponse> ConnectTwilioCall( |
| | | 105 | | ConnectTwilioCallRequest request |
| | | 106 | | ) |
| | 1 | 107 | | { |
| | 1 | 108 | | return await SendAsync( |
| | 1 | 109 | | Twirp.Routes.Connector.ConnectTwilioCall, |
| | 1 | 110 | | request, |
| | 1 | 111 | | ConnectTwilioCallResponse.Parser, |
| | 1 | 112 | | AuthHeader(new VideoGrants { RoomCreate = true }) |
| | 1 | 113 | | ) |
| | 1 | 114 | | .ConfigureAwait(false); |
| | 1 | 115 | | } |
| | | 116 | | } |
| | | 117 | | } |