- Voice User Interface Projects
- Henry Lee
- 757字
- 2021-07-23 17:17:22
Creating your first context
In this section, you will learn how to incorporate contexts into intents.
The following flowchart shows the conversational flow that you will learn to build for FaqChatBot, which is asking about the Presidents' birthdays:

- In FaqChatBot, you will find the list of intents created by Dialogflow: Default Fallback Intent and Default Welcome Intent. The following screenshot shows the default welcome and fallback intents:

- The Default Welcome Intent is triggered the very first time the user uses FaqChatBot. Modify the Default Welcome Intent by changing the text response to Hi! Welcome to FAQ Chatbot. What is your name? so that the user will be greeted and asked what his or her name is. The following screenshot shows the modified Default Welcome Intent text response:

- Create Get Name and, in the Contexts section, type in GET_NAME in the Add output context textbox. GET_NAME can now be used as the input context in other intents, allowing other intents to access all the parameters captured by the Get Name intent.
- From the @sys.given-name:username template or my name is @sys.given-name:username, the intent will extract the username @sys.given-name:username and store it in the $username variable.
- Create a personalized text response using the user's name stored in the $username variable, $username you can ask me anything about the president of America. The following image shows the Get Name intent, which gets triggered when the user responds with his or her name:

The following screenshot shows the username variable, which contains the captured username found in the Action section of the Get Name intent:

- Before we can start creating the intent that can use the GET_NAME context, let's create a new entity for the Presidents' birthdays, called president-birthday, using JSON.
The following code shows the president-birthday entity:
[
{
"value": "December 14, 1799",
"synonyms": [ "George Washington" ]
},
{
"value": "October 30, 1735",
"synonyms": [ "John Adams" ]
}
]
- Once the president-birthday entity has been created, you can create the Get President Birthday intent, as shown in the following screenshot. Notice that, in the Contexts section, there is the GET_NAME context as the input context, which comes from the output context of the Get Name intent. By adding the GET_NAME context as the input, the Get President Birthday intent has access to all the parameters in the Get_Name intent.
- In the Action section, you can add the parameter called username, which maps to the parameter from the Get Name intent, #GET_NAME.username.
The following screenshot shows the get President Birthday intent, which shows the username variable mapping to #GET_NAME.username:

- You can create the text response using the $username variable, making the response more personable by using $username $president-birthday.original's birthday is on $president-birthday.
Contexts are a very powerful way to persist data across requests, but they come with drawbacks. First, if the intent contains the context, the intent will only get triggered if the request contains the required context and what the user says matches the intent template. For example, in the case of the Get President Birthday intent, the request must contain the GET_NAME context, and what the user says must also match the what is his birthday? or I want to know @president-birthday:president-birthday template. Lastly, the context lifespan can be limited to 10 minutes or the context can only be available through n number of requests. But an expiring context is not really ideal in a real-world application because you would not want to ask a user their name every time they use the voice application. In fact, you would want to recognize the user and greet them by their name. In Chapter 4, Hosting, Securing, and Testing Fortune Cookie in the Cloud, you will learn how to manage your own context without relying on Dialogflow contexts by creating your own persistence.
- Spring Boot 2實戰之旅
- GAE編程指南
- Modular Programming with Python
- Mobile Web Performance Optimization
- Power Up Your PowToon Studio Project
- Oracle Database In-Memory(架構與實踐)
- 樂學Web編程:網站制作不神秘
- 程序員數學:用Python學透線性代數和微積分
- INSTANT Mercurial SCM Essentials How-to
- Building Minecraft Server Modifications
- 從Java到Web程序設計教程
- 第一行代碼 C語言(視頻講解版)
- Node.js:來一打 C++ 擴展
- C# and .NET Core Test Driven Development
- 區塊鏈技術進階與實戰(第2版)