public interface ConversationData
This interface must be implemented by clients that wish to provide external data to Spokestack's dialogue manager.
"External data" here means any data not available from the user's voice interactions with the app; in other words, account data, or data produced or retrieved by a user action. Anything data required by the dialogue but not explicitly provided by the user should be available via a key-based lookup against a class that implements this interface.
If an implementer of this interface is provided to Spokestack's dialogue
manager, Spokestack will use its set
method to store conversational
data. No persistence is performed by the dialogue manager, so any data
intended to be long-lived must be persisted by the app.
Note that this API stores objects but expects to retrieve strings via getFormatted(String, Format)
. This is to allow clients to store any type of
data they wish but provide their own formatting for how custom objects should
be read to the user in a synthesized response or printed in a chat stream.
A get(String)
method is also included, but this is only used to
serialize dialogue policy state for cross-session persistence, so its
implementation may return null
if such persistence is not needed.
Modifier and Type | Interface and Description |
---|---|
static class |
ConversationData.Format
A simple enum that expresses the eventual use of retrieved conversation
data.
|
Modifier and Type | Method and Description |
---|---|
Object |
get(String key)
Get the raw object stored at
key . |
String |
getFormatted(String key,
ConversationData.Format mode)
Get a version of the data stored at
key suitable for inserting
into the conversation. |
void |
set(String key,
Object value)
Store an object under the specified key.
|
void set(String key, Object value)
Store an object under the specified key.
Note that since this API is used by Spokestack to store data provided by
the user during voice interactions, key
should not begin with an
underscore (_
) unless intentionally overriding a key set by the
dialogue manager.
key
- The key under which value
will be available.value
- Data to store for use by the conversation.Object get(String key)
key
. This method is only used by
the dialogue system during DialoguePolicy.dump(ConversationData)
to retrieve original slot values for use in cross-session persistence.key
- The key whose original object should be returned.key
, or null
if key
is not found in the data.String getFormatted(String key, ConversationData.Format mode)
Get a version of the data stored at key
suitable for inserting
into the conversation.
Full objects are stored by the API, but the dialogue manager needs
formatted strings to use for prompts. The simplest implementation is to
call Object.toString()
on the stored object, but custom
formatting logic can be supplied as needed.
Occasionally an object (for example, a date) might require different formatting for use in a synthesized voice response than for use in a text-based interface, so a formatting mode is also required.
key
- The key of the data to be retrieved.mode
- The data's destination, either text or voice.key
suitable for use in
the specified medium.Copyright © 2021. All rights reserved.