-
Notifications
You must be signed in to change notification settings - Fork 39
reactions
Reactions is a main interface for building the response that should be sent back to the user.
It also contains functions for dialogue state managing.
That is why this abstraction has been named Reactions
- it provides a ways to react somehow on the request from the user.
Each channel in JAICF creates it's own channel-related Reactions implementation and provides it through the ActionContext to the action block of the scenario. Once the state is activated, JAICF executes it's action block in context of this object, thus reactions interface becomes available for response building and dialogue state managing. Here is a simple example:
state("fallback", noContext = true) {
activators {
catchAll()
}
action {
reactions.say("I have nothing to say yet...")
reactions.actions?.run {
say("Bye bye!")
endConversation()
}
}
}
Here you can see how reactions
is used.
Once a "fallback" state is activated, JAICF executes it's action block.
Reactions instance contains say
method to send a raw text in the response to the user.
Channel that received a request and created this
Reactions
is responsive for this function invocation handling.
Each Reactions
instance contains functions that help to build a response(s).
say
method just appends a raw text reply to the response.
There is also sayRandom
variation of this method that picks a random text to append to response.
image
method appends an image URL to the response.
Please note that not every channel supports this type of reply.
buttons
method appends buttons array to the response.
Please note that not every channel supports this type of reply.
You can also notice how channel-related reactions can be used.
In the example above there is a null-safe invocation of reactions.actions?
that works only in case the request was received by Google Actions channel. In this case a channel-related reactions become available - like Actions-related endConversation
function that finishes the Actions execution on a Google Assistant's side.
To learn what channel-related functions are available, please look into a corresponding channel's Reactions implementation. For example there are ActionsReactions for Google Actions, AlexaReactions for Alexa and etc.
Also it is important to know that you can extend any channel-related Reactions
if it doesn't contain methods you need. Because each Reactions
holds a native response builder - thus you can use it directly.