public class RuleBasedDialoguePolicy extends Object implements DialoguePolicy
This policy loads a dialogue configuration from a JSON file and determines transitions for the app based on the rules and scenes referenced in that file.
See the online documentation for more information on the Spokestack dialogue format.
This dialogue policy employs two-step processing of user requests to allow
apps to retrieve or operate on external data before completing a user turn.
It will fire ACTION
events to registered
dialogue event listeners when an app feature is triggered. When all
operations on external data are complete and data relevant to the action has
been made accessible via the current data store
, the
app should call completeTurn()
on the dialogue manager in use so that any follow-up navigation/prompts can
occur.
This component supports the following configuration properties:
Constructor and Description |
---|
RuleBasedDialoguePolicy(SpeechConfig config)
Creates a dialogue policy from the supplied configuration.
|
Modifier and Type | Method and Description |
---|---|
void |
completeTurn(boolean success,
ConversationData conversationData,
DialogueDispatcher eventDispatcher)
Complete the pending user turn.
|
String |
dump(ConversationData conversationData)
Store the internal state of the dialogue policy in the specified data
store for cross-session persistence.
|
void |
handleTurn(NLUResult nluResult,
ConversationData conversationData,
DialogueDispatcher eventDispatcher)
Process a user turn and return a relevant response.
|
void |
load(String state,
ConversationData conversationData)
Load previously serialized internal state.
|
public RuleBasedDialoguePolicy(SpeechConfig config) throws IOException, com.google.gson.stream.MalformedJsonException
config
- Configuration containing the path to a policy file.IOException
- if there is an error reading the policy
file.com.google.gson.stream.MalformedJsonException
- if the policy file contains invalid JSON.public String dump(ConversationData conversationData)
DialoguePolicy
dump
in interface DialoguePolicy
conversationData
- The data store where policy state should be
saved.public void load(String state, ConversationData conversationData)
DialoguePolicy
load
in interface DialoguePolicy
state
- Policy state serialized using dump()
.conversationData
- The data store where any relevant policy state
should be loaded.public void completeTurn(boolean success, ConversationData conversationData, DialogueDispatcher eventDispatcher)
DialoguePolicy
This method should be called after any actions or data retrieval pending in the app are completed.
completeTurn
in interface DialoguePolicy
success
- true
if the user's request/desired action
was fulfilled successfully; false
otherwise.conversationData
- Conversation data used to resolve and prepare a
response.eventDispatcher
- Dispatcher used to notify listeners of dialoguepublic void handleTurn(NLUResult nluResult, ConversationData conversationData, DialogueDispatcher eventDispatcher)
DialoguePolicy
handleTurn
in interface DialoguePolicy
nluResult
- The user input as determined by the NLU
component.conversationData
- Conversation data used to resolve and prepare a
response.eventDispatcher
- Dispatcher used to notify listeners of dialogue
events.Copyright © 2021. All rights reserved.