- 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 5.0 Microservices(Second Edition)
- 程序員面試白皮書
- 數據結構與算法JavaScript描述
- 網頁設計與制作教程(HTML+CSS+JavaScript)(第2版)
- Git高手之路
- Building Cross-Platform Desktop Applications with Electron
- Web程序設計(第二版)
- 從零開始學C語言
- 蘋果的產品設計之道:創建優秀產品、服務和用戶體驗的七個原則
- 零基礎學C語言第2版
- Monitoring Docker
- Python自動化運維:技術與最佳實踐
- Flask Web開發實戰:入門、進階與原理解析
- SQL Server 2012數據庫管理與開發(慕課版)
- Python量子計算實踐:基于Qiskit和IBM Quantum Experience平臺