Difference between pages "Phone Notify! TextToSay Advanced Commands" and "Convert Money to Text in C Sharp"

From CDYNE Wiki
(Difference between pages)
Jump to navigation Jump to search
imported>ChristopherC
(StatusChangePostURL)
 
imported>ChristopherC
 
Line 1: Line 1:
=== Advanced Notify Commands in our Current Release ===
+
This C# code allows you to convert currency numbers into words.
  
==== ActOnDigitPress ====
+
Example:
This turns off Message Interruption for digit commands (such as 1 for repeat). This is useful for a message that says Enter your zip code and doesn't jump around in the Dial Plan when the digits are pressed.
+
$152.17 into One Hundred Fifty Two Dollars and Seventeen Cents.
  
~\ActOnDigitPress(false)~
+
<code type=c#>
  
==== ActOnFeature ====
+
public static string ConvertMoneyToText(string value)
This will turn off AMD (Answering Machine Detection), Fax, and Ring Detection. This is useful when you do not wish the message to restart when these tones are detected.
+
{
 +
value = value.Replace(",", "").Replace("$", "");
 +
int decimalCount = 0;
 +
int Val = value.Length - 1;
 +
for (int x = 0; x <= Val; x++)
 +
{
 +
char Val2 = value[x];
 +
if (Val2.ToString() == ".")
 +
{
 +
decimalCount++;
 +
if (decimalCount > 1)
 +
{
 +
throw new ArgumentException("Only monetary values are accepted");
 +
}
 +
}
 +
Val2 = value[x];
 +
char Valtemp = value[x];
 +
if (!(char.IsDigit(value[x]) | (Val2.ToString() == ".")) & !((x == 0) & (Valtemp.ToString() == "-")))
 +
{
 +
throw new ArgumentException("Only monetary values are accepted");
 +
}
 +
}
 +
string returnValue = "";
 +
string[] parts;
 +
if (value.Contains("."))
 +
parts = value.Split(new char[] { '.' });
 +
else
 +
parts = (value + ".00").Split(new char[] { '.' });
  
~\ActOnFeature(false)~
 
  
==== AssignDTMF ====
+
parts[1] = new string((parts[1] + "00").Substring(0, 2).ToCharArray());
Assigns 1 to go to TestLbl (Note: 1 defaults to repeat msg.) - This can change anytime in the dialplan
+
bool IsNegative = parts[0].Contains("-");
 +
if (parts[0].Replace("-", "").Length > 0x12)
 +
{
 +
throw new ArgumentException("Maximum value is $999,999,999,999,999,999.99");
 +
}
 +
if (IsNegative)
 +
{
 +
parts[0] = parts[0].Replace("-", "");
 +
returnValue = returnValue + "Minus ";
 +
}
 +
if (parts[0].Length > 15)
 +
{
 +
returnValue = ((((returnValue + HundredsText(parts[0].PadLeft(0x12, '0').Substring(0, 3)) + "Quadrillion ")
 +
+ HundredsText(parts[0].PadLeft(0x12, '0').Substring(3, 3)) + "Trillion ") +
 +
HundredsText(parts[0].PadLeft(0x12, '0').Substring(6, 3)) + "Billion ") +
 +
HundredsText(parts[0].PadLeft(0x12, '0').Substring(9, 3)) + "Million ") +
 +
HundredsText(parts[0].PadLeft(0x12, '0').Substring(12, 3)) + "Thousand ";
 +
}
 +
else if (parts[0].Length > 12)
 +
{
 +
returnValue = (((returnValue + HundredsText(parts[0].PadLeft(15, '0').Substring(0, 3)) +
 +
"Trillion ") + HundredsText(parts[0].PadLeft(15, '0').Substring(3, 3)) + "Billion ") +
 +
HundredsText(parts[0].PadLeft(15, '0').Substring(6, 3)) + "Million ") +
 +
HundredsText(parts[0].PadLeft(15, '0').Substring(9, 3)) + "Thousand ";
 +
}
 +
else if (parts[0].Length > 9)
 +
{
 +
returnValue = ((returnValue + HundredsText(parts[0].PadLeft(12, '0').Substring(0, 3)) +
 +
"Billion ") + HundredsText(parts[0].PadLeft(12, '0').Substring(3, 3)) + "Million ") +
 +
HundredsText(parts[0].PadLeft(12, '0').Substring(6, 3)) + "Thousand ";
 +
}
 +
else if (parts[0].Length > 6)
 +
{
 +
returnValue = (returnValue + HundredsText(parts[0].PadLeft(9, '0').Substring(0, 3)) +
 +
"Million ") + HundredsText(parts[0].PadLeft(9, '0').Substring(3, 3)) + "Thousand ";
 +
}
 +
else if (parts[0].Length > 3)
 +
{
 +
returnValue = returnValue + HundredsText(parts[0].PadLeft(6, '0').Substring(0, 3)) +
 +
"Thousand ";
 +
}
 +
string hundreds = parts[0].PadLeft(3, '0');
 +
int tempInt = 0;
 +
hundreds = hundreds.Substring(hundreds.Length - 3, 3);
 +
if (int.TryParse(hundreds, out tempInt) == true)
 +
{
 +
if (int.Parse(hundreds) < 100)
 +
{
 +
//returnValue = returnValue + "and ";
 +
}
 +
returnValue = returnValue + HundredsText(hundreds) + "Dollar";
 +
if (int.Parse(hundreds) != 1)
 +
{
 +
returnValue = returnValue + "s";
 +
}
 +
if (int.Parse(parts[1]) != 0)
 +
{
 +
returnValue = returnValue + " and ";
 +
}
 +
}
 +
if ((parts.Length == 2) && (int.Parse(parts[1]) != 0))
 +
{
 +
returnValue = returnValue + HundredsText(parts[1].PadLeft(3, '0')) + "Cent";
 +
if (int.Parse(parts[1]) != 1)
 +
{
 +
returnValue = returnValue + "s";
 +
}
 +
}
 +
return returnValue;
 +
}
  
