- Voice User Interface Projects
- Henry Lee
- 553字
- 2021-07-23 17:17:20
Creating your first intent
Let's create our first FAQ question in this section: who is the first president of USA?. Click on Intents (+) and name it First-President. Enter Who is the first president of USA? into the User says box, and enter The first president of USA is George Washington into the text response box.
The following screenshot shows the First-President intent that was created in Dialogflow:

First, notice that when you enter Who is the first president of USA? into the User says input box, the words first and USA are highlighted in yellow and orange, respectively. Dialogflow automatically identifies the word first as the type ordinal (@sys.ordinal) and the word USA as the type geo-country (@sys.geo-country) and basically creates a templatized question. The FaqChatBot agent will use those parameters to match against the user's question. You can think of the parameters as the keywords that you will be using to search with Google's search engine and the search engine returning a result relevant to the search terms. In the case of FaqChatBot, the agent will match the intent First-President to the user's inquiry and respond to the user with the text you entered in the Text response box.
The following screenshot shows debugging in the virtual Google Assistant in Dialogflow:

When you type who is the first president of USA?, it shows the matching intent name First-President, and two parameters, geo-country as United States of America and ordinal 1, which are used to match the intent. It also shows the answer to the intent that you previously entered in the Default Response and you can play the voice output by clicking on the PLAY button. All this metadata about the found intent is converted into JSON, which the backend server can use. You will learn more about this in Chapter 3, Building a Fortune Cookie Application. When you click on the SHOW JSON
button, you will see the request data in the JSON format.
Important properties that are useful to observe in the given JSON are queryResult.parameters.geo-country and queryResult.parameters.ordinal, which contain extracted values that map to the entities automatically defined by Dialogflow. Also, queryResult.intent.displayName contains the matching intent name. With this information, the backend server will be able to properly process the user requests. We will cover this in Chapter 3, Building a Fortune Cookie Application.
The following code shows the request data in JSON:
{
"responseId": "0c50fd61-dd7e-4c91-a11a-eaebdaa1a412",
"queryResult": {
"queryText": "who is the first president of USA?",
"parameters": {
"geo-country": "United States of America",
"ordinal": 1
},
"allRequiredParamsPresent": true,
"fulfillmentText": "The first president of USA is George Washington.",
"fulfillmentMessages": [
{
"text": {
"text": [
"The first president of USA is George Washington."
]
}
}
],
"intent": {
"name": "projects/faqchatbot-9417a/agent/intents/40991159-4a3e-4cfe-95ac-9be610220f51",
"displayName": "First President"
},
"intentDetectionConfidence": 0.75,
"diagnosticInfo": {},
"languageCode": "en"
}
}
Lastly, if you enter who is the second president of USA?, you will notice that you get the exact same response, except the ordinal will be 2 and the response you get is George Washington as the second president, which is not the correct answer. In the next section, you will learn how to utilize entities to address this problem.
- 計算思維與算法入門
- Android應(yīng)用程序開發(fā)與典型案例
- GitLab Cookbook
- 數(shù)據(jù)庫系統(tǒng)原理及MySQL應(yīng)用教程
- Java EE 7 Performance Tuning and Optimization
- Visual Basic程序設(shè)計實(shí)驗指導(dǎo)(第二版)
- Python Data Structures and Algorithms
- Yii Project Blueprints
- C語言從入門到精通
- Android開發(fā)三劍客:UML、模式與測試
- Red Hat Enterprise Linux Troubleshooting Guide
- C++程序設(shè)計習(xí)題與實(shí)驗指導(dǎo)
- 破繭成蝶:用戶體驗設(shè)計師的成長之路
- Apple Watch極速開發(fā)
- Java核心技術(shù)·卷Ⅱ:高級特性(原書第10版)