Proto AICX Docs
  • Getting Started
    • Glossary
    • Signing-in
    • Main Dashboard
    • Proto AI
    • Data Privacy
  • AICX Modules
    • AI Agents
      • Manage AI Agents
      • Actions
        • Send Message
        • Send File
        • Show Carousel
        • Show Survey
        • Collect Feedback
        • Create Ticket
        • Human Handoff
        • External Handoff
        • Jump to Trigger/Action
        • If/Else
        • Set Chat Variable
        • Send API Request
      • LLMs
        • Cloudflare Training
      • Publishing
        • Webchat
          • Proactive Messages
        • Facebook Messenger
        • WhatsApp
        • Telegram
        • LINE
        • Africa's Talking
        • Bitrix24
        • Zendesk
    • Inbox
      • Find & View Conversations
      • Message Editor
      • Transfers & Takeovers
    • Livechats
    • Tickets
    • People
    • Analytics
      • Winnow
  • General
    • Settings
      • Workspace
        • Plan & Billing
          • Interactions Amount
        • Roles & Permissions
        • Users
        • Teams
        • IP Allowlist
        • Whitelabelling
      • Teamspaces
        • Banning
        • Tags
        • Chat Assignment
        • Email Domains
        • Email Templates
        • Exports
        • Canned Replies
        • Custom Fields
        • Custom Profiles
        • Custom Analytics
      • User Account
        • User Aliases
        • Online Status
    • Plans & Pricing
    • Enterprise Max
  • Developers
    • Developer Tools
      • Chat Variables
      • Chat Scripts
      • Webchat Script
      • Developer API
      • On-Premise & Hybrid Hosting
Powered by GitBook
On this page
  • Actions & Delimiters
  • Scripts
  • _.dt_diff(datetime1, datetime2, unit)
  • _.fmt(string, value)
  • _.format_time(datetime, format, timezone)
  • _.join(separator, items)
  • _.json_parse(data)
  • _.json_stringify(data)
  • _.len(x)
  • _.lower(string)
  • _.now(timezone, format)
  • _.replace(string, search, replacement)
  • _.split(string, separator)
  • _.str2datetime(timestring, format)
  • _.upper(string)
  • _.as_int(string)
  • _.as_float(string)
  • _.as_str(string)
  • _.round_num(number,precision)
  • _.random_num(min,max)
  • _.random_choice(list)
  • _.match_pattern(string, pattern)
  • _.obj_keys(dictionary)
  • _.obj_values(dictionary)
  • _.get(dictionary, path)
  • _.map_get(list[dict], path)
  1. Developers
  2. Developer Tools

Chat Scripts

Apply custom logic to actions in chats.

PreviousChat VariablesNextWebchat Script

Last updated 5 days ago

Chat scripts are simple Python expressions. They're used for data manipulation in certain AI agent triggered during a chat.


Actions & Delimiters

The following actions support chat scripts. To display a variable's value within an AI agent's action content, enclose the variable name within curly braces { } as a delimiter.

Actions that require { ... } delimiter
Actions that do not require delimiter

{ … } is required to print out variable/script values.

From Modify Variable to Message

Scripts

_.dt_diff(datetime1, datetime2, unit)

Calculates the difference between two datetime objects and returns the result in the specified time unit. Unit - d for day, h for hour, m for minute, s for second, e.g.:

dt1 = datetime.datetime(2022, 4, 12, 12, 0, 0)
dt2 = datetime.datetime(2022, 4, 11, 12, 0, 0)

seconds_diff = _.dt_diff(dt1, dt2,'s')
Output: 86400

hours_diff = _.dt_diff(dt1, dt2,'h')
Output: 24

_.fmt(string, value)

Formats the specified value(s) and insert them inside the string's placeholder, e.g.:

_.fmt("Hello, %s!", "world")
Output: "Hello, world!"

_.format_time(datetime, format, timezone)

Format datetime, e.g.:

_.format_time(datetime.datetime.now(), "%Y-%m-%d %H:%M:%S", "America/New_York"))
Output: Formatted time in New York timezone

 _.formatTime(_.str2datetime(timestamp), '%Y-%m-%d %H:%M:%S', 'America/Toronto')
Output: Formatted time in Toronto timezone

_.join(separator, items)

Join all items in a tuple into a string, using a character as a separator, e.g.:

