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

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.

主站蜘蛛池模板: 泸溪县| 红河县| 邳州市| 社旗县| 黄骅市| 乌拉特后旗| 惠州市| 龙泉市| 井陉县| 昂仁县| 云霄县| 房产| 上饶市| 永登县| 巨野县| 蓬溪县| 泰来县| 柳州市| 康平县| 驻马店市| 咸阳市| 常州市| 吉安市| 揭阳市| 普定县| 宜川县| 康马县| 海口市| 万宁市| 全南县| 体育| 建昌县| 浦江县| 佳木斯市| 星子县| 临夏县| 拉孜县| 台北市| 黄平县| 锦屏县| 靖安县|