Target
Even with zero knowledge, we will bring you to the point where you can create Slack Bot and Line Bot using Watson.
[Updated on June 6, 2019] This post was written during the Watson Conversation era, the predecessor of Watson Assistant, and although screen captures are still old, Watson Assitant's basic ideas and operations Does not change, so please read it as the latest environment. </ font>
■ I would like to touch on the following.
(1) Introduction to thinking, creating an account
** ② How to design a dialogue flow using "Hotel reservation" as an example ** ← This article
** ③ Utilization of context, practical usage of various functions not mentioned in Tutorial **
④ How to link with Java logic
⑤ Create a chatbot with Watson + Java + Slack
This time, as Part 2, I will explain ** ② "Hotel reservation" as an example of how to design a dialogue flow **.
Click here for the last time → (1) Introduction to thinking, creating an account.
Create workspace
Last time, we even created the workspace and were ready to start interactive design.
If you haven't created a workspace yet, go to https://www.ibmwatsonconversation.com and create one.
Make a hotel reservation chatbot
The Watson Conversation dialogue flow can be created using a design tool on the Web called ** Dialog Node Editor ** (hereinafter referred to as the node editor).
This time, we will make a simple ** hotel reservation chatbot ** based on hotel reservations.
Make an Intent
I will explain step by step one by one.
No ** Intent ** has been registered yet, so click [Create new] to create the ** Intent ** required for hotel reservations.
Select ** Intents ** on the top tab and click Create new.
First, create an Intent that means ** reserve a room **. The Intent name is ** # reserve_room **.
Next, register the example sentence of ** Reserving a room **. ** Book a room ** You need to register at least 5 examples of sentences that you might say when you make a reservation.
When I reserve a room, I think there are various phrases, so I will put in what I can think of.
――I would like to reserve a room
--I want to make a reservation
――I want to make a reservation
――I want to secure a room
- I'd like to make an appointment
When you're done, click Done
Next, create an ** Intent to cancel the reservation **. Click Create new.
Name the Intent ** #cancel_room ** and, as before, enter an example sentence that you might say when canceling a room.
--I want to cancel the room
--Cassel the room
--I want to cancel my reservation
--I want to cancel my reservation
After creating two Intents, the balloon icon ** Ask Watson **![Askwatson.jpg](https://qiita-image-store.s3.amazonaws.com/0/170905/28c90fe7-d850-8326] in the upper right corner -3bca-59f4fd2cc1f9.jpeg) Click.
This will open a pane on the right that says ** Try it out **. This is a convenient tool that allows you to immediately execute and check the created Intent and Dialog, but when you look at it, it says ** Watson is training **.
This means that Watson is learning the Intent (example sentence) created earlier.
Wait a moment here. Learning will be completed in a few minutes at the earliest. When the ** Watson is training ** disappears, try entering the text immediately.
Enter ** "I want to take a room" **
Then, it became such a display.
Looking down, it says ** reserve_room **. This means that the sentence "I want to take a room" that I just entered was determined to be an Intent of ** # reserve_room **.
Now type ** "I want to cancel my reservation" **
This was determined to be ** # cancel_room **.
Then, enter ** "I want to cancel the room" **,
** I tried typing "I want to cancel the room, right?" **,
It was properly determined as ** # cancel_room **. As I mentioned last time, it is good that Watson absorbs and interprets the expression fluctuations of sentences even if they are not the registered example sentences.
Make a Dialog
Next, we will actually create the dialogue part.
Click the ** Dialog ** tab on the screen to display a screen like this. Click [Create].
This will automatically create two rectangles labeled ** Welcome ** and ** Other **. The part displayed by this rectangle is called a node.
(Previously nothing was automatically generated, but it is now generated with an update around May 2017)
You can open and close the node by clicking the "**> **" part.
Click on the part that says ** Welcome **.
![3-12.jpg](https://qiita-image-store.s3.amazonaws.com/0/170905/0a7e78b8-e22b-8b20-6c98-5ee9338a4f22.jpeg)
This will open the node's editor on the right.
![3-13.jpg](https://qiita-image-store.s3.amazonaws.com/0/170905/c9d5dee9-9c75-5d35-c132-6339258388cd.jpeg)
Edit here and rename ** Welcome ** to ** Start **. Also, welcome ** in Responses below. Hello ** a ** Please enter your business, is the River Sun Hotel. What are your requirements? Change to **. Now it looks like a hotel.
Next, open the ** Other ** node, change the node name to ** Other **, and erase the text entered by default in Responses. To erase it, click the (-) mark on the right side of the text.
And there is a new ** sorry. I didn't understand input.text?>. You can reserve or cancel your room. **Enter.
By the way, ** input.text ** surrounded by ** ** and **?> ** Means the text entered by the user. ** input ** is a reserved variable called a global built-in variable, but it's okay to understand that here. It will be explained separately.
Now let's try the dialogue once. Click ** Ask Watson **![Askwatson.jpg](https://qiita-image-store.s3.amazonaws.com/0/170905/28c90fe7-d850-8326-3bca-59f4fd2cc1f9.jpeg) on the upper right. I will.
The ** Try it out ** pane will open. Enter "I want to reserve a room" in the text entry space at the bottom.
Then, the intent "I want to reserve a room" is interpreted as ** # reserve_room **. However, since there is no node in this node that fires on the condition of ** # reserve_room **, it will transition to the ** anything_else ** node.
Now let's add a node that handles the room reservation intent ** # reserve_room **. Click the ** Welcome ** node and you will see (+) marks on the bottom and right.
Click the (+) mark at the bottom.
A new node will be added under the ** Welcome ** node.
At the same time, the node edit pane on the right opens, so edit this node.
The node name is ** Start_making_a_reservation **.
Next, if you enter ** # ** in the Trigger part, intent candidates will appear, so select ** # reserve_room **.
In Trigger, describe the conditional expression ** following the ** if statement.
Nodes are evaluated in order from the top, triggered by user input, etc., but if this conditional expression is met during evaluation, the processing of this node (returning a response, branching, etc.) is executed. ..
By the way, ** # reserve_room ** is an abbreviation for ** intent =='reserve_room'**. It's okay to write ** intent =='reserve_room' ** just like writing an if statement in programming.
Then edit Responses. This describes how this node responds when it is processed.
This node is the node that handles ** # reserve_room **. In other words, it is the process when the user says "I want to reserve a room", so let Watson respond ** "Reservation. I'm clever" **.
Multiple responses can be returned depending on the condition. For example, when you reserve a second room, you can change the response depending on whether you have already reserved one room or not.
Also, although the editor is designed to return text, it can also return more complex responses (JSON format objects). This will be explained separately.
Now that you have a ** Start_making_a_reservation ** node, ** Ask Watson **![Askwatson.jpg](https://qiita-image-store.s3.amazonaws.com/0/170905/28c90fe7-d850- Let's try it with 8326-3bca-59f4fd2cc1f9.jpeg).
When I entered ** "I want to reserve a room" **, the intent was determined to be ** # reserve_room **, and Watson responded properly ** "It's a reservation.
In addition to booking a room, be prepared to cancel.
Click the (+) mark to add a node.
The node name is ** Start_canceling_reservation **, the condition to put in Trigger is ** #cancel_room **, and Responses is "** We have accepted the cancellation of the room. We are waiting for you again * *"It was made.
Click ** Ask Watson **![Askwatson.jpg](https://qiita-image-store.s3.amazonaws.com/0/170905/28c90fe7-d850-8326-3bca-59f4fd2cc1f9.jpeg) in the upper right corner. Let's try the dialogue.
If you enter ** I want to cancel the room **, it will be recognized as ** #cancel_room **, and the response will be "We have accepted the cancellation of the room. We are waiting for you to use it again." As set in the node. had.
Up to this point, we have created a dialogue that accepts hotel room reservations and cancellations, but in response to user input, simply say ** Reserved **, ** Canceled **. , The dialogue is not yet ** interactive **.
When booking a hotel room, the user must at least specify ** when they want to stay **, so let's make it possible to specify ** accommodation date (date) **.
First, select the ** Start_making_a_reservation ** node and press the (-) mark to the right of the text ** "Reserved. I'm clever" ** in Responses to remove it.
Create Entity
Then click ** Entities ** on the top tab.
If you have not defined Entity yet, this screen will be displayed. Now select ** System entities **
System entities are special entities provided by Watson.
Set ** @ sys-date ** to ** on **. ** @ sys-date ** is an Entity that can detect dates, days of the week, etc.
For example, if today is June 5, 2017, then "tomorrow" will be interpreted as June 6, 2017, and "next Friday" will be interpreted as June 16, 2017. It's a smart Entity.
We will add nodes so that we can handle the accommodation date (date). ** Start_making_a_reservation ** Click the (+) mark to the right of the node.
Set the added node name to ** Reservation_date_specified **, and specify the system Entity ** @ sys-date ** in the conditional statement.
This condition means ** ”if the text entered by the user contains an Entity equivalent to @ sys-date **.
Responses
** entities ['sys-date'] ?. value.reformatDateTime ('yyyy year MM month dd day')?>. I made the reservation. Thank you very much! ** **
Enter the.
** ?> ** is messy, but ** ?> ** is the notation that tells Watson to calculate the notation sandwiched here.
The actual notation is ** entities ['sys-date'] ?. value.reformatDateTime ('yyyy year MM month dd day') **, but ** entities ['sys-date'] ** It means to take an entity (that is, date) called sys-date ** and format it in **'yyyy year MM month dd day ** format and display it.
Watson's backend seems to be running on Spring (Java Framework), and variables can be accessed and manipulated using SPEL (Spring Expression Language). The types of these variables and the data types that can be handled (some Java data types can be handled as they are) will be explained separately.
Click ** Ask Watson **![Askwatson.jpg](https://qiita-image-store.s3.amazonaws.com/0/170905/28c90fe7-d850-8326-3bca-59f4fd2cc1f9.jpeg) on the upper right. I will try the operation so far
Enter ** I want to reserve a room next Friday **. And, I didn't get any reply.
It is recognized as ** # reserve_room ** as intent and ** @ sys-date: 2017-06-16 ** as entity.
What this means is that the ** I want to reserve a room next Friday ** rating is stopped at the ** Start_making_a_reservation ** node.
** Stopped ** is actually ** waiting for user input **.
Here, when the intent of ** # reserve_room ** comes, how can I move to the next node, that is, ** Reservation_date_specified ** on the right side, without returning anything in the ** Start_making_a_reservation ** node? Is it?
In that case, use jump. As shown in the figure, ** Jump to **![Jump to.jpg](https://qiita-image-store.s3.amazonaws.com/0/170905/2e038441-2922-41ea-8525-3c8342da87d2.jpeg )Click.
** Jump to **![Jump to.jpg](https://qiita-image-store.s3.amazonaws.com/0/170905/2e038441-2922-41ea-8525-3c8342da87d2.jpeg) to another node This is a function for jumping. Even if you say jump to a node, you can choose from the following three where to jump in the node.
-
Condition
Jumps to the conditional statement (Trigger) of the node. The condition (for example, user input content) is inherited from the jump source and evaluated again at the node. To select ** Go to condition ** <img src = "https://qiita-image-store.s3.amazonaws.com/0/170905/b121a268-4ab6-f73d-6b60-714821770a3f.jpeg " width = Click "100px">.
-
Response
Jumps to the Responses of the node. Since the user input from the jump source is not evaluated, the node is processed from Response even if the condition is not met for that node. To select, ** Go to response ** .
-** User input **
Jumps to ** waiting for user input ** after the node is executed instead of the node. To select, a balloon icon is drawn in 〇 ** User input **![Uinput.jpg](https://qiita-image-store.s3.amazonaws.com/0/170905/b0a1667e- 1421-0eef-95bc-584a6de224b6.jpeg) Click.
Here, select ** Go to condition **.
This is because we want to determine ** whether the accommodation date is specified ** in the text entered by the user.
So far, let's take a step-by-step process when the user says ** "I want to reserve a room next Friday" **
(1) First, it matches the ** Start_making_a_reservation ** node condition ** # reserve_room **.
(2) Since the jump destination is specified in the ** Start_making_a_reservation ** node, next, jump to the Trigger (Condition) of the ** Reservation_date_specified ** node.
(3) Trigger of the ** Reservation_date_specified ** node of the jump destination will evaluate ** "I want to reserve a room next Friday" ** again.
(4) Since the Entity ** Next Friday ** is included, it will be processed by the ** Reservation_date_specified ** node, and the Response of the ** Reservation_date_specified ** node will be displayed.
Actually using ** Ask Watson **![Askwatson.jpg](https://qiita-image-store.s3.amazonaws.com/0/170905/28c90fe7-d850-8326-3bca-59f4fd2cc1f9.jpeg) I'll give it a try.
Enter ** I want to reserve a room next Friday **
Then, ** "It's June 16, 2017. I made a reservation. Thank you." ** I got a response, so it seems that it is working well. The input ** next Friday ** was also interpreted as ** June 16, 2017 **. It's smart.
Then click the (+) mark under ** Reservation_date_specified **.
What I want to do with this node is what to do if the user makes a reservation request ** without specifying a date and time.
For example, you might be told to "book a room".
Enter ** anything_else ** in Trigger with the node name ** Else **.
If the user did not specify a date and time, then Responses will be ** when will you be staying? (Example: April 29th, tomorrow, next Saturday) ** and a sentence prompting the accommodation date.
Then click ** Jump to **![Jump to.jpg](https://qiita-image-store.s3.amazonaws.com/0/170905/2e038441-2922-41ea-8525-3c8342da87d2.jpeg) I will.
Select ** User input ** as the jump destination.
This is ** when will you stay? (Example: April 29th, tomorrow, next Saturday) ** This is to accept user input again after displaying **.
By jumping here, the evaluation will start from the ** Reservation_date_specified ** node as the user types. Now, if the user says a date like ** next Friday **, the ** Reservation_date_specified ** node will be processed, and if it's completely different, the ** Else ** node will process it again. Will be done.
Try again ** Ask Watson **![Askwatson.jpg](https://qiita-image-store.s3.amazonaws.com/0/170905/28c90fe7-d850-8326-3bca-59f4fd2cc1f9.jpeg) to watch
Enter ** I want to reserve a room **
Then, I could recognize it as ** # reserve_room , but since ** accommodation date ** is not entered, it transitions to the ** Else ** node as designed and ** "When will you stay?" ? ... " is returned.
A detailed look at how the node transitioned with this input is as follows (see the figure below).
-① User says ** "I want to reserve a room" ** (enter)
-② Watson determined that the text was ** # reserve_room , so it matches the conditions of the ** Start_making_a_reservation ** node and this node is executed.
-③ Jump from the ** Start_making_a_reservation ** node to the ** Trigger ** of the ** Reservation_data_specified ** node. Since it does not match the conditions of Trigger ( @ sys-date ** does not exist), the process moves to the node ** Else ** below.
-④ ** Else ** node is executed and ** "When will you stay?" ** is output.
-⑤ After processing the ** Else ** node, jump to user input. Here, it waits for user input.
Now enter ** next Friday **
Then the node transitions and executes as follows
-⑥ The user says ** "Next Friday" ** (enters)
-⑦ ** "Next Friday" ** is judged as Entity ** @ sys-date , ** Reservation_data_specified ** node is executed, ** "It is June 16, 2017. Reservation. Thank you. ” is displayed.
By the way, we have realized the following exchanges.
** User "I want to reserve a room" **
** Watson "When are you going to stay?" **
** User "Next Friday" **
** Watson "It's June 16, 2017. I made a reservation." **
Basically, more complicated dialogue can be realized by preparing Intent and Entity and combining nodes.
Summary
This time, we took a closer look at node transitions using a simple ** hotel reservation service ** as an example. Next time, we will take a closer look at Conetxt and built-in variables that are indispensable for interactive design.
The continuation is here.
** Let's go with Watson Conversation ③ Hotel reservation chatbot utilizing Context **
download
The dialogue data (JSON) created in this article can be downloaded from the following.
You can do this by importing it from the Watson Conversation editor.
https://github.com/riversun/watson_q02/blob/master/wcs_hotelreservation.json