This tutorial introduces sessions, how they are handled and Conversation Learner's onSessionStart and onSessionEnd callbacks.
This tutorial requires that the "tutorialSessionCallbacks" bot is running.
npm run tutorial-session-callbacks
This tutorial covers the concept of a session, how sessions are handled by default, and how you can override that behavior.
In Conversation Learner a session represents one, uninterrupted interactive exchange with the bot. Sessions can have multiple turns, but be programmatically ended due to inactivity if greater than thirty minutes has lapsed. See the help page on "Limits" for information on changing this default session timeout duration.
This long period of inactivity will cause the bot to create a new session and reset the recurrent neural network to its initial state. By default all entity values will be cleared. This default behavior of clearing entity values can be changed as seen below.
In the web UI, click on "Import Tutorials" and select the model named "Tutorial-13-SessionCallbacks".
Sample code for this Model's two callbacks can be found in: c:\<installedpath>\src\demos\tutorialSessionCallbacks.ts
.
- OnSessionStartCallback: this method sets the BotName entity.
- OnSessionEndCallback: you can specify what you want to preserve. This will clear all entities except user name and user phone.
Each callback is optional.
Four Actions are defined in the Model. The existing Actions are displayed in the grid view for "Actions"
- On the left panel, click "Actions", then the "New Action" button.
- Select "ENDSESSION" for the "Entity Type."
- In the "Data..." field, type "Done"
- Click the "Create" button.
- Select the "So, $UserName, you are in $UserLocation" Action from the grid view.
- Un-check the "Wait for Response" check-box.
- Click the "Save" button.
- On the left panel, click "Train Dialogs", then the "New Train Dialog" button.
- In the chat panel, where it says "Type your message...", type in "hi."
- Click the "Score Actions" button.
- Select the response, "Hi, I'm Botty. What's your name?"
- In the chat panel, where it says "Type your message...", type in "Lars"
- Select the response, "Hi Lars. What is your phone number?"
- In the chat panel, where it says "Type your message...", type in "555-555-5555"
- Click the "Score Actions" button.
- Select the response, "Can you tell Botty your location, Lars?"
- In the chat panel, where it says "Type your message...", type in "Seattle"
- Click the "Score Actions" button.
- Select the response, "So, Lars, you are in Seattle"
- Select the response, "Done"
- Click the "Save" button.
- On the left panel, click "Log Dialogs", then the "New Log Dialog" button.
- In the chat panel, where it says "Type your message...", type in "hi"
- In the chat panel, where it says "Type your message...", type in "Lars"
- In the chat panel, where it says "Type your message...", type in "555-555-5555"
- In the chat panel, where it says "Type your message...", type in "Seattle"
- At this point all entity values excluding location should have been preserved.
- In the chat panel, where it says "Type your message...", type in "hello"
- In the chat panel, where it says "Type your message...", type in "Detroit"
- Click the "Session Timeout" button.
- Clicking this button exercises the bot's response to long periods of inactivity
- Click the "OK" button.
- Click the "Done Testing" button.
[!div class="nextstepaction"] API calls