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

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.

主站蜘蛛池模板: 赤水市| 探索| 临武县| 论坛| 文安县| 花垣县| 彰武县| 阳城县| 和田市| 平乐县| 肇州县| 离岛区| 彭泽县| 泸水县| 余江县| 邻水| 木里| 绥化市| 洞头县| 达日县| 龙泉市| 东兰县| 汶上县| 平昌县| 秦安县| 乌什县| 通化县| 芷江| 永年县| 瓦房店市| 兖州市| 嘉鱼县| 宜丰县| 衡东县| 姜堰市| 尚志市| 高淳县| 信阳市| 德安县| 孟连| 大足县|