官术网_书友最值得收藏!

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 President intent 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:

Dialogflow Virtual Google Assistant

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.

主站蜘蛛池模板: 马山县| 洪洞县| 子洲县| 旬邑县| 韶关市| 宣恩县| 洪泽县| 祁阳县| 华容县| 荣成市| 肥东县| 新竹县| 深泽县| 敖汉旗| 吴忠市| 尉氏县| 安顺市| 黔西县| 东乡| 博野县| 寻甸| 色达县| 平果县| 沁阳市| 都安| 宿松县| 吉木萨尔县| 温宿县| 万盛区| 花莲市| 志丹县| 乌苏市| 南郑县| 二连浩特市| 丰都县| 开平市| 资溪县| 报价| 青河县| 阿鲁科尔沁旗| 夏邑县|