Context handler function is used to control the conversational flow of an action. You can change the order in which the params are prompted to the users in the runtime. You can also skip some params, do custom validations of the param values and ask for a confirmation before action execution in the runtime.
Please note that, the context handler function can override the order in which the static params are defined. If the context handler function is enabled, Zia will prompt the parameters in the order as dictated by the context handler function and not by the order you have declared while defining the params.
Invocation Point
Once Zia detects the action of the user input, the possible param values that are present in the user input will be detected; then, Zia will prompt the first missing param to the user. When a user replies to the param prompt, Zia will invoke the context handler function. Hence, context handler function is invoked for every param that is prompted in the conversation. If an action doesn’t have any params at all, the context handler function will be executed once before the execution function.
Argument
| Deluge data type
| Description
|
userInput
| String
| Latest reply from user.
|
previousParam
| Map
| The param that is last prompted to the user. The user reply has been made as a value to this param.
|
Return Value
Context handler function must return a Map that should be in the following format.
{
"todo" : "prompt",
"prompt" :
{
"param_name" : "deal_stage",
"options":
[
{
"id" : "111",
"label" : " "
},
{
"id" : "112",
"label" :" "
}
],
"msg" : "You don't have enough casual leaves. Please choose some other leave type."
},
"confirm" :
{
"message" : "Are you sure to apply leave for next Monday?"
},
"assign" :
{
"name" : "something",
"date" : "somedate",
"cache" : " "
}
}
The following are the keys that can be present in the map that would be returned from the Context handler function.
- todo (mandatory) — Used to indicate what Zia should do next after completing the context handler function. It can take one of the following values only.
- prompt — instructs Zia to prompt a param from the user.
- confirm — instructs Zia to ask for a final confirmation for invoking the execution function of the action.
- execute — instructs Zia to invoke the action execution function.
- prompt (mandatory, only if “todo” is set as “prompt”) — Contains a map that specifies what param is to be prompted to the user. If this key is not provided even if “todo” is set as “prompt”, Zia will prompt the next param as per the order of the param definition. So this key can be skipped if we will have to use the default order of params definition. The map value can contain the following keys.
- param_name * — The name of the param to be prompted. The param name should be one of the declared static or dynamic params.
- options — Options to be displayed as suggestions to the param. This is applicable only to the array type params.
- msg — Used to momentarily override the default prompt message of the param.
- confirm (mandatory only if “todo” is set as “confirm”) — Contains a map that specifies the confirmation message for action execution that should be prompted to the user. The map value can contain only the following key.
- message — The confirmation message that should be prompted to the user.
- assign — The value of this key should be a map. This key is used to change the values to any of the mutable input arguments of the function. All the static params and the system defined argument “cache” are mutable.