~\AssignDTMF(1|TestLbl)~
 
  
==== Beep ====
+
static string[] Tens = new string[] {
A standard Beep tone.  Usually used right before a Record command.
+
"Ten",
 +
"Twenty",
 +
"Thirty",
 +
"Forty",
 +
"Fifty",
 +
"Sixty",
 +
"Seventy",
 +
"Eighty",
 +
"Ninety" };
 +
static string[] Ones = new string[] {
 +
"One",
 +
"Two",
 +
"Three",
 +
"Four",
 +
"Five",
 +
"Six",
 +
"Seven",
 +
"Eight",
 +
"Nine",
 +
"Ten",
 +
"Eleven",
 +
"Twelve",
 +
"Thirteen",
 +
"Fourteen",
 +
"Fifteen",
 +
"Sixteen",
 +
"Seventeen",
 +
"Eighteen",
 +
"Nineteen" };
  
~\Beep()~
 
  
==== ClearDTMF ====
 
Provides a clean slate for Acting on DTMF Commands (This will clear the default of press 1 to repeat).
 
  
~\ClearDTMF()~
+
private static string HundredsText(string value)
 +
{
 +
char Val_1;
 +
char Val_2;
  
==== DialDTMF ====
+
string returnValue = "";
Dials a number in DTMF tones. xxx being the number to dial.
+
bool IsSingleDigit = true;
 +
char Val = value[0];
 +
if (int.Parse(Val.ToString()) != 0)
 +
{
 +
Val_1 = value[0];
 +
returnValue = returnValue + Ones[int.Parse(Val_1.ToString()) - 1] + " Hundred ";
 +
IsSingleDigit = false;
 +
}
 +
Val_1 = value[1];
 +
if (int.Parse(Val_1.ToString()) > 1)
 +
{
 +
Val = value[1];
 +
returnValue = returnValue + Tens[int.Parse(Val.ToString()) - 1] + " ";
 +
Val_1 = value[2];
 +
if (int.Parse(Val_1.ToString()) != 0)
 +
{
 +
Val = value[2];
 +
returnValue = returnValue + Ones[int.Parse(Val.ToString()) - 1] + " ";
 +
}
 +
return returnValue;
 +
}
 +
Val_1 = value[1];
 +
if (int.Parse(Val_1.ToString()) == 1)
 +
{
 +
Val = value[1];
 +
Val_2 = value[2];
 +
return (returnValue + Ones[int.Parse(Val.ToString() + Val_2.ToString()) - 1] + " ");
 +
}
 +
Val_2 = value[2];
 +
if (int.Parse(Val_2.ToString()) == 0)
 +
{
 +
return returnValue;
 +
}
 +
if (!IsSingleDigit)
 +
{
 +
returnValue = returnValue + "and ";
 +
}
 +
Val_2 = value[2];
 +
return (returnValue + Ones[int.Parse(Val_2.ToString()) - 1] + " ");
 +
}
  
