Can be set to jump the iteration to a formation GUID on the next iterator pump
Retrieves cache that is being used to retrieve the messages
Sets cache that is being used to retrieve the messages
The current formation discourse.
The features of the formation. This is pulled from the metadata
Retrieves the ID that is currently being processed
The current formation link. This can be used to determine what the next formation will be.
It is highly likely you will need to use redirect
as well
undefined
when the current formation is not known
The formation metadata. This can be used to determine extra information about the formation. Of particular note
are the features
.
Retrieves options to use when processing the links
Set options to use when processing the links
This is the current redirection state of the walker. This is used to ignore the link target and go straight to
this GUID. This can be used with link
to determine which formation will be walked to.
The formation tags. Can be used to determine formation metadata
Performs classification of a users response.
the input that the user provided
the classification targets to match the user input against
an iterator that returns a stream of target matches with a confidence level
Override this to provide conversion of non-string data types into inputs. This will populate the suggestions
the data that is provided as a suggested input
a constructed input interface
Derived classes can implement this function to process expected discourse interactions. Usually this will keep yielding a message until the expected answer is given. This base implementation is really dumb:
Data
into IInputImmutable
and there is no need to require everybody to implement that interface.
It does provide the answer when Data
is a string
, though, to help out the demo application.this.locale
.context.response
with the results of the classification using the standard classifySet
an interaction with the user that requires an expected response
yields chat bot message data
Maps the suggestions from the data type to the canonical user input classes. Can be used as a hook to modify the returned suggestions from the formation
the suggestions provided by the formation
the conversion function to use to convert the suggestions. Will usually be
this.convertSuggestion
or but can be built in conversion functions if Data
is a known type
the mapped suggestions to the input interfaces
Performs the processing of a conversation discourse piece
Derived classes can implement this function to process statements. Usually this just forwards on the
conversation discourse statement, verbatim. The processing function can update the local conversation context at
this.context
protected async *statement(discourse: IDiscourseStatementImmutable<Data>): IAsyncIterableIteratorStatement<Data> {
this.context.statements = this.context.hasOwnProperty('statements') ? ++this.context.statements : 1;
yield { data: discourse.statement };
}
a statement to show to the user
yields chat bot message data
The conversation generator can walk a formation tree and yield chat bot messages. It provides an event emitter interface to easily hook into the walking of the tree.
The events are generated in the following lifecycle of a formation:
+------+ +----> pump <-----------------------+ | +--+---+ | | | | | ...v.... | | | walk | | | '''+'''' | | | | | +--v---+ | | | step +---+ | | +--+---+ | | | | | | | | +---v--+ | | | +-+ jump | | | | | +------+ | | | | | | +---v-v---+ | | | process +---+ | | +----+-+--+ | | | | | | | | +----v----+ | | | +-+ feature | | | | | +---------+ | | | | | | +-----v-v---+ | | | statement +-+ | | +-----+-----+ | | | | | | | ....v.... | | +----+ yield | | | ''''+'''' | | | | | | +----v-----+ | | | expected | | | +----+-----+ | | | | | +--v---+ | | | hint +-----+ | | +--+---+ | | | | | | | | +-----v------+ | | | +-+ suggestion | | | | | +------------+ | | | | | | +--v-v--+ | | | input | | | +---+---+ | | | | | ....v.... | | + yield | | | ''''''''' | | | | | +----v-----+ | | | classify +-----------+ | +----+-----+ | | +---v--+ | | done <-----+ +------+
The events, surrounded in boxes are:
pump
- the iterator has been pumped but the underlying formation walker has not yet updated all the propertieson the generator such as `id`, `link`, etc. <a href="../interfaces/_lib_event_payload_ipump_.ieventpayloadpumpimmutable.html">IEventPayloadPumpImmutable</a>
step
- the underlying walker has moved to the next formation, the properties on the generator will haveupdated such as `id`, `link`, etc. <a href="../interfaces/_lib_event_payload_istep_.ieventpayloadstepimmutable.html">IEventPayloadStepImmutable</a>
jump
- if the generator has had thejump
property set, this event will be raised. Thejump
property allowsthe generator to ignore the formation link ID and move to the specified jump ID. <a href="../interfaces/_lib_event_payload_ijump_.ieventpayloadjumpimmutable.html">IEventPayloadJumpImmutable</a>
process
- when a formation discourse is processed. IEventPayloadProcessImmutablefeature
- the formation has attached features in the metadata. The event will be emitted for each feature andthe corresponding feature metadata will be provided. <a href="../interfaces/_lib_event_payload_ifeature_.ieventpayloadfeatureimmutable.html">IEventPayloadFeatureImmutable</a>
statement
- the formation discourse is aIDiscourseStatement
. Statements are yielded as a non-interactivechat message. <a href="../interfaces/_lib_event_payload_istatement_.ieventpayloadstatementimmutable.html">IEventPayloadStatementImmutable</a>
expected
- an expected discourse which creates an interactive experience with the user. The user will beprompted for a response. <a href="../interfaces/_lib_event_payload_iexpected_.ieventpayloadexpectedimmutable.html">IEventPayloadExpectedImmutable</a>
hint
- the response required for anexpected
formation can hint at when type of input is required.<a href="../interfaces/_lib_event_payload_ihint_.ieventpayloadhintimmutable.html">IEventPayloadHintImmutable</a>
suggestions
- the expected formation can provide a set of suggested inputs to avoid the user having to type aresponse. If there are no suggestions provided the event will not raise. <a href="../interfaces/_lib_event_payload_isuggestions_.ieventpayloadsuggestionsimmutable.html">IEventPayloadSuggestionsImmutable</a>
input
- the user has provide a response to the expected discourse. IEventPayloadInputImmutableclassify
- The input has been classified against the expected answers. IEventPayloadExpectedImmutabledone
- the generator has completed walking the formation. IEventPayloadDoneImmutable