Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Voice mpc changes #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Plivo/PlivoApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Plivo.Resource.Identity;
using Plivo.Resource.CallFeedback;
using Plivo.Resource.Media;
using Plivo.Resource.MultiPartyCall;

namespace Plivo
{
Expand All @@ -40,6 +41,7 @@ public class PlivoApi
private readonly Lazy<AccountInterface> _account;
private readonly Lazy<SubaccountInterface> _subaccount;
private readonly Lazy<ApplicationInterface> _application;
private readonly Lazy<MultiPartyCallInterface> _multipartycall;
private readonly Lazy<CallInterface> _call;
private readonly Lazy<ConferenceInterface> _conference;
private readonly Lazy<MessageInterface> _message;
Expand Down Expand Up @@ -143,6 +145,8 @@ public class PlivoApi
/// </summary>
/// <value>Call Feedback.</value>
public CallFeedbackInterface CallFeedback => _callFeedback.Value;

public MultiPartyCallInterface MultiPartyCall => _multipartycall.Value;

/// <summary>
/// Initializes a new instance of the <see cref="T:plivo.PlivoApi"/> class.
Expand Down Expand Up @@ -180,6 +184,7 @@ public PlivoApi(
_address = new Lazy<AddressInterface>(() => new AddressInterface(Client));
_identity = new Lazy<IdentityInterface>(() => new IdentityInterface(Client));
_callFeedback = new Lazy<CallFeedbackInterface>(() => new CallFeedbackInterface(Client));
_multipartycall = new Lazy<MultiPartyCallInterface>(() => new MultiPartyCallInterface(Client));
}
}
}
91 changes: 91 additions & 0 deletions src/Plivo/Resource/MultiPartyCall/MultiPartyCall.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using System.Threading.Tasks;
using Plivo.Client;

namespace Plivo.Resource.MultiPartyCall
{
/// <summary>
/// Application.
/// </summary>
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";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Plivo.Resource.MultiPartyCall
{
public class MultiPartyCallAddParticipantResponse : CreateResponse
{
/// <summary>
/// Gets or sets the app identifier.
/// </summary>
/// <value>The app identifier.</value>
public string ApiId { get; set; }

public string Message { get; set; }
public string RequestUuid { get; set; }

/// <summary>
/// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:plivo.Resource.Application.ApplicationCreateResponse"/>.
/// </summary>
/// <returns>A <see cref="T:System.String"/> that represents the current <see cref="T:plivo.Resource.Application.ApplicationCreateResponse"/>.</returns>
public override string ToString()
{
return "ApiId Id: " + ApiId + "\n" + "Message: " + Message + "\n" + "Request UUID: " + "\n" + RequestUuid + "\n";
}
}
}
214 changes: 214 additions & 0 deletions src/Plivo/Resource/MultiPartyCall/MultiPartyCallInterface.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// MPC interface.
/// </summary>
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;
}

/// <summary>
/// Initializes a new instance of the <see cref="T:plivo.Resource.Application.MultiPartyCallInterface"/> class.
/// </summary>
/// <param name="client">Client.</param>
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<MultiPartyCall>(mpcId,
new Dictionary<string, object>() {{"is_voice_request", true}}).ConfigureAwait(false)).Result;
mpc.Interface = this;
return mpc;
});
}

public ListResponse<MultiPartyCall> 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<string> { };
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<ListResponse<MultiPartyCall>>(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<string> { };
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<MultiPartyCallAddParticipantResponse>(Uri + mpcId + "/Participant", data).ConfigureAwait(false)).Result;
result.Object.StatusCode = result.StatusCode;
return result.Object;
});
}
}
}