~\DialDTMF(xxx)~
+
</code>
 
 
==== EndCall ====
 
Ends the call immediately.
 
 
 
~\EndCall()~
 
 
 
==== GetDigits ====
 
Returns the digits in the variable specified. Also waits 5 (or what you specify) seconds for digits.  Then continues to the next command.  Variables will be added to a new GetQueueIDStatus function called GetQueueIDStatusAdvanced.  This is due to security concerns and will allow you to pull more information about the call.  It is good to use this with the ActOnDigitPress(false) command before the sound file that you ask for this information.
 
 
 
~\GetDigits(TestVar|5)~
 
 
 
==== Goto ====
 
This will goto a Label defined by the Label command.
 
 
 
~\Goto(lbl)~
 
 
 
==== GotoIf ====
 
This will goto a Label only if the Variable is equal to the 2nd value.
 
 
 
~\GotoIf(TestVar|true|TestLbl)~
 
 
 
==== Label ====
 
Sets a label
 
 
 
~\Label(TestLbl)~
 
 
 
===== Special Labels =====
 
You can reset these labels in order for the system to do something that you wish during Amd for instance.
 
* '''Start''' - Start of a call.
 
* '''Ring''' - Where to go if a ring is detected in the call.
 
* '''Amd''' - Where to go if an answering machine is detected.
 
 
 
==== PlaySpecialSoundFile ====
 
This function is mainly used by CDYNE for global sound files such as recording sound files.
 
 
 
~\PlaySpecialSoundFile(xxxx)~
 
 
 
===== Some predefined sound files =====
 
 
 
* BEA78757-BE32-4670-A8F7-D7E03AAFFB95 - Hello, please record sound file for id...
 
* AAA31398-AED0-4854-B745-95D174AAFE37 - after the tone record the message and press # to hang up or stop speaking when you are finished.
 
* C8F07A8C-E130-4E54-BE55-8079B8BB64E5 - Press 1 to accept, Press 2 to rerecord the sound file.
 
* B8B80319-0308-4E9A-80D8-D3A3D1E3CF51 - Thank you for using the Sound Record Service.
 
 
 
==== QueryExternalServer ====
 
This allows you to query your own server and return a Variable to use in the dialplan.  Note: Special characters such as ~ ^ ( ) | are not allowed in the URL Field.  Your server has 5 seconds to respond or the system will report a provider error to the caller.
 
 
 
~\QueryExternalServer(url|TestVar)~
 
 
 
==== RecordAndSaveAs ====
 
Records the Wave file and saves it as the Sound ID.
 
 
 
~\RecordAndSaveAs(MySoundID) ~
 
 
 
==== RecordWithUniqueID ====
 
Records a with a unique soundid and sets the Variable to that SoundID.
 
 
 
~\RecordWithUniqueID(Variable)~
 
 
 
==== SetVar ====
 
Sets a Variable with the Value Specified.  Values could be forced to lowercase.
 
 
 
