Events are optional outputs of functions. A function may emit any one of a set of declared events. These events then
cause state changes in the Flow, giving Grace new thoughts as the conversation progresses.
You can create a function by clicking the “Create” button in the top right of the Functions page.This will bring up the create function page.Here you can configure your function, giving it a name, description, a set of inputs, declaring the outputs, and writing
the javascript code that will be executed when the function is called.
Parameters are inputs that are passed in from Grace. For example, if you have a “search customer” function, you could pass
in a customer name as a parameter.
Internal parameters are parameters that come from the context of the conversation. These may have been set by a previous
function or may be a property of the current conversation.
These are a set of key/value pairs that will be added to the context of the conversation. These can be used to store
information that will be used by other functions, but does not need to be seen by Grace.It’s highly advised you list all the potential context addition keys under “Emitted Context Additions” so that the UI
can offer smart suggestions. A warning will be emitted if a function adds context that is not declared.
Finally, events are what drive changes in state in a flow. A function may emit zero or one events.It’s highly advised you list all the potential events under “Emitted Events” so that the UI can offer smart suggestions.
A warning will be emitted if a function emits an event that is not declared.
The source code is the JavaScript code that will be executed when the function is called. There is a full reference of
all the available helpers in the app under the info icon.
Functions can be called directly by Grace, called automatically at the conversation’s start, or called automatically at
the conversation’s end.In order for Grace to use a function, the flow must have visited a state where that function was available.
Functions remain available even after the conversation state has changed.
You can add a function to a state by selecting the state, going to the “Functions” tab, and adding the desired function
to the state.
Not all functions need to “do things”, sometimes it’s useful to have a function that emits an event that causes
the conversation to enter a new stateFor example, if there are complex rules around billing, you probably do not want to include all that logic in the initial
state. Instead one should have a function called “start billing process” that emits an event that causes the conversation to
enter the new state with detailed billing instructions.