Functions
Yola Functions are built-in utility functions that allow you to dynamically manipulate and process data within the platform. These functions can interact with system variables, API responses, and user inputs to enhance chatbot workflows.
Using Functions in Bot Actions
Functions are applied differently depending on the bot action:
Bot Actions That Require Delimiters e.g.{_customer.id}
{_customer.id}
For these bot actions, you must enclose the function in curly braces {}
:
Bot Message
Carousel
Create Case
Email
Hyperlink
Survey
Bot Actions That Do Not Require Delimiters e.g.{_customer.id}
{_customer.id}
For these bot actions, functions are inserted directly into the input fields. These input boxes are identified by the </> ProtoScript
label at the bottom:
Branch (e.g. for POST when a JSON input is required)
JSON API
Modify Variable
You can combine functions with system variables, refer to the Variables Documentation to see what data can be accessed.
Function Reference Guide
The following table lists the utility functions available in Yola, grouped by their purpose:
String Manipulation Functions
Function
Description
Example
Output
_.upper(string)
Converts a string to uppercase.
_.upper("hello")
"HELLO"
_.lower(string)
Converts a string to lowercase.
_.lower("WORLD")
"world"
_.replace(text, old, new)
Replaces occurrences of a string with another.
_.replace("hi world", "world", "Yola")
"hi Yola"
_.split(string, separator)
Splits a string into a list based on a specified separator.
_.split("apple,banana", ",")
['apple', 'banana']
_.join(separator, list)
Joins list items into a string using the specified separator.
_.join(", ", ["a", "b", "c"])
"a, b, c"
_.fmt(string, value)
Formats text by inserting specified values into placeholders.
_.fmt("Hello, %s!", "Yola")
"Hello, Yola!"
Date and Time Functions
Function
Description
Example
Output
_.now(timezone, format)
Gets the current date/time in UTC or specified timezone, with optional format.
_.now('Asia/Manila', '%Y-%m-%d %H:%M:%S')
2024-04-15 10:30:00
_.dt_diff(dt1, dt2, unit)
Calculates the difference between two datetime objects in specified units.
_.dt_diff(dt1, dt2, "h")
24
_.format_time(datetime, format, timezone)
Formats a datetime object based on a custom format.
_.format_time(_.now(), "%Y-%m-%d", "UTC")
"2024-04-15"
JSON and Data Functions
Function
Description
Example
Output
_.json_parse(data)
Converts a JSON string to a Python-like dictionary.
_.json_parse('{"name": "Alice"}')
{'name': 'Alice'}
_.json_stringify(data)
Converts a Python-like object to a JSON string.
_.json_stringify({"name": "John"})
'{"name": "John"}'
_.get(dictionary, path)
Retrieves a value from a nested dictionary using a specific path.
_.get({"a": {"b": 1}}, "a.b")
1
_.map_get(list[dict], path)
Extracts a specified value from each dictionary in a list.
_.map_get([{"a": 1}, {"a": 2}], "a")
[1, 2]
Numeric and Utility Functions
Function
Description
Example
Output
_.len(item)
Returns the length of a string, list, or object.
_.len("hello")
5
_.random_num(min, max)
Generates a random integer between two values.
_.random_num(1, 10)
7
(example)
_.random_choice(list)
Returns a random element from a list.
_.random_choice(["red", "blue"])
"blue"
(example)
Best Practices
Use Delimiters When Required In actions like Bot Message, enclose variables and functions within
{}
to ensure proper execution.Example:
Leverage JSON Functions for Complex APIs Use
_.json_parse
and_.json_stringify
to work with API responses and complex data structures.Keep Your Data Clean Combine functions like
_.replace
,_.split
, and_.join
to format data before sending it to users or saving it.
Last updated