~\SetVar(Variable|Value)~
 
 
 
===== System Vars =====
 
This can be set at anytime in the call.
 
 
 
* '''maxrecordseconds''' - Sets the Maximum Record Length in seconds (ex: ~\SetVar(maxrecordseconds|30)~ for 30 secs).
 
* '''maxcallseconds''' - Sets the Maximum Call Length in seconds (You should set this at the beginning of the call).
 
 
 
==== StatusChangePostURL ====
 
This posts information about the call to a URL you specify.
 
 
 
~\StatusChangePostURL(posturl)~
 
 
 
It will Post to you these values:
 
* QueueID - Contains the ID of the Call.
 
* ResponseCode - 1 = Call Answered, 2 or more - Call unanswered. [http://ws.cdyne.com/notifyws/phonenotify.asmx/GetResponseCodes Status Codes]
 
* StartTime - Start time in Universal Time (UTC)
 
* EndTime - End time in Universal Time (UTC)
 
* Duration - Call Length in Seconds
 
* machinedetection - Currently only HUMAN, MACHINE, or FAX.
 
* [Any Variables you collected] - Any additional variables that you collected during the call.
 
 
 
Example of Usage:<br>
 
In Visual Studio.NET, under the Standard Page_Load event you could simply use the Request object to request these variables.
 
 
 
'''Note:''' Sending an AdvancedNotify will allow you to set this also.  Use StatusPostBackUrl in the AdvancedNotify Class.
 
 
 
==== TransferTo ====
 
This transfers the call immediately to the number specified.
 
 
 
~\TransferTo(17575551000)~
 
 
 
==== WaitForDTMF ====
 
This function waits x seconds for a DTMF Command - this differs from getdigits in that it accepts only one digit.  Make sure that ActOnDigitPress(true) is set (It is true by default).
 
 
 
~\WaitForDTMF(5)~
 
 
 
==== WaitForSilence ====
 
Waits for silence that lasts xxx number of seconds. (Up to a 10 second wait.)
 
 
 
~\WaitForSilence(xxx)~
 
 
 
=== Advanced Notify Commands in our Upcoming Release ===
 
 
 
==== VariableToTTS ====
 
Converts a Variable to Text To Speech and plays it to a caller.  Keep in mind that this gets sent to the TTS Server Farm for conversion (This is usually very quick).  Please try to limit the size of these otherwise your caller might enjoy too much dead-air.
 
 
 
~\VariableToTTS(Variable)~
 

Revision as of 17:20, 30 November 2009

This C# code allows you to convert currency numbers into words.

Example: $152.17 into One Hundred Fifty Two Dollars and Seventeen Cents.

public static string ConvertMoneyToText(string value) { value = value.Replace(",", "").Replace("$", ""); int decimalCount = 0; int Val = value.Length - 1; for (int x = 0; x <= Val; x++) { char Val2 = value[x]; if (Val2.ToString() == ".") { decimalCount++; if (decimalCount > 1) { throw new ArgumentException("Only monetary values are accepted"); } } Val2 = value[x]; char Valtemp = value[x]; if (!(char.IsDigit(value[x]) | (Val2.ToString() == ".")) & !((x == 0) & (Valtemp.ToString() == "-"))) { throw new ArgumentException("Only monetary values are accepted"); } } string returnValue = ""; string[] parts; if (value.Contains(".")) parts = value.Split(new char[] { '.' }); else parts = (value + ".00").Split(new char[] { '.' });


parts[1] = new string((parts[1] + "00").Substring(0, 2).ToCharArray()); bool IsNegative = parts[0].Contains("-"); if (parts[0].Replace("-", "").Length > 0x12) { throw new ArgumentException("Maximum value is $999,999,999,999,999,999.99"); } if (IsNegative) { parts[0] = parts[0].Replace("-", ""); returnValue = returnValue + "Minus "; } if (parts[0].Length > 15) { returnValue = ((((returnValue + HundredsText(parts[0].PadLeft(0x12, '0').Substring(0, 3)) + "Quadrillion ") + HundredsText(parts[0].PadLeft(0x12, '0').Substring(3, 3)) + "Trillion ") + HundredsText(parts[0].PadLeft(0x12, '0').Substring(6, 3)) + "Billion ") + HundredsText(parts[0].PadLeft(0x12, '0').Substring(9, 3)) + "Million ") + HundredsText(parts[0].PadLeft(0x12, '0').Substring(12, 3)) + "Thousand "; } else if (parts[0].Length > 12) { returnValue = (((returnValue + HundredsText(parts[0].PadLeft(15, '0').Substring(0, 3)) + "Trillion ") + HundredsText(parts[0].PadLeft(15, '0').Substring(3, 3)) + "Billion ") + HundredsText(parts[0].PadLeft(15, '0').Substring(6, 3)) + "Million ") + HundredsText(parts[0].PadLeft(15, '0').Substring(9, 3)) + "Thousand "; } else if (parts[0].Length > 9) { returnValue = ((returnValue + HundredsText(parts[0].PadLeft(12, '0').Substring(0, 3)) + "Billion ") + HundredsText(parts[0].PadLeft(12, '0').Substring(3, 3)) + "Million ") + HundredsText(parts[0].PadLeft(12, '0').Substring(6, 3)) + "Thousand "; } else if (parts[0].Length > 6) { returnValue = (returnValue + HundredsText(parts[0].PadLeft(9, '0').Substring(0, 3)) + "Million ") + HundredsText(parts[0].PadLeft(9, '0').Substring(3, 3)) + "Thousand "; } else if (parts[0].Length > 3) { returnValue = returnValue + HundredsText(parts[0].PadLeft(6, '0').Substring(0, 3)) + "Thousand "; } string hundreds = parts[0].PadLeft(3, '0'); int tempInt = 0; hundreds = hundreds.Substring(hundreds.Length - 3, 3); if (int.TryParse(hundreds, out tempInt) == true) { if (int.Parse(hundreds) < 100) { //returnValue = returnValue + "and "; } returnValue = returnValue + HundredsText(hundreds) + "Dollar"; if (int.Parse(hundreds) != 1) { returnValue = returnValue + "s"; } if (int.Parse(parts[1]) != 0) { returnValue = returnValue + " and "; } } if ((parts.Length == 2) && (int.Parse(parts[1]) != 0)) { returnValue = returnValue + HundredsText(parts[1].PadLeft(3, '0')) + "Cent"; if (int.Parse(parts[1]) != 1) { returnValue = returnValue + "s"; } } return returnValue; }


static string[] Tens = new string[] { "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" }; static string[] Ones = new string[] { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" };


private static string HundredsText(string value) { char Val_1; char Val_2;

string returnValue = ""; bool IsSingleDigit = true; char Val = value[0]; if (int.Parse(Val.ToString()) != 0) { Val_1 = value[0]; returnValue = returnValue + Ones[int.Parse(Val_1.ToString()) - 1] + " Hundred "; IsSingleDigit = false; } Val_1 = value[1]; if (int.Parse(Val_1.ToString()) > 1) { Val = value[1]; returnValue = returnValue + Tens[int.Parse(Val.ToString()) - 1] + " "; Val_1 = value[2]; if (int.Parse(Val_1.ToString()) != 0) { Val = value[2]; returnValue = returnValue + Ones[int.Parse(Val.ToString()) - 1] + " "; } return returnValue; } Val_1 = value[1]; if (int.Parse(Val_1.ToString()) == 1) { Val = value[1]; Val_2 = value[2]; return (returnValue + Ones[int.Parse(Val.ToString() + Val_2.ToString()) - 1] + " "); } Val_2 = value[2]; if (int.Parse(Val_2.ToString()) == 0) { return returnValue; } if (!IsSingleDigit) { returnValue = returnValue + "and "; } Val_2 = value[2]; return (returnValue + Ones[int.Parse(Val_2.ToString()) - 1] + " "); }