Data Manipulation Functions in Luma
Luma provides a set of pre-defined functions that enable Administrator/Developer to parse, process and modify user text response or JSON response received by the system. The modified response can be used to configure payload to execute an action/skill.
These functions are available in ‘Skill builder’ module and can be invoked by typing ‘@fn.’ on Text Response field on ‘Skill Builder’ screen.
Below are the available functions:
Split
Substring
Replace
Random number
Split function
‘Split’ function can be used to split a text or JSON response into smaller strings while building a skill. On ‘Skill Builder’ page- Text Responses section, use @fn.split function to split a string in an attribute at a specified position.
Function | Syntax | Example | Result |
---|---|---|---|
Split() | @fn.split(' '.split(' ')) | Consider @context.Email_Address holds 'John@test.com', then: @fn.split('@context.Email_Address'.split('@')[0]) | John |
In the above example, ‘John@test.com'. The string is split at the character ‘@’ starting from location ‘[0]’, which is the start of the string. The result string is 'John’.
Substring function
‘Substring’ function extracts characters from a text string to create another string. The function selects characters between specified locations and returns the same as a new string. On ‘Skill Builder’ page- Text Responses section, use @fn.substring function to select a substring from an attribute value.
Function | Syntax | Example | Result |
---|---|---|---|
Substring | @fn.substring(' '.substring( , )) | Consider @context.OrgName holds 'Serviceaide', then: @fn.substring('@context.OrgName'.substring(0,'@context.OrgName'.length()-4)) | Service |
In the above example, ‘Serviceaide'. Substring is selected starting at location ‘[0]’ till character at location [7] (i.e. string length (11)-4 ). The result is 'Service'
Replace function
‘Replace’ function replaces characters specified by location in a given text string with another text string. On ‘Skill Builder’ page- Text Responses section, use @fn.replace function to replace a part of the text response with another string. Note that the function does an exact match and is case sensitive.
Function | Syntax | Example | Result |
---|---|---|---|
Replace | @fn.replace(' '.replace(' ',' ')) | Consider @context.Email_Address holds 'John@test.com', then: @fn.replace('@context.Email_Address'.replace('test','serviceaide')) |
In the above example, ‘John@test.com', string ‘test’ will be replaced by 'serviceaide'. The result is 'John@serviceaide.com'
Random Number
RandomNumber function generates a 4-digit random number that can be saved in an attribute for later action while building skills. Random numbers are mostly used for user authentication and verification. For example, OTP generation used for user authentication.
On Skill Builder page- Text Responses section, use @fn.randomNumber function to generate a 4 digit random number.
Function | Syntax | Example | Result |
---|---|---|---|
randomNumber | @fn.randomNumber | @fn.randomNumber | 3463 |
Â
© 2019 Serviceaide 1-650-206-8988 http://www.serviceaide.com info@serviceaide.com