Skip to content

Commit

Permalink
(New) Added Interdigit timeout to Ask object.
Browse files Browse the repository at this point in the history
(New) Added collect digits sample app.
(Fix) Code cleanup and reformatting.
  • Loading branch information
unknown committed Dec 5, 2011
1 parent 0c33c47 commit 0e17d89
Show file tree
Hide file tree
Showing 40 changed files with 665 additions and 262 deletions.
6 changes: 6 additions & 0 deletions TropoCSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TropoOutboundSMS", "TropoOu
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TropoConference", "TropoConference\TropoConference.csproj", "{771A2BE5-CA58-47C7-B15F-94A5CC4B0478}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TropoCollectDigits", "TropoCollectDigits\TropoCollectDigits.csproj", "{28BDBA2A-4127-42B8-A22B-E54E43FDD185}"
EndProject
Global
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = TropoCSharp.vsmdi
Expand Down Expand Up @@ -49,6 +51,10 @@ Global
{771A2BE5-CA58-47C7-B15F-94A5CC4B0478}.Debug|Any CPU.Build.0 = Debug|Any CPU
{771A2BE5-CA58-47C7-B15F-94A5CC4B0478}.Release|Any CPU.ActiveCfg = Release|Any CPU
{771A2BE5-CA58-47C7-B15F-94A5CC4B0478}.Release|Any CPU.Build.0 = Release|Any CPU
{28BDBA2A-4127-42B8-A22B-E54E43FDD185}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28BDBA2A-4127-42B8-A22B-E54E43FDD185}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28BDBA2A-4127-42B8-A22B-E54E43FDD185}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28BDBA2A-4127-42B8-A22B-E54E43FDD185}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 3 additions & 0 deletions TropoCSharp/Structs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public struct Voice
public const string UsEnglishFemale_Susan = "Susan";
public const string UsEnglishFemale_Vanessa = "Vanessa";
public const string UsEnglishFemale_Veronica = "Veronica";
public const string UsEnglishMale_Dave = "Dave";
public const string UsEnglishMale_Steven = "Steven";
public const string UsEnglishMale_Victor = "Victor";
public const string BritishEnglishFemale_Elizabeth = "Elizabeth";
public const string BritishEnglishFemale_Kate = "Kate";
public const string BritishEnglishMale = "Simon";
Expand Down
23 changes: 13 additions & 10 deletions TropoCSharp/Tropo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,17 @@ public void Ask(int? attempts, bool? bargein, Choices choices, int? minConfidenc
/// 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="allowSignals">Allows for the assignment of an interruptable signal for this Tropo function</param>
/// <param name="bargein">Should the user be allowed to barge in before TTS is complete?</param>
/// <param name="interdigitTimeout">Defines how long to wait - in seconds - between key presses to determine the user has stopped entering input.</param>
/// <param name="choices">The grammar to use in recognizing and validating input</param>
/// <param name="minConfidence">How confident should Tropo be in a speech reco match?</param>
/// <param name="name">Identifies the return value of an Ask, so you know the context for the returned information.</param>
/// <param name="recognizer">Tells Tropo what language to listen for</param>
/// <param name="required">Is input required here?</param>
/// <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, Array allowSignals, bool? bargein, Choices choices, int? minConfidence, string name, bool? required, Say say, float? timeout)
public void Ask(int? attempts, Array allowSignals, bool? bargein, int? interdigitTimeout, Choices choices, int? minConfidence, string name, string recognizer, bool? required, Say say, float? timeout)
{
Ask ask = new Ask();
ask.Attempts = attempts;
Expand Down Expand Up @@ -101,7 +103,7 @@ public void Ask(Ask ask)
/// Places a call or sends an an IM, Twitter, or SMS message. To start a call, use the Session API to tell Tropo to launch your code.
/// </summary>
/// <param name="to">The party(ies)to call.</param>
/// <param name="from">An Endpoint object representing who the call is from.</param>
/// <param name="from">A string representing who the call is from.</param>
/// <param name="network">Network is used mainly by the text channels; values can be SMS when sending a text message, or a valid IM network name such as AIM, MSN, JABBER, YAHOO and GTALK.</param>
/// <param name="channel">This defines the channel used to place new calls.</param>
/// <param name="answerOnMedia">If this is set to true, the call will be considered "answered" and audio will begin playing as soon as media is received from the far end </param>
Expand All @@ -127,7 +129,7 @@ public void Call(IEnumerable<String> to, string from, string network, string cha
/// Overload for Call that allows the To parameter to be passed as a String.
/// </summary>
/// <param name="to">A String containing the recipient to call.</param>
/// <param name="from">An Endpoint object representing who the call is from.</param>
/// <param name="from">A string representing who the call is from.</param>
/// <param name="network">Network is used mainly by the text channels; values can be SMS when sending a text message, or a valid IM network name such as AIM, MSN, JABBER, YAHOO and GTALK.</param>
/// <param name="channel">This defines the channel used to place new calls.</param>
/// <param name="answerOnMedia">If this is set to true, the call will be considered "answered" and audio will begin playing as soon as media is received from the far end.</param>
Expand Down Expand Up @@ -155,7 +157,7 @@ public void Call(String to, string from, string network, string channel, bool? a
/// Overload for Call that allows events to be set via allowSignals.
/// </summary>
/// <param name="to"></param>
/// <param name="allowSignals"></param>
/// <param name="allowSignals">Allows for the assignment of an interruptable signal for this Tropo function</param>
/// <param name="from"></param>
/// <param name="network"></param>
/// <param name="channel"></param>
Expand Down Expand Up @@ -237,7 +239,7 @@ public void Conference(string id, bool? mute, string name, bool? playTones, bool
/// Overload for Conference that allows events to be set via allowSignals.
/// </summary>
/// <param name="id"></param>
/// <param name="allowSignals"></param>
/// <param name="allowSignals">Allows for the assignment of an interruptable signal for this Tropo function</param>
/// <param name="mute"></param>
/// <param name="name"></param>
/// <param name="playTones"></param>
Expand Down Expand Up @@ -283,7 +285,7 @@ public void Hangup()
/// <param name="to">The destination to make a call to or send a message to.</param>
/// <param name="answerOnMedia">If this is set to true, the call will be considered "answered" and audio will begin playing as soon as media is received from the far end.</param>
/// <param name="channel">This defines the channel used to place new calls.</param>
/// <param name="from">An Endpoint object representing who the call is from.</param>
/// <param name="from">A string representing who the call is from.</param>
/// <param name="name">Identifies the return value of a Message, so you know the context for the returned information.</param>
/// <param name="network">Network is used mainly by the text channels; values can be SMS when sending a text message, or a valid IM network name such as AIM, MSN, JABBER, YAHOO and GTALK.</param>
/// <param name="required">Determines whether Tropo should move on to the next action.</param>
Expand Down Expand Up @@ -426,7 +428,7 @@ public void Record(int? attempts, bool? bargein, bool? beep, Choices choices, st
/// Overload for Record that allows events to be set via allowSignals.
/// </summary>
/// <param name="attempts"></param>
/// <param name="allowSignals"></param>
/// <param name="allowSignals">Allows for the assignment of an interruptable signal for this Tropo function</param>
/// <param name="bargein"></param>
/// <param name="beep"></param>
/// <param name="choices"></param>
Expand Down Expand Up @@ -535,7 +537,7 @@ public void Say(string @value, string @as, string name, bool? required)
/// Overload for say that allows events to be set via allowSignals.
/// </summary>
/// <param name="value"></param>
/// <param name="allowSignals"></param>
/// <param name="allowSignals">Allows for the assignment of an interruptable signal for this Tropo function</param>
/// <param name="as"></param>
/// <param name="name"></param>
/// <param name="required"></param>
Expand Down Expand Up @@ -639,7 +641,7 @@ public void StopRecording()
/// </summary>
/// <param name="answerOnMedia">If this is set to true, the call will be considered "answered" and audio will begin playing as soon as media is received from the far end.</param>
/// <param name="choices">The grammar to use in recognizing and validating input.</param>
/// <param name="from">An Endpoint object representing who the call is from.</param>
/// <param name="from">A string representing who the call is from.</param>
/// <param name="on">An On object.</param>
/// <param name="ringRepeat">The number of rings to allow on the outbound call attempt.</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>
Expand All @@ -661,6 +663,7 @@ public void Transfer(bool? answerOnMedia, Choices choices, string from, On on, f
/// Overload for Transfer that allows events to be set via allowSignals.
/// </summary>
/// <param name="answerOnMedia"></param>
/// <param name="allowSignals">Allows for the assignment of an interruptable signal for this Tropo function</param>
/// <param name="choices"></param>
/// <param name="from"></param>
/// <param name="on"></param>
Expand Down
1 change: 1 addition & 0 deletions TropoCSharp/TropoCSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<Compile Include="TropoJSON.cs" />
<Compile Include="TropoResult.cs" />
<Compile Include="TropoSession.cs" />
<Compile Include="TropoUtilities.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
6 changes: 6 additions & 0 deletions TropoCSharp/TropoClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ public class Ask : TropoBase
[JsonProperty(PropertyName = "bargein")]
public bool? Bargein { get; set; }

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

[JsonProperty(PropertyName = "minConfidence")]
public int? MinConfidence { get; set; }

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

[JsonProperty(PropertyName = "recognizer")]
public string Recognizer { get; set; }

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

Expand Down
4 changes: 2 additions & 2 deletions TropoCSharp/TropoResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public Result(string json)
Sequence = (int)results["result"]["sequence"];
Complete = (bool)results["result"]["complete"];
Error = (string)results["result"]["error"];
Actions = (JObject)results["result"]["actions"];
Actions = (JContainer)results["result"]["actions"];
}

/// <summary>
Expand Down Expand Up @@ -56,6 +56,6 @@ public Result(string json)
/// <summary>
/// The result of the actions requested in the previous payload.
/// </summary>
public JObject Actions { get; set; }
public JContainer Actions { get; set; }
}
}
76 changes: 76 additions & 0 deletions TropoCSharp/TropoUtilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System.IO;
using Newtonsoft.Json.Linq;
using System.Text;

namespace TropoCSharp.Tropo
{
/// <summary>
/// Utility class for Tropo WebAPI.
/// </summary>
public static class TropoUtilities
{
/// <summary>
/// Method to read JSON sent from Tropo WebAPI.
/// </summary>
/// <param name="reader">Streamreader representing the JSON sent from Tropo.</param>
/// <returns>String of JSON</returns>
public static string parseJSON(StreamReader reader)
{
return reader.ReadToEnd();
}

/// <summary>
/// Parse a child object that is part of a Tropo JSON payload.
/// </summary>
/// <param name="tropoObject"></param>
/// <returns></returns>
public static JObject parseObject(JContainer tropoObject)
{
return JObject.Parse(tropoObject.ToString());
}

/// <summary>
/// Parse the child Actions object that is part of the Tropo Result object.
/// </summary>
/// <param name="actions">Actions - is either an Object or an Array.</param>
/// <returns></returns>
public static JContainer parseActions(JContainer actions)
{
JTokenType type = actions.Type;
if (type == JTokenType.Array)
{
return JArray.Parse(actions.ToString());
}
else
{
return parseObject(actions);
}
}

/// <summary>
/// Remove double quotes from strings that can break JSON.

This comment has been minimized.

Copy link
@brandly

brandly Sep 10, 2013

lol

/// </summary>
/// <param name="value">The string to remove double quotes from.</param>
/// <returns></returns>
public static string removeQuotes(string value)
{
return value.Replace("\"", "");
}

/// <summary>
/// Add spaces to a string of digits to improve TTS readback.
/// </summary>
/// <param name="value">The string to add spaces to.</param>
/// <returns></returns>
public static string addSpaces(string value)
{
StringBuilder str = new StringBuilder();
char[] array = value.ToCharArray();
foreach(char s in array)
{
str.Append(s + " ");
}
return str.ToString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ C:\TropoCSharp\TropoCSharp\obj\Debug\TropoCSharp.dll
C:\TropoCSharp\TropoCSharp\obj\Debug\TropoCSharp.pdb
C:\GitStuff\tropo-webapi-csharp\TropoCSharp\bin\Debug\TropoCSharp.dll
C:\GitStuff\tropo-webapi-csharp\TropoCSharp\bin\Debug\TropoCSharp.pdb
C:\GitStuff\tropo-webapi-csharp\TropoCSharp\bin\Debug\Newtonsoft.Json.xml
C:\GitStuff\tropo-webapi-csharp\TropoCSharp\obj\Debug\ResolveAssemblyReference.cache
C:\GitStuff\tropo-webapi-csharp\TropoCSharp\obj\Debug\TropoCSharp.dll
C:\GitStuff\tropo-webapi-csharp\TropoCSharp\obj\Debug\TropoCSharp.pdb
12 changes: 6 additions & 6 deletions TropoClassesTests/TropoClassesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class TropoClassesTests
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 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 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}}]}";
Expand Down Expand Up @@ -113,7 +113,7 @@ public void testAskWithEvents()
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.Ask(5, signals, false, null, choices, null, "test", Recognizer.UsEnglish, true, say, 30);
tropo.Hangup();
Assert.AreEqual(this.askJsonWithEvents, tropo.RenderJSON());
}
Expand Down Expand Up @@ -202,7 +202,7 @@ public void testMessage()
{
Say say = new Say("This is an announcement");
Tropo tropo = new Tropo();
tropo.Voice = Voice.BritishEnglishFemale;
tropo.Voice = Voice.BritishEnglishFemale_Kate;
string from = "3055551212";
List<String> to = new List<String>();
to.Add("3055195825");
Expand All @@ -228,7 +228,7 @@ public void testMessageFromObject()
message.Timeout = 10;

Tropo tropo = new Tropo();
tropo.Voice = Voice.BritishEnglishFemale;
tropo.Voice = Voice.BritishEnglishFemale_Kate;
tropo.Message(message);

Assert.AreEqual(this.messageJson, tropo.RenderJSON());
Expand All @@ -239,7 +239,7 @@ public void testMessageUseAllOptions()
{
Say say = new Say("This is an announcement");
Tropo tropo = new Tropo();
tropo.Voice = Voice.BritishEnglishFemale;
tropo.Voice = Voice.BritishEnglishFemale_Kate;
string from = "3055551212";
List<String> to = new List<String>();
to.Add("3055195825");
Expand Down
Loading

0 comments on commit 0e17d89

Please sign in to comment.