« Previous Section | Branching and Logic |
In the last section, we learned how to use the branching modules (Branch on String, Branch on Number) to branch out to different sections within our application.
Now, we are going to learn how to use some of the modules from Variables and Math to add to our application.
For our sample application, we are going to create some variables and demonstrate how to use some of the variable modules.
First, drag out a Simple Prompt module onto your workspace and connect the circular node from the Start module to the triangular receptor of the Simple Prompt module. In the textbox of the Simple Prompt module, enter the following text: “This is a variable application”.
Next, drag out two “Reserve Variable” modules onto your workspace from the Variables and Math list of modules. Rename the first variable, variable, to variable1.
Then, drag out a Set Variable module onto your workspace and connect the circular node from the Simple Prompt module to the triangular receptor on the Set Variable module. Set the variable, variable1, to the value, “foo”.
From here, drag out another Simple Prompt module onto your workspace and connect the circular node from the Set Variable module to the triangular receptor on the Simple Prompt module. In that Simple Prompt module, enter the following text: “Variable 1 is set to”. Next, drag out a Say Variable module onto your workspace and connect the circular node from your Simple Prompt module to the triangular receptor on your Say Variable module. For your Say Variable module, select variable1 as your variable.
At this point, we have learned how to reserve a variable, set a variable, and say a variable. From here, we'll learn how to increment our variables. Continuing from our example, drag out a Set Variable module onto your workspace and connect the circular node from the Say Variable module to the triangular receptor on the Set Variable module. For your Set Variable module, rename the variable to variable2 and enter “2” in the textbox. Drag out a Simple Prompt module and connect the circular node from your Set Variable module to the triangular receptor on your Simple Prompt module. In the textbox of the Simple Prompt module, enter the following text: “Variable 2 is set to”. Next, drag out a Say Variable module to your workspace and connect the circular node from your Simple Prompt module to the triangular receptor of your Say Variable module. For your Say Variable module, select variable2 as your variable. From here, drag out an Increment By One module onto your workspace and connect the circular node from your Say Variable module to the triangular receptor of your Increment By One module. Then, drag out a Simple Prompt module onto your workspace and connect the circular node from your Increment By One module to the triangular receptor of your Simple Prompt module. In the textbox of your Simple Prompt module, enter the following text: “Variable 2 is now”. Drag out another Say Variable module onto your workspace and connect the circular node from your Simple Prompt module to the triangular receptor of the Say Variable. Select variable2 as the variable for your Say Variable module.
From here, drag out an Increment Variable module to your workspace and connect the circular node of your Say Variable module to the triangular receptor of your Increment Variable module. For your Increment Variable module, rename the variable to variable2 and enter “7” in the textbox. Next, drag out a Simple Prompt module onto your workspace and connect the circular node of your Increment Variable module to the triangular receptor of your Simple Prompt module. In the textbox of your Simple Prompt module, enter the following text: “Variable 2 is now”. Drag out a Say Variable module onto your workspace and connect the circular node from your Simple Prompt module to the triangular receptor of your Say Variable module. For your Say Variable module, select variable2 as your variable. Finally, drag out an Exit App module onto your workspace and connect the circular node from your Say Variable module to the triangular receptor on your Exit App module.
From this example, we reserve two variables, variable1 and variable2, using the Reserve Variable module and used the Set Variable module to set variable1 to “foo” and variable2 to “2”. We also use the Increment By One module to increment the value of variable2 from “2” to “3”. The Increment Variable module is used to increment variable2 from “3” to “10” after entering the value “7” in the textbox.
Now that we've learned how to use the variable modules, let's learn about the Concatenate, String Length, and Substring modules. First, drag out two Reserve Variable modules onto your workspace and name one of them variable1 and the other variable2.
Next, drag a Simple Prompt module to your workspace and connect the circular node from the Start module to the triangular receptor of the Simple Prompt module. In the textbox of the Simple Prompt module, enter the following text: “This is a variable application”. Drag out a Set Variable module onto your workspace and connect the circular node from your Simple Prompt module to the triangular receptor of your Set Variable module. Rename the variable of your Set Variable module to variable1 and enter “banana” in the textbox. Drag another Set Variable module onto your workspace and connect the circular node from your previous Set Variable module to the triangular receptor of your new Set Variable module. Rename the variable of your Set Variable module to variable2 and enter “bread” in the textbox.
From here, drag out a Concatenate module to your workspace and connect the circular node from your Say Variable module to the triangular receptor on your Concatenate module. For your Concatenate module, click on the ”+” button to add another variable and select variable1 and variable2 as your variables for concatenation.
Next, drag out a String Length module onto your workspace and connect the circular node from your Concatenate module to the triangular receptor of your String Length module. For your String Length module, select concat as the variable.
Next, drag out a Substring module onto your workspace and connect the circular node of the String Length module to the triangular receptor of the Substring module. For your Substring module, select concat as your variable. In the first textbox of your “Substring” module, enter “6” as the “chars from start”. In the second textbox of your “Substring” module, enter 0” as the “chars from end”.
Now, let's tie everything together using a Multipart Prompt. In the textbox of your Multipart Prompt module, enter the following text: “You're eating”. Click on the ”+” button to add a phrase/variable and click on the toggler to convert it to a variable. Select concat as the variable. Click on the ”+” button to add another phrase/variable and enter the following text in the textbox: “The string length of”. Click on the ”+” button to add another phrase/variable and click on the toggler to convert it to a variable. Select concat as the variable. Click on the ”+” button to add another phrase/variable and enter the following text in the textbox: “is”. Click on the ”+” button to add another phrase/variable and click on the toggler to convert it to a variable. Select strlen as the variable. Click on the ”+” button to add another phrase/variable and enter the following text in the textbox: “Without banana, you have”. Click on the ”+” button to add another phrase/variable and click on the toggler to convert it to a variable. Select substring as the variable. Finally, drag out an Exit App module and connect the circular node of your Multipart Prompt module to the triangular receptor of your Exit App module.
From this example, we reserve two variables, variable1 and variable2, and set variable1 to “banana” and variable2 to “bread”. We then use the Concatenate module to concatenate variable1 and variable2 together to make “bananabread”, which is stored in concat. We also use the String Length module to capture the string length in characters of concat, which is 11. Finally, we use the Substring module to capture the substring from the 6th character of the variable, concat, to the end of it. This leaves us with “bread” and that is stored in the variable, substring.
Now, we're going to learn how to use the Call Properties, Input Properties, Counter, and Parse Date/Time modules.
First, drag out two Reserve Variable modules to your workspace and declare one of them variable1 and the other variable2. Then, drag out a Call Properties module onto your workspace and connect the circular node of your Start module to the triangular receptor of your Call Properties module. For your Call Properties module, select variable1 as the variable and “Start time” as the property.
Next, drag out a Date Input module (located in the Complex Inputs list of modules) to your workspace and connect the circular node from your Call Properties module to the triangular receptor of your Date Input module. In the textbox of your Date Input module, enter the following text: “Please enter a date. First enter 4 digits for the year, then 2 digits for the month, followed by 2 digits for the day.” Select “yyyymmdd” as the format and enable Error handling for your Date Input module. Then, drag out a Counter module to your workspace and connect the Silence node of your Date Input module to the triangular receptor on the Counter module. For the default node of your Counter module, connect it to the triangular receptor on the Date Input module. Drag out a Simple Prompt module to your workspace and connect the “After 2 times” node to the triangular receptor of the Simple Prompt module. In the textbox of your Simple Prompt module, enter the following text: “I'm sorry, please try your call again later.” Connect an Exit App module to your Simple Prompt module to wrap up that branch of your application. Drag out another Counter module to your workspace and connect the Invalid entry node of your Date Input module to the triangular receptor on your Counter module. From there, follow the same procedure that you implemented for the Silence node of your Date Input module.
Next, drag out a Parse Date/Time module to your workspace and connect the circular node from your Date Input module to the triangular receptor of your Parse Date/Time module. For your Parse Date/Time module, select date as your variable and select “M/d/yyyy” as the output format.
Then, drag out an Input Properties module to your workspace and connect the circular node from your Parse Date/Time module to the triangular receptor of your Input Properties module.
Finally, to tie everything together again, let's drag out a Multipart Prompt module to your workspace and connect the circular node from your Input Properties module to the triangular receptor of your Multipart Prompt module. In the textbox of your Multipart Prompt module, enter the following text: “The start time of this call was”. Then, click on the ”+” button to add a phrase/variable and click on the toggler to convert it to a variable. Select variable1 as the variable. Click on the ”+” button again to add another phrase/variable and enter “You entered” in the textbox. Add another variable and select datePart (the variable for your Parse Date/Time module) as the variable. Add another phrase to your Multipart Prompt module and enter “using” in the textbox. Add one final variable to your Multipart Prompt module and select variable2 as your variable. Finally, add an Exit App module to your workspace and connect the circular node of your Multipart Prompt module to the triangular receptor of your Exit App module.
So, the application should look somewhat like the following:
From this example, we use the Call Properties module to set one of our variables, variable1, to the start time of the call. For our Date Input module, we prompt the user to enter a date in the format of “yyyymmdd” and enable Error handling. By attaching Counter modules to the Silence and Invalid entry nodes of the Date Input module, we allow the user up to 2 tries before playing an “I'm sorry, please try your call again later” message and hanging up. From here, we attach a Parse Date/Time module to the Date Input module to parse the result to a “M/d/yyyy” format. Finally, we use the Input Properties module to set variable2 to the input mode of the last entered input (in this case, it would be DTMF as we had not enabled speech recognition for our Date Input module).
The last module we'll look at for this section is the Evaluate Math module. The Evaluate Math function can be used to evaluate math expressions, with the full range of ECMAScript Math functions, Math constants, and operators. In the following example application, we'll demonstrate a case in how you can use the Evaluate Math function.
For our multiplication application, drag out a Simple Prompt module to your workspace and connect it to the Start module. Enter the following text in the textbox: “Let's learn some math.” Next, drag out a Digits Input module to your workspace and connect it to your Simple Prompt module. Enter the following text in the textbox: “Enter a digit.” Drag out another Digits Input module to your workspace and connect it to your previous Digits Input module. Enter the following text in the textbox: “Enter another digit.” From here, drag out an Evaluate Math module to your workspace and connect it to your Digits Input module. Inside of your Evaluate Math module, enter the following text: “digits * digits2”. To wrap it up, drag out a Multipart Prompt module and connect it to your Evaluate Math module. Convert your phrase to a variable by clicking on the toggler and select digits as the variable. Click on the ”+” button to add a phrase and enter “times” in the textbox. Click on the ”+” button again to add a phrase/variable and convert it to a variable by clicking on the toggler. Select digits2 as your variable. Click on the ”+” button to add a phrase and enter “equals” in the textbox. Then, click on the ”+” button one last time to add a phrase/variable and click on the toggler to convert it to a variable. Select mathResult as your variable. Finally, drag out an Exit App module and connect it to your Multipart Prompt module.
From this example, we allow the user to enter two digits using the Digits Input modules. With these inputs, we multiply them together by using the Evaluate Math module. This is done by entering digits (the variable for our first Digits Input module) * digits2 (the variable for our second Digits Input module). From here, we state the digits that the user had entered along with the result of adding the two digits together.
Next Section » | Simple Database Integration |