Defining Deluge Functions

Defining Deluge Functions


Functions are custom hooks written by action developers that are invoked by Zia at various points during an action's execution. The conversational flow and the execution of an action are determined by the functions defined for that action. 

The following are the functions provided as hooks during the execution of an action. 
  1. Execution Function
  2. Context Handler Function
These functions will be invoked at their respective invocation points. 

All functions must be written in Deluge, the native online scripting language of the Zoho cloud environment. 

Input arguments 

The following system defined input arguments are available for all the functions.

Argument
Deluge Data Type
Description
user 
Map
Contains the details of the user who is interacting with the bot. 
org
Map
Contains the details of the organization in Zia Skills that the interacting user belongs to.
sessionData 
Map
Contains the details of the client that is hosting the current chat session. 
cache
Map
A temporary storage variable which is used to pass data across functions along the action execution cycle.
broadcast
Map
A storage variable which is used to pass data across different actions, as the user is interacting with the bot. 

In addition to the system defined arguments listed above, all the static params defined for the action will also be available as input arguments individually for every function. 

Zia will populate apt values for all the variables and will pass on as input arguments for all the functions.


Session Data

The current chat session details of the client will be stored in the bot's context and these data will be available in all functions under the 'sessionDataargument. This argument consists of the following keys.

Key Name
Possible Values
Description
 id 
 a unique id of current session

 A unique id (session id) is assigned to every session.

 medium

 'call' or 'chat'.

 The mode of communication through which the user interacts with the bot.

 client_host

 'mobile' or 'web'

 The nature of client application that hosts the bot.

 client_host_type
  1. The name of the mobile operating system, if  'client_host' is 'mobile'.
  1. The name of the web browser, if 'client_host' is 'web'.

 The specific environment in which the client_host runs.

 client_identifier
  1. The URL of the client web application, if  'client_identifier' is 'web'.
  1. The package name / bundle identifier of the mobile applicationif 'client_identifier' is 'mobile'.

 A unique identifier of the client.


The following is a sample value of the 'sessionData' argument.
"sessionData" : {
                              "id" : "1579635239811",
                              "medium" : "chat",
                              "client_host" : "web",
                              "client_host_type" : "Firefox 72",
                              "client_identifier" : "https://zylker.com/"
                              }


Broadcast 

If you wish your bot to remember any information related to the currently executing action, the information can be set as a map value to 'broadcast' key. This value gets retained even after the execution of the current action and will be available for all subsequent actions until the current chat session is over. Subsequent actions can use this value, as required by their business logic.

The following is a sample value of the 'broadcast' argument.
"broadcast" : {
                           "user_level" : "admin", 
                           "status" : "booked"
                        }


Return value 

Each function has its own specification of return data. Please note that it is the developer’s responsibility to fulfill the return data contract of every function for the proper functioning of your action.


Function Validations

The code that you write to define the functions would be validated by Zia Skills for syntax and return value correctness.

Syntax validation happens whenever a function is attempted to be saved. If the syntax validation fails due to any compile time errors, the function will not be saved and an apt error message would be displayed. Compile time errors includes incorrect syntax, punctuation, missing variable initialization etc.



In addition to the above syntax validations, the return values of the functions will also be validated for every function execution. You can use the sample chat window to test the functions and view the results of the return value validations in the error window.

If the function's return value violates the contract specified for the function, an apt error message with the JSON element that commits the error will be displayed in the error window.



Please note, not only the errors committed in that current function in display will be shown in its error window, but the errors which are caused by other functions in the flow of the action will also be displayed here.

    • Related Articles

    • Functions

      Functions are the building blocks for developing an extension. They come handy for all server side customization. Sigma executes functions without additional infrastructure cost. External function calls can be done using rest APIs. You have to ...
    • Functions

      Set Up Functions   You can set up functions in six places: Create a standalone function. Associate function to a workflow rule. Use functions later by including them in Schedules. Set the function to get executed upon the click of a Custom Button. ...
    • Defining an Action

      Adding a new Action To add a new action to a bot, follow the steps as given below.  In the bot's detail page, under the ACTIONS tab, click the + ADD ACTION option. The Create New Action page appears. Give a meaningful name for the action. Based on ...
    • Custom Functions

      The Manage Business icon in the top menu bar is your go-to for managing all of your booking preferences. This page discusses Custom Functions. Aside from the default flow of a customer booking, you can define additional workflows at each stage of the ...
    • Custom Functions

      Super admins and admins can view and edit this information. Managers can only view this information. Staff members will not have access to this information. Custom functions help with automating actions that require procedural logic and that cannot ...