Skip to content

Commit

Permalink
(New) Added support for events on call, say, ask, record, conference,…
Browse files Browse the repository at this point in the history
… transfer objects

(New) Added additional tests for objects with event support.
(New) Enhanced conference example to demonstrate announcement to all conference participants.
  • Loading branch information
unknown committed Jul 29, 2011
1 parent 7f17058 commit e0fbed6
Show file tree
Hide file tree
Showing 11 changed files with 320 additions and 28 deletions.
147 changes: 143 additions & 4 deletions TropoCSharp/Tropo.cs
Expand Up @@ -60,7 +60,7 @@ public void Ask(int? attempts, bool? bargein, Choices choices, int? minConfidenc
}

/// <summary>
/// Overload method for Ask that allows an array of events to be used.
/// Overload method for Ask that allows events to be set via allowSignals.
/// </summary>
/// <param name="attempts">How many times the caller can attempt input before an error is thrown.</param>
/// <param name="bargein">Should the user be allowed to barge in before TTS is complete?</param>
Expand All @@ -71,10 +71,11 @@ public void Ask(int? attempts, bool? bargein, Choices choices, int? minConfidenc
/// <param name="say">This determines what is played or sent to the caller.</param>
/// <param name="timeout">The amount of time Tropo will wait, in seconds, after sending or playing the prompt for the user to begin a response.</param>
/// <param name="events">??</param>
public void Ask(int? attempts, bool? bargein, Choices choices, int? minConfidence, string name, bool? required, Say say, float? timeout, Array events)
public void Ask(int? attempts, Array allowSignals, bool? bargein, Choices choices, int? minConfidence, string name, bool? required, Say say, float? timeout)
{
Ask ask = new Ask();
ask.Attempts = attempts;
ask.allowSignals = allowSignals;
ask.Bargein = bargein;
ask.Choices = choices;
ask.MinConfidence = minConfidence;
Expand All @@ -85,8 +86,6 @@ public void Ask(int? attempts, bool? bargein, Choices choices, int? minConfidenc
ask.Timeout = timeout;

Serialize(ask, "ask");

// TODO: How is the events array supposed to be added to the Tropo object?
}

/// <summary>
Expand Down Expand Up @@ -152,6 +151,36 @@ public void Call(String to, string from, string network, string channel, bool? a
Serialize(call, "call");
}

/// <summary>
/// Overload for Call that allows events to be set via allowSignals.
/// </summary>
/// <param name="to"></param>
/// <param name="allowSignals"></param>
/// <param name="from"></param>
/// <param name="network"></param>
/// <param name="channel"></param>
/// <param name="answerOnMedia"></param>
/// <param name="timeout"></param>
/// <param name="headers"></param>
/// <param name="recording"></param>
public void Call(String to, Array allowSignals, string from, string network, string channel, bool? answerOnMedia, float? timeout, IDictionary<String, String> headers, StartRecording recording)
{
Call call = new Call
{
To = new List<String> { to },
allowSignals = allowSignals,
From = from,
Network = network,
Channel = channel,
AnswerOnMedia = answerOnMedia,
Timeout = timeout,
Headers = headers,
Recording = recording
};

Serialize(call, "call");
}

/// <summary>
/// Overload for Call that allows one parameter.
/// </summary>
Expand Down Expand Up @@ -204,6 +233,30 @@ public void Conference(string id, bool? mute, string name, bool? playTones, bool
Serialize(conference, "conference");
}

/// <summary>
/// Overload for Conference that allows events to be set via allowSignals.
/// </summary>
/// <param name="id"></param>
/// <param name="allowSignals"></param>
/// <param name="mute"></param>
/// <param name="name"></param>
/// <param name="playTones"></param>
/// <param name="required"></param>
/// <param name="terminator"></param>
public void Conference(string id, Array allowSignals, bool? mute, string name, bool? playTones, bool? required, string terminator)
{
Conference conference = new Conference();
conference.Id = id;
conference.allowSignals = allowSignals;
conference.Mute = mute;
conference.Name = name;
conference.PlayTones = playTones;
conference.Required = required;
conference.Terminator = terminator;

Serialize(conference, "conference");
}

/// <summary>
/// Overload for Conference that allows a Conference object to be passed.
/// </summary>
Expand Down Expand Up @@ -369,6 +422,48 @@ public void Record(int? attempts, bool? bargein, bool? beep, Choices choices, st
Serialize(record, "record");
}

/// <summary>
/// Overload for Record that allows events to be set via allowSignals.
/// </summary>
/// <param name="attempts"></param>
/// <param name="allowSignals"></param>
/// <param name="bargein"></param>
/// <param name="beep"></param>
/// <param name="choices"></param>
/// <param name="format"></param>
/// <param name="maxSilence"></param>
/// <param name="maxTime"></param>
/// <param name="method"></param>
/// <param name="password"></param>
/// <param name="required"></param>
/// <param name="say"></param>
/// <param name="timeout"></param>
/// <param name="transcription"></param>
/// <param name="username"></param>
/// <param name="url"></param>
public void Record(int? attempts, Array allowSignals, bool? bargein, bool? beep, Choices choices, string format, float? maxSilence, float? maxTime, string method, string password, bool? required, Say say, float? timeout, Transcription transcription, string username, string url)
{
Record record = new Record();
record.Attempts = attempts;
record.allowSignals = allowSignals;
record.Bargein = bargein;
record.Beep = beep;
record.Choices = choices;
record.Format = format;
record.MaxSilence = maxSilence;
record.MaxTime = maxTime;
record.Method = method;
record.Password = password;
record.Required = required;
record.Say = say;
record.Timeout = timeout;
record.Transcription = transcription;
record.Url = url;
record.Username = username;

Serialize(record, "record");
}

/// <summary>
/// Overload for Record that allows a Record object to be passed.
/// </summary>
Expand Down Expand Up @@ -436,6 +531,27 @@ public void Say(string @value, string @as, string name, bool? required)
Serialize(say, "say");
}

/// <summary>
/// Overload for say that allows events to be set via allowSignals.
/// </summary>
/// <param name="value"></param>
/// <param name="allowSignals"></param>
/// <param name="as"></param>
/// <param name="name"></param>
/// <param name="required"></param>
public void Say(string @value, Array allowSignals, string @as, string name, bool? required)
{
Say say = new Say();
say.allowSignals = allowSignals;
say.Value = @value;
say.As = @as;
say.Name = name;
say.Required = required;
say.Voice = String.IsNullOrEmpty(this.Voice) ? null : this.Voice;

Serialize(say, "say");
}

/// <summary>
/// Overload method for Say that allows only a string value to be passed.
/// </summary>
Expand Down Expand Up @@ -541,6 +657,29 @@ public void Transfer(bool? answerOnMedia, Choices choices, string from, On on, f
Serialize(transfer, "transfer");
}

/// <summary>
/// Overload for Transfer that allows events to be set via allowSignals.
/// </summary>
/// <param name="answerOnMedia"></param>
/// <param name="choices"></param>
/// <param name="from"></param>
/// <param name="on"></param>
/// <param name="timeout"></param>
/// <param name="to"></param>
public void Transfer(bool? answerOnMedia, Array allowSignals, Choices choices, string from, On on, float? timeout, IEnumerable<String> to)
{
Transfer transfer = new Transfer();
transfer.AnswerOnMedia = answerOnMedia;
transfer.allowSignals = allowSignals;
transfer.Choices = choices;
transfer.From = from;
transfer.On = on;
transfer.Timeout = timeout;
transfer.To = to;

Serialize(transfer, "transfer");
}

/// <summary>
/// Overload for Transfer that allows a Transfer object to be passed directly.
/// </summary>
Expand Down
18 changes: 18 additions & 0 deletions TropoCSharp/TropoClasses.cs
Expand Up @@ -14,6 +14,9 @@ public class Ask : TropoBase
[JsonProperty(PropertyName = "attempts")]
public int? Attempts { get; set; }

[JsonProperty(PropertyName = "allowSignals")]
public Array allowSignals { get; set; }

[JsonProperty(PropertyName = "bargein")]
public bool? Bargein { get; set; }

Expand Down Expand Up @@ -70,6 +73,9 @@ public class Call : TropoBase
[JsonProperty(PropertyName = "answerOnMedia")]
public bool? AnswerOnMedia { get; set; }

[JsonProperty(PropertyName = "allowSignals")]
public Array allowSignals { get; set; }

[JsonProperty(PropertyName = "name")]
public string Name { get; set; }

Expand Down Expand Up @@ -139,6 +145,9 @@ public class Conference : TropoBase
[JsonProperty(PropertyName = "id")]
public string Id { get; set; }

[JsonProperty(PropertyName = "allowSignals")]
public Array allowSignals { get; set; }

[JsonProperty(PropertyName = "mute")]
public bool? Mute { get; set; }

Expand Down Expand Up @@ -249,6 +258,9 @@ public class Record : TropoBase
[JsonProperty(PropertyName = "attempts")]
public int? Attempts { get; set; }

[JsonProperty(PropertyName = "allowSignals")]
public Array allowSignals { get; set; }

[JsonProperty(PropertyName = "bargein")]
public bool? Bargein { get; set; }

Expand Down Expand Up @@ -343,6 +355,9 @@ public class Say : TropoBase
[JsonProperty(PropertyName = "value")]
public string Value { get; set; }

[JsonProperty(PropertyName = "allowSignals")]
public Array allowSignals { get; set; }

[JsonProperty(PropertyName = "as")]
public string As { get; set; }

Expand Down Expand Up @@ -442,6 +457,9 @@ public class Transfer : TropoBase
[JsonProperty(PropertyName = "answerOnMedia")]
public bool? AnswerOnMedia { get; set; }

[JsonProperty(PropertyName = "allowSignals")]
public Array allowSignals { get; set; }

[JsonProperty(PropertyName = "choices")]
public Choices Choices { get; set; }

Expand Down
60 changes: 59 additions & 1 deletion TropoClassesTests/TropoClassesTests.cs
Expand Up @@ -16,15 +16,18 @@ namespace TropoClassesTests
public class TropoClassesTests
{
private string askJson = @"{""tropo"":[{ ""ask"":{""name"":""foo"",""choices"":{""value"":""[5 DIGITS]""},""say"":{""value"":""Please enter your 5 digit zip code.""}}}]}";
private string askJsonWithEvents = @"{""tropo"":[{ ""ask"":{""attempts"":5,""allowSignals"":[""endCall"",""tooLong""],""bargein"":false,""name"":""test"",""required"":true,""choices"":{""value"":""1,2,3""},""say"":{""value"":""This is an Ask test with events. Please enter 1, 2 or 3.""},""timeout"":30.0}},{ ""hangup"":{}}]}";
private string askJsonWithOptions = @"{""tropo"":[{ ""ask"":{""attempts"":1,""bargein"":false,""minConfidence"":30,""name"":""foo"",""required"":true,""choices"":{""value"":""[5 DIGITS]""},""say"":{""value"":""Please enter your 5 digit zip code.""},""timeout"":30.0}}]}";
private string recordJson = @"{""tropo"":[{ ""record"":{""choices"":{""value"":""[5 DIGITS]"",""terminator"":""#""},""format"":""audio/wav"",""method"":""POST"",""required"":true,""say"":{""value"":""Please say your account number""}}}]}";
private string recordJsonWithTranscription = @"{""tropo"":[{ ""record"":{""attempts"":1,""bargein"":false,""beep"":true,""choices"":{""value"":""[5 DIGITS]"",""terminator"":""#""},""format"":""audio/wav"",""maxSilence"":5.0,""maxTime"":30.0,""method"":""POST"",""required"":true,""say"":{""value"":""Please say your account number""},""timeout"":5.0,""password"":""foo"",""transcription"":{""id"":""foo"",""uri"":""http://example.com/"",""emailFormat"":""encoded""},""username"":""bar"",""url"":""http://example.com/""}}]}";
private string callJson = @"{""tropo"":[{ ""call"":{""to"":[""3055195825"",""3054445567""]}}]}";
private string callJsonAllOptions = @"{""tropo"":[{ ""call"":{""to"":[""3055195825""],""from"":""3055551212"",""network"":""SMS"",""channel"":""TEXT"",""answerOnMedia"":false,""headers"":{""foo"":""bar"",""bling"":""baz""},""recording"":{""format"":""audio/mp3"",""method"":""POST"",""url"":""http://blah.com/recordings/1234.wav"",""username"":""jose"",""password"":""password""},""timeout"":10.0}}]}";
private string conferenceJson = @"{""tropo"":[{ ""conference"":{""name"":""foo"",""id"":""1234"",""mute"":false,""playTones"":false,""terminator"":""#""}}]}";
private string callJsonWithEvents = @"{""tropo"":[{ ""call"":{""to"":[""3055195825""],""from"":""3055551414"",""network"":""PSTN"",""channel"":""VOICE"",""answerOnMedia"":true,""allowSignals"":[""tooLong"",""callOver""],""headers"":{""x-foo"":""bar"",""x-bling"":""baz""},""timeout"":60.0}}]}";
private string messageJson = @"{""tropo"":[{ ""message"":{""say"":{""value"":""This is an announcement""},""to"":[""3055195825""],""from"":""3055551212"",""network"":""SMS"",""channel"":""TEXT"",""answerOnMedia"":false,""timeout"":10.0,""voice"":""kate""}}]}";
private string messageJsonAllOptions = @"{""tropo"":[{ ""message"":{""say"":{""value"":""This is an announcement""},""to"":[""3055195825""],""from"":""3055551212"",""network"":""SMS"",""channel"":""TEXT"",""answerOnMedia"":false,""name"":""foo"",""required"":true,""timeout"":10.0,""voice"":""kate""}}]}";
private string startRecordingJson = @"{""tropo"":[{ ""startRecording"":{""format"":""audio/mp3"",""method"":""POST"",""url"":""http://blah.com/recordings/1234.wav"",""username"":""jose"",""password"":""password""}}]}";
private string conferenceJson = @"{""tropo"":[{ ""call"":{""to"":[""3035551212""]}},{ ""say"":{""value"":""Welcome to the conference.""}},{ ""conference"":{""id"":""123456789098765432"",""mute"":false,""name"":""testConference"",""playTones"":false,""terminator"":""#"",""required"":true}},{ ""say"":{""value"":""Thank you for joining the conference.""}}]}";
private string conferenceJsonWithEvents = @"{""tropo"":[{ ""call"":{""to"":[""3035551212""]}},{ ""say"":{""value"":""Welcome to the conference.""}},{ ""conference"":{""id"":""123456789098765432"",""allowSignals"":[""conferenceOver""],""mute"":false,""name"":""testConference"",""playTones"":false,""terminator"":""#"",""required"":true}}]}";

public TropoClassesTests()
{
Expand Down Expand Up @@ -103,6 +106,18 @@ public void testAskMethodWithAllArguements()
Assert.AreEqual(this.askJsonWithOptions, tropo.RenderJSON());
}

[TestMethod]
public void testAskWithEvents()
{
Tropo tropo = new Tropo();
string[] signals = new string[] { "endCall", "tooLong" };
Say say = new Say("This is an Ask test with events. Please enter 1, 2 or 3.");
Choices choices = new Choices("1,2,3");
tropo.Ask(5, signals, false, choices, null, "test", true, say, 30);
tropo.Hangup();
Assert.AreEqual(this.askJsonWithEvents, tropo.RenderJSON());
}

#endregion

#region Call Tests
Expand Down Expand Up @@ -163,6 +178,21 @@ public void testCallUsingCallObject()
Assert.AreEqual(this.callJsonAllOptions, tropo.RenderJSON());
}

[TestMethod]
public void testCallWithEvents()
{
Tropo tropo = new Tropo();

string[] signals = new string[] { "tooLong", "callOver" };

IDictionary<string, string> headers = new Dictionary<String, String>();
headers.Add("x-foo", "bar");
headers.Add("x-bling", "baz");

tropo.Call("3055195825", signals, "3055551414", Network.Pstn, Channel.Voice, true, 60, headers, null);
Assert.AreEqual(this.callJsonWithEvents, tropo.RenderJSON());
}

#endregion

#region Message Tests
Expand Down Expand Up @@ -313,5 +343,33 @@ public void testNewStartRecordingObject()

#endregion

#region Conference Tests

[TestMethod]
public void testConference()
{
Tropo tropo = new Tropo();
tropo.Call("3035551212");
tropo.Say("Welcome to the conference.");
tropo.Conference("123456789098765432", false, "testConference", false, true, "#");
tropo.Say("Thank you for joining the conference.");

Assert.AreEqual(this.conferenceJson, tropo.RenderJSON());

}

[TestMethod]
public void testConferenceWithEvents()
{
Tropo tropo = new Tropo();
string[] signals = new string[] { "conferenceOver" };
tropo.Call("3035551212");
tropo.Say("Welcome to the conference.");
tropo.Conference("123456789098765432", signals, false, "testConference", false, true, "#");

Assert.AreEqual(this.conferenceJsonWithEvents, tropo.RenderJSON());
}

#endregion
}
}

0 comments on commit e0fbed6

Please sign in to comment.