Context handler function

Context handler function


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.

Input Arguments

In addition to the system defined input arguments, the following input arguments are also available for the Context handler 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.
  1. 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.
    1. prompt — instructs Zia to prompt a param from the user.
    2. confirm — instructs Zia to ask for a final confirmation for invoking the execution function of the action.
    3. execute — instructs Zia to invoke the action execution function.
  2. 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.
    1. param_name * — The name of the param to be prompted. The param name should be one of the declared static or dynamic params.
    2. options — Options to be displayed as suggestions to the param. This is applicable only to the array type params.
    3. msg — Used to momentarily override the default prompt message of the param.
  3. 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.
    1. message — The confirmation message that should be prompted to the user.
  4. 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.
    • Related Articles

    • Action Execution function

      The Execution function is the endpoint to an action execution. It defines the fulfillment of an action. This does the actual execution of the action and gives a final success (or failure) message to the user, as a result of the completion of an ...
    • Fallback Function

      When a bot receives an input message that it couldn't understand, it would reply with a "Sorry, I can't understand" message. If you wish to customize this default response message to give a reply of your own, you can customize that with Fallback ...
    • Trigger Function

      Zoho Survey is integrated with Deluge, our online scripting language, which can help you add functions to automatically perform actions when responses are submitted. Use Deluge and APIs to create connections and push data to third-party services or ...
    • Insert a function

      To insert a formula 1. Click Insert > Function. 2. Alternatively, you can select a cell, click on the Function icon on the side panel, and choose the function you'd like to add in the selected cell.3. Enter the addresses of the required cells to be ...
    • Custom Function: Create_Job

      This custom function can be used to create a new job in any layout. It can also be configured to carry forward necessary field values from the former job to the latter.   Business Scenario Helen is the head of Procurement Management in her ...