items = ["apple", "banana"", "cherry"]
_.join("", "", items)
Output: "apple, banana, cherry"

_.json_parse(data)

Parses a JSON string and returns a Python object, e.g.:

json_data = '{"name": "Alice", "age": 25}'
_.json_parse(json_data)
Output: {'name': 'Alice', 'age': 25}

_.json_stringify(data)

Serialises Python objects into JSON format. It returns a JSON string representing the input data, e.g.:

data = {"name": "John", "age": 30}
_.json_stringify(data)
Output: '{"name": "John", "age": 30}'

_.len(x)

The number of characters in a variable, e.g.:

_.len("hello")
Output: 5

_.lower(string)

Convert string to lowercase, e.g.:

_.lower("WORLD")
Output: "world"

_.now(timezone, format)

Retrieves the current date and time in the Coordinated Universal Time (UTC) timezone. If a timezone is define, it would display the current year and hour based on the timezone, formatted as a string. If a dateime format code is define, it will output based on the format set.

_.now()
Output: Current date and time in UTC timezone

example time now at Manila is 2024-04-15 10:30:00
_.now('Asia/Manila', '%Y %H')
Output: 2024 10

_.replace(string, search, replacement)

Replaces a specified phrase with another specified phrase, e.g.:

_.replace("hello world", "world", "universe")
Output: "hello universe"

_.split(string, separator)

Split a string into a list where each word is a list item, e.g.:

string = "apple, banana, cherry"
_.split(string, "", "")
Output: ['apple', 'banana', 'cherry']

_.str2datetime(timestring, format)

Convert string to datetime, e.g.:

_.str2datetime("2023-12-25"))
Output: 2023-12-25 00:00:00

_.upper(string)

Convert string to uppercase, e.g.:

_.upper("hello))  
Output: "HELLO"

_.as_int(string)

Convert string to integer, e.g.:

_.as_int("10") 
Output: 10

_.as_float(string)

Convert string to float, e.g.:

_.as_float("3.14")
Output: 3.14

_.as_str(string)

Convert specified value to string, e.g.:

_.as_str(42))
Output: "42"

_.round_num(number,precision)

Returns a floating point number that is a rounded version of the specified number, e.g.:

_.round_num(3.14159, 2) 
Output: 3.14

_.random_num(min,max)

Returns an integer number selected element from the specified range, e.g.:

_.random_num(1, 10)
Output: Random integer between 1 and 10

_.random_choice(list)

Returns a randomly selected element from the specified sequence. The sequence can be a string, a range, a list, a tuple, or any other kind of sequence, e.g.:

_.random_choice(["apple", "banana", "cherry"])
Output: Randomly chosen item from the list

_.match_pattern(string, pattern)

Search the regular expression pattern and return the first occurrence, .e.g.:

email = "example@email.com"
pattern = r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"
_.match_pattern(email,pattern)

_.obj_keys(dictionary)

Takes a dictionary as input and returns a list containing all the keys from the input dictionary, e.g.:

my_dict = {'a': 1, 'b': 2, 'c': 3}
result = _.obj_keys(my_dict)
Output: [a, b, c]

_.obj_values(dictionary)

Takes a dictionary as input and returns a list containing all the values from the input dictionary, e.g.:

my_dict = {'a': 1, 'b': 2, 'c': 3}
result = _.obj_values(my_dict)
Output: [1, 2, 3]

_.get(dictionary, path)

Retrieves the value at a specified path within a nested dictionary or list, e.g.:

object = {
    'a': [
        {'b': {'c': 3}}
    ]
}

 _.get(object, 'a')
Output: [{'b': {'c': 3}}]

 _.get(object, 'a[0].b.c')
Output: 3

_.get(object, ['a', '0', 'b', 'c'])
Output: 3

_.map_get(list[dict], path)

Maps the get function over a list of dictionaries. It retrieves the value at a specified path within each dictionary in the list, e.g.:

list_d = [
    {'a': {'b': 1}},
    {'a': {'b': 2}},
    {'a': {'b': 3}}
]

_.map_get(list_d, 'a.b')
Output: [1, 2, 3]

From Survey to Message
Send Message
If/Else
Send File
Set Chat Variable
Show Carousel
Send API Request
Show Survey
Create Ticket
actions