diff --git a/src/Plivo/PlivoApi.cs b/src/Plivo/PlivoApi.cs index 4d6852e4..0f08843c 100755 --- a/src/Plivo/PlivoApi.cs +++ b/src/Plivo/PlivoApi.cs @@ -17,6 +17,7 @@ using Plivo.Resource.Identity; using Plivo.Resource.CallFeedback; using Plivo.Resource.Media; +using Plivo.Resource.MultiPartyCall; namespace Plivo { @@ -40,6 +41,7 @@ public class PlivoApi private readonly Lazy _account; private readonly Lazy _subaccount; private readonly Lazy _application; + private readonly Lazy _multipartycall; private readonly Lazy _call; private readonly Lazy _conference; private readonly Lazy _message; @@ -143,6 +145,8 @@ public class PlivoApi /// /// Call Feedback. public CallFeedbackInterface CallFeedback => _callFeedback.Value; + + public MultiPartyCallInterface MultiPartyCall => _multipartycall.Value; /// /// Initializes a new instance of the class. @@ -180,6 +184,7 @@ public PlivoApi( _address = new Lazy(() => new AddressInterface(Client)); _identity = new Lazy(() => new IdentityInterface(Client)); _callFeedback = new Lazy(() => new CallFeedbackInterface(Client)); + _multipartycall = new Lazy(() => new MultiPartyCallInterface(Client)); } } } \ No newline at end of file diff --git a/src/Plivo/Resource/MultiPartyCall/MultiPartyCall.cs b/src/Plivo/Resource/MultiPartyCall/MultiPartyCall.cs new file mode 100644 index 00000000..ba9beaf5 --- /dev/null +++ b/src/Plivo/Resource/MultiPartyCall/MultiPartyCall.cs @@ -0,0 +1,91 @@ +using System; +using System.Threading.Tasks; +using Plivo.Client; + +namespace Plivo.Resource.MultiPartyCall +{ + /// + /// Application. + /// + public class MultiPartyCall : Resource + { + public string BilledAmount { get; set; } + public string BilledDuration { get; set; } + public string CreationTime { get; set; } + public string Duration { get; set; } + public string EndTime { get; set; } + public string FriendlyName { get; set; } + public string MpcUuid { get; set; } + public string Participants { get; set; } + public string Recording { get; set; } + public string HangResourceUri { get; set; } + public string StartTime { get; set; } + public string Status { get; set; } + public string StayAlone { get; set; } + public string TerminationCause { get; set; } + public string TerminationCauseCode { get; set; } + + // public string Role { get; set; } + // public string From { get; set; } + // public string To { get; set; } + // public string CallUuid { get; set; } + // public string CallStatusCallbackUrl { get; set; } + // public string CallStatusCallbackMethod { get; set; } + // public string SipHeaders { get; set; } + // public string ConfirmKey { get; set; } + // public string ConfirmKeySoundUrl { get; set; } + // public string ConfirmKeySoundMethod { get; set; } + // public string DialMusic { get; set; } + // public string RingTimeout { get; set; } + // public string MaxDuration { get; set; } + // public string MaxParticipants { get; set; } + // public string WaitMusicUrl { get; set; } + // public string WaitMusicMethod { get; set; } + // public string AgentHoldMusicUrl { get; set; } + // public string AgentHoldMusicMethod { get; set; } + // public string CustomerHoldMusicUrl { get; set; } + // public string CustomerHoldMusicMethod { get; set; } + // public string RecordingCallbackUrl { get; set; } + // public string RecordingCallbackMethod { get; set; } + // public string StatusCallbackUrl { get; set; } + // public string StatusCallbackMethod { get; set; } + // public string OnExitActionUrl { get; set; } + // public string OnExitActionMethod { get; set; } + // public string Record { get; set; } + // public string RecordFileFormat { get; set; } + // public string StatusCallbackEvents { get; set; } + // public string CoachMode { get; set; } + // public string Mute { get; set; } + // public string Hold { get; set; } + // public string StartMpcOnEnter { get; set; } + // public string EndMpcOnExit { get; set; } + // public string RelayDtmfInputs { get; set; } + // public string EnterSound { get; set; } + // public string EnterSoundMethod { get; set; } + // public string ExitSound { get; set; } + // public string ExitSoundMethod { get; set; } + + public MultiPartyCall() + { + } + + public override string ToString() + { + return "BilledAmount: " + BilledAmount + "\n" + + "BilledDuration: " + BilledDuration + "\n" + + "CreationTime: " + CreationTime + "\n" + + "Duration: " + Duration + "\n" + + "EndTime: " + EndTime + "\n" + + "FriendlyName: " + FriendlyName + "\n" + + "MpcUuid: " + MpcUuid + "\n" + + "Participants: " + Participants + "\n" + + "Recording: " + Recording + "\n" + + "HangResourceUri: " + HangResourceUri + "\n" + + "StartTime: " + StartTime + "\n" + + "Status: " + Status + "\n" + + "StayAlone: " + StayAlone + "\n" + + "TerminationCause: " + TerminationCause + "\n" + + "TerminationCauseCode: " + TerminationCauseCode + "\n"; + } + } +} \ No newline at end of file diff --git a/src/Plivo/Resource/MultiPartyCall/MultiPartyCallAddParticipantResponse.cs b/src/Plivo/Resource/MultiPartyCall/MultiPartyCallAddParticipantResponse.cs new file mode 100644 index 00000000..01feb6cf --- /dev/null +++ b/src/Plivo/Resource/MultiPartyCall/MultiPartyCallAddParticipantResponse.cs @@ -0,0 +1,23 @@ +namespace Plivo.Resource.MultiPartyCall +{ + public class MultiPartyCallAddParticipantResponse : CreateResponse + { + /// + /// Gets or sets the app identifier. + /// + /// The app identifier. + public string ApiId { get; set; } + + public string Message { get; set; } + public string RequestUuid { get; set; } + + /// + /// Returns a that represents the current . + /// + /// A that represents the current . + public override string ToString() + { + return "ApiId Id: " + ApiId + "\n" + "Message: " + Message + "\n" + "Request UUID: " + "\n" + RequestUuid + "\n"; + } + } +} \ No newline at end of file diff --git a/src/Plivo/Resource/MultiPartyCall/MultiPartyCallInterface.cs b/src/Plivo/Resource/MultiPartyCall/MultiPartyCallInterface.cs new file mode 100644 index 00000000..15278c70 --- /dev/null +++ b/src/Plivo/Resource/MultiPartyCall/MultiPartyCallInterface.cs @@ -0,0 +1,214 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Plivo.Client; +using Plivo.Exception; +using Plivo.Http; + + +namespace Plivo.Resource.MultiPartyCall +{ + /// + /// MPC interface. + /// + public class MultiPartyCallInterface : ResourceInterface + { + public string MakeMpcId(string mpcUuid, string friendlyName) + { + string mpcId = ""; + if (mpcUuid != null) + { + mpcId = "uuid_" + mpcUuid; + } + else if (friendlyName != null) + { + mpcId = "name_" + friendlyName; + } + else + { + throw new PlivoValidationException("Provide either mpc_uuid or friendly_name"); + } + + return mpcId; + } + + /// + /// Initializes a new instance of the class. + /// + /// Client. + public MultiPartyCallInterface(HttpClient client) : base(client) + { + Uri = "Account/" + Client.GetAuthId() + "/MultiPartyCall/"; + } + + public MultiPartyCall Get(string mpcUuid = null, string friendlyName = null) + { + string mpcId = MakeMpcId(mpcUuid, friendlyName); + return ExecuteWithExceptionUnwrap(() => + { + var mpc = Task.Run(async () => + await GetResource(mpcId, + new Dictionary() {{"is_voice_request", true}}).ConfigureAwait(false)).Result; + mpc.Interface = this; + return mpc; + }); + } + + public ListResponse List( + string subAccount = null, + string friendlyName = null, + string status = null, + string terminationCauseCode = null, + string endTimeGt = null, + string endTimeGte = null, + string endTimeLt = null, + string endTimeLte = null, + string endTime = null, + string creationTimeGt = null, + string creationTimeGte = null, + string creationTimeLt = null, + string creationTimeLte = null, + string creationTime = null, + uint? limit = null, + uint? offset = null) + { + string mpcId = MakeMpcId("", friendlyName); + var givenParams = new List { }; + bool isVoiceRequest = true; + var data = CreateData( + givenParams, + new + { + mpcId, subAccount, status, terminationCauseCode, endTime, endTimeGt, endTimeGte, endTimeLt, + endTimeLte, + creationTime, creationTimeGt, creationTimeGte, creationTimeLt, creationTimeLte, limit, offset, + isVoiceRequest + }); + return ExecuteWithExceptionUnwrap(() => + { + var resources = Task.Run(async () => + await ListResources>(data).ConfigureAwait(false)).Result; + resources.Objects.ForEach( + (obj) => obj.Interface = this + ); + + return resources; + }); + } + + public MultiPartyCallAddParticipantResponse AddParticipant( + string role = null, + string friendlyName = null, + string mpcUuid = null, + string from = null, + string to = null, + string callUuid = null, + string callStatusCallbackUrl = null, + string callStatusCallbackMethod = "POST", + string sipHeaders = null, + string confirmKey = null, + string confirmKeySoundUrl = null, + string confirmKeySoundMethod = "GET", + string dialMusic = null, + int ringTimeout = 45, + int maxDuration = 14400, + int maxParticipants = 10, + string waitMusicUrl = null, + string waitMusicMethod = "GET", + string agentHoldMusicUrl = null, + string agentHoldMusicMethod = "GET", + string customerHoldMusicUrl = null, + string customerHoldMusicMethod = "GET", + string recordingCallbackUrl = null, + string recordingCallbackMethod = "GET", + string statusCallbackUrl = null, + string statusCallbackMethod = "GET", + string onExitActionUrl = null, + string onExitActionMethod = "POST", + bool record = false, + string recordFileFormat = "mp3", + string statusCallbackEvents = "mpc-state-changes,participant-state-changes", + bool stayAlone = false, + bool coachMode = true, + bool mute = false, + bool hold = false, + bool startMpcOnEnter = true, + bool endMpcOnExit = false, + bool relayDtmfInputs = false, + string enterSound = "beep:1", + string enterSoundMethod = "GET", + string exitSound = "beep:2", + string exitSoundMethod = "GET") + { + if ((from != null || to != null) && callUuid != null) { + throw new PlivoValidationException("cannot specify call_uuid when (from, to) is provided"); + } + if (from == null && to == null && callUuid == null) { + throw new PlivoValidationException("specify either call_uuid or (from, to)"); + } + if (callUuid == null && (from == null || to == null)) { + throw new PlivoValidationException("specify (from, to) when not adding an existing call_uuid to multi party participant"); + } + string mpcId = MakeMpcId(mpcUuid, friendlyName); + var givenParams = new List { }; + bool isVoiceRequest = true; + var data = CreateData( + givenParams, + new + { + role, + friendlyName, + mpcUuid, + from, + to, + callUuid, + callStatusCallbackUrl, + callStatusCallbackMethod, + sipHeaders, + confirmKey, + confirmKeySoundUrl, + confirmKeySoundMethod, + dialMusic, + ringTimeout, + maxDuration, + maxParticipants, + waitMusicUrl, + waitMusicMethod, + agentHoldMusicUrl, + agentHoldMusicMethod, + customerHoldMusicUrl, + customerHoldMusicMethod, + recordingCallbackUrl, + recordingCallbackMethod, + statusCallbackUrl, + statusCallbackMethod, + onExitActionUrl, + onExitActionMethod, + record, + recordFileFormat, + statusCallbackEvents, + stayAlone, + coachMode, + mute, + hold, + startMpcOnEnter, + endMpcOnExit, + relayDtmfInputs, + enterSound, + enterSoundMethod, + exitSound, + exitSoundMethod, + isVoiceRequest + }); + return ExecuteWithExceptionUnwrap(() => + { + var result = Task.Run(async () => await Client.Update(Uri + mpcId + "/Participant", data).ConfigureAwait(false)).Result; + result.Object.StatusCode = result.StatusCode; + return result.Object; + }); + } + } +} \ No newline at end of file