VOGO Voice – Knowledge Base

Subexpression and its Significance

Estimated reading time: 5 min

Subexpression is a process implemented within a custom interaction model when there arises a need to write an expression inside another expression or for the purpose of writing nested expressions. This basic tutorial aims to showcase the advantage of using subexpression to carry out the calculation and call to action the values stored during a specific part of the session, thereby eliminating the need for using an Add Variables component.  

Adopting a comprehensive methodology, the tutorial is dedicated towards presenting a guided step-by-step walk-through to illustrate the execution of the subexpression and highlight its importance with an interaction flow. This instructional tutorial aims wholly at presenting an elementary use-case on how to create subexpression to carry out the task inline. Herein, the application of subexpression is used to determine the odd and even integer based on the mod the calculation derives at using the number provided by the user. Depending on the remainder that is attained, the skill then performs the task of identifying the given number as odd or even and relays it to the user accordingly.

Prerequisites: 

  •  VOGO Voice account: https://www.vogovoice.com/
  • Access rights to the Intents section under Settings.
  • Access rights to Interaction builder platform.

Create a custom intent

Create an appropriate intent to be invoked for executing an interaction flow mapped to it, the purpose here being to execute the subexpression within the custom interaction model.

Create an intent titled ‘Subexpression’ with suitable sample utterances mapped to it. The sample utterance for this intent would be: “Is the number odd or even” & “Tell me whether the number is odd or even”

To learn how to create custom intents refer the guide: https://university.vogovoice.com/kb/creating-intents/

Create another custom intent

Create another intent to be called within the interaction flow to capture the number provided by the user to produce the desired result of determining the number provided as odd or even.

Create an intent titled ‘Give number’ with suitable sample utterances mapped to it. The sample utterances for this intent would be: “{num)” & “number {num}” and “the number is {num}” where ‘num’ is the slot name. Assign the slot type to ENVIRONMENT_Number, which is a global slot with predefined values. 

Steps to create an interaction flow

Let’s walk you through the step-by-step process on how to build an interaction model that will illustrate the significance of the subexpression to perform the task of identifying the integer as odd or even in order to produce the desired output requested by the user.

1. Log into your VOGO Voice account to be directed to VOGO Voice Management Console (https://account.vogovoice.com)
2. Navigate to Interactions on the vertical bar displayed on the left-hand side of the Dashboard.
3. Click on the Interaction button at the bottom right-hand corner of the screen and select the ‘Subexpression’ intent to be directed into the Interaction builder platform.

4. In the flow diagram area, you will be able to see the Start and Response component.

5. Roll the mouse over the Response component to see the voice, computer and camera icon on the top right-hand side of the component.
6. Clicking on the Voice icon opens a Speak pop-up window with a field titled Say wherein you need to type the voice action intended for the user.
Say: Please give me the number, and I will check if it is odd or even.
7. Check the checkmark box in the Expect Response and type in the suitable Prompt message to proceed with the flow.
Prompt: Please provide the number.
The same message will be replicated in the Reprompt field.
Reprompt: Please provide the number.
8. Populate the field under Expectations by selecting the custom Intent Give Number from the drop-down list. 

🖍 Note: Ensure to click the Save button to save the interaction flow as and when edits are made.

To add a display message in a video-enabled voice-assisted device

1. Click on the Computer icon, and type in a condensed version of the voice message in the field titled Display Message of the Show pop-up window.
2. Populate the required fields and click the Save button. 
Title: Even and Odd Numbers 
Display Message: Please give me the number, and I will check if it is odd or even.

For further reference on how to populate the additional fields visit https://university.vogovoice.com/kb/guide-response-component/

9. Drag and drop another Response component onto the flow canvas and connect the anchor symbol of Give Number on the previous Response card to the newly dragged Response Component.

🖍 Note: To interconnect the different components click on their respective Anchor symbols so as to chain and hold them in the interaction flow.

10. Click on the Voice icon of the Response card to open up the Speak pop-up window and type the input as specified below.
Say: {{#if (mod inputs.num.value 2)}} The number is an odd number.{{else}}The number is an even number{{/if}}.

A Breakdown of the Template’s Structure

Here we use an ‘if’ statement to validate if the user input number is an odd number or an even number. For the execution of this task, we use the ‘mod’ function inside the ‘if’ statement. The ‘mod’ function will give a ‘true’ value if there is a remainder. The arguments for the ‘mod’ function are ‘inputs.num.value’ and ‘2’. If the mod value is true, then the first message will be given as the output. Or else, the second message will be provided as the output.

To add a display message in a video-enabled voice-assisted device

1. Click on the Computer icon, and type in a condensed version of the voice message in the field titled Display Message of the Show pop-up window.
2. Populate the required fields and click the Save button. 
Title: Even and Odd Numbers 
Display Message: {{#if (mod inputs.num.value 2)}} The number is an odd number.{{else}}The number is an even number{{/if}}.

To learn about different template engines to be followed to run functions visit https://university.vogovoice.com/kb/template-engine/

The screenshot below captures the aforementioned interaction flow.

Testing and Validation 

a) For Even Numbers

1. Click on the Test button next to the Flow Editor button on the interaction builder platform. 

2. In the Tests pop-up window that appears click the + button on its top right-hand corner. 

3. Fill the Name field of the Test Response window that shows up.
4. In the Conversation section of the Test Response, Subexpression intent through which this interaction flow has been initiated will be auto-generated in the User invokes field.
5. Click the plus button within the Conversation section to open up an additional field titled User Invokes. Ensure to populate this field by selecting the Give Number intent called to action within the interaction flow.
6. Provide the ‘With slots’ field under Conversation titled ‘num’ with an even number.  Herein, the input provided is the number 2.

7. Finally, click the Save button to perform the test.
8. To validate the Test Response, click on the lightning symbol on the left-hand side of the test case.

9. On the resultant Test Response window, the blue chat bubbles present the input message within the Response component.

10. Click on the chat bubble to see the details of the response.

Testing and Validation

b) For Odd Numbers

Repeat the same steps as carried out while performing Testing for Even Number by incorporating the following changes:

Create a new test card titled Test 2 –Odd Number.

i) Provide an odd number within the ‘With slots’ field under Conversation titled ‘num’. The input to be provided is the number 3 which will generate the resultant Test Response window with the relevant chat bubbles.

ii) Click on the chat bubble to see the details of the individual responses.

To know more about testing an interaction refer https://university.vogovoice.com/kb/testings/

Congratulations! You have successfully created a custom interaction model by making use of subexpression to determine the odd and even integer based on the input provided by the user. On the whole, you have designed an interaction flow that is efficiently tailored and curated with voice responses to suit the specific requirements of the end-user. 

👍 Note: To test the functioning of the interactions on your device you have to deploy the custom skill to facilitate the skill with the new edits. To accomplish this, click on the Deploy button seen at the bottom of the Skill Settings pop-up window.

To know how to deploy a custom skill visit https://university.vogovoice.com/kb/deploying-a-skill/

To learn more about Subexpression, click here.

Tags:
Was this article helpful?
Dislike 0
Previous: How to use Lookup Function
Next: Loop with Condition