Expressions let Avortyx reshape and calculate data as calls and leads move through it: clean a name before it reaches a buyer, compute a payout, format a date for a postback. Functions can be nested inside each other, so small pieces combine into real logic.
They work anywhere Avortyx fills in tokens, including:
- Default values for contact fields
- Webhook URLs and postback bodies
- Filters in your routing rules
Every expression has a type (String, Integer, Float or Time), and its arguments are converted to that type before it is evaluated.
Sample data
The examples on this page use the data below; the result of each expression follows its =>
{
"first_name": "John",
"last_name": "Smith",
"birth_year": "1977",
"yob": 2012,
"mortgage_amount": 65000,
"debt_amount": 8283.25,
"started_at_utc": "2020-06-21 22:35:12 UTC"
}
A String expression
Arguments are treated as text before the expression runs.
[!String! ALPHANUMERIC_DASH(CONCAT([first_name], " ", [last_name])) !!] => john-smith
A Time expression
Arguments are treated as times before the expression runs.
[!Time! DATE_FORMAT(DATE_ADD([started_at_utc], 86400), "%Y-%m-%d %M-%S") !!] => "2020-06-22T18:35:12"
Functions
case(statement)
logicTests several conditions in order and returns the output of the first one that is true.
| Argument | Required | Info |
|---|---|---|
| statement | Required | The statement that will be evaluated. |
CASE('apple' WHEN 'apple' THEN 1 WHEN 'banana' THEN 2 ELSE 3 END)
=> 1
if(statement, output_when_true, output_when_false)
logicChecks a condition and returns one value when it holds and another when it does not.
| Argument | Required | Info |
|---|---|---|
| statement | Required | The statement that will be evaluated. |
| output_when_true | Required | The value that will be outputted if the statement evaluates to true. |
| output_when_false | Required | The value that will be outputted if the statement evaluates to false. |
IF(15 < 10, 10, 20) => 20
avg(*values)
numericThe mean of the numbers you pass in.
| Argument | Required | Info |
|---|---|---|
| *values | Required | This function accepts an unlimited number of numeric values. |
AVG(1,2,3,4) => 2.5
count(*values)
numericHow many values were passed in.
| Argument | Required | Info |
|---|---|---|
| *values | Required | This function accepts an unlimited number of numeric values. |
COUNT(1,2,3,4) => 4
max(*values)
numericThe largest of the numbers you pass in.
| Argument | Required | Info |
|---|---|---|
| *values | Required | This function accepts an unlimited number of numeric values. |
MAX(1,2,3,4) => 4
min(*values)
numericThe smallest of the numbers you pass in.
| Argument | Required | Info |
|---|---|---|
| *values | Required | This function accepts an unlimited number of numeric values. |
MIN(1,2,3,4) => 1
round(value, precision)
numericRounds a number to the closest value at the precision you give.
| Argument | Required | Info |
|---|---|---|
| value | Required | The value to be rounded. EG:ROUND(8.8) => 9 |
| precision | Optional | The precision to be used. EG:ROUND(8.75, 1) => 8.8 |
ROUND(8.2) => 8
rounddown(value, precision)
numericRounds a number down, toward the lower value, at the precision you give.
| Argument | Required | Info |
|---|---|---|
| value | Required | The value to be rounded. EG:ROUND(8.8) => 8 |
| precision | Optional | The precision to be used. EG:ROUND(1.234, 2) => 1.23 |
ROUNDDOWN(1.234) => 1
roundup(value, precision)
numericRounds a number up, toward the higher value, at the precision you give.
| Argument | Required | Info |
|---|---|---|
| value | Required | The value to be rounded. EG:ROUND(8.8) => 9 |
| precision | Optional | The precision to be used. EG:ROUND(1.234, 2) => 1.24 |
ROUNDUP(1.234) => 2
sum(*values)
numericAdds the numbers you pass in.
| Argument | Required | Info |
|---|---|---|
| *values | Required | This function accepts an unlimited number of numeric values. |
SUM(1,2,3,4) => 10
alphanumeric_dash(value)
stringKeeps only letters (a-z, A-Z) and digits (0-9), turns spaces into dashes and trims spaces from both ends. Handy for slugs and IDs.
| Argument | Required | Info |
|---|---|---|
| value | Required |
ALPHANUMERIC_DASH(" ./;!!!] hello waffle world!@#$%^&*($) ")
=> "hello-waffle-world"
alphanumeric_underscore(value)
stringKeeps only letters (a-z, A-Z) and digits (0-9), turns spaces into underscores and trims spaces from both ends.
| Argument | Required | Info |
|---|---|---|
| value | Required |
ALPHANUMERIC_UNDERSCORE(" ./;!!!] hello waffle world!@#$%^&*($) ")
=> "hello_waffle_world"
base64_decode(value)
stringDecodes a Base64 string (RFC 2045), skipping any characters outside the Base64 alphabet.
| Argument | Required | Info |
|---|---|---|
| value | Required |
BASE64_DECODE('dGVzdA==')
=> 'text'
base64_encode(value)
stringEncodes a value as Base64 (RFC 2045), with a line break after every 60 encoded characters.
| Argument | Required | Info |
|---|---|---|
| value | Required |
BASE64_ENCODE('text')
=> 'dGVzdA=='
concat(*values)
string| Argument | Required | Info |
|---|---|---|
| *values | Required | This function accepts an unlimited number of string values. |
CONCAT('AB', 'CD', 'EF')
=> "ABCDEF"
contains(search, value)
string| Argument | Required | Info |
|---|---|---|
| search | Required | Outputs true if [value] contains this string. |
| value | Required | The string that will be checked. |
CONTAINS('ABCD', 'A')
=> true
date_add(value, seconds)
stringMoves a date forward by a number of seconds.
| Argument | Required | Info |
|---|---|---|
| value | Required | The date that will be modified. |
| seconds | Required | The seconds that will be added. |
DATE_ADD([started_at_utc], 86400) => "2020-06-29 11:34:25 -0400"
date_format(value, format)
stringWrites a date in the format you choose.
| Argument | Required | Info |
|---|---|---|
| value | Required | The date that will be modified. EG '2020-06-29 11:22:57 -0400' |
| format | Required | Specifies the format for the date. The following characters can be used. Date (Year, Month, Day): %Y - Year with century %y - year % 100 (00..99) %m - Month of the year, zero-padded (01..12) %B - The full month name (``January'') %b - The abbreviated month name (``Jan'') %d - Day of the month, zero-padded (01..31) %j - Day of the year (001..366) Time %H - Hour of the day, 24-hour clock, zero-padded (00..23) %I - Hour of the day, 12-hour clock, zero-padded (01..12) %P - Meridian indicator, lowercase (``am'' or ``pm'') %p - Meridian indicator, uppercase (``AM'' or ``PM'') %M - Minute of the hour (00..59) %S - Second of the minute (00..59) %L - Millisecond of the second (000..999) %N - Fractional seconds digits, default is 9 digits (nanosecond) %z - Time zone as hour and minute offset from UTC (e.g. +0900) Weekday %A - The full weekday name (``Sunday'') %a - The abbreviated name (``Sun'') %u - Day of the week (Monday is 1, 1..7) %w - Day of the week (Sunday is 0, 0..6) Seconds since the Unix Epoch %s - Number of seconds since 1970-01-01 00:00:00 UTC. %Q - Number of milliseconds since 1970-01-01 00:00:00 UTC. |
DATE_FORMAT([started_at_utc], "%Y-%m-%d %M-%S") => "2020-06-22T18:35:12"
date_parse(value, format)
stringReads a date or time written in plain language and turns it into a date.
| Argument | Required | Info |
|---|---|---|
| value | Required | The date or natural language expression. Simple Examples thursday november summer friday 13:00 mon 2:35 4pm yesterday today tomorrow last week next week Complex Examples 3 years ago a year ago 5 months from now 7 hours ago 7 days from now in 3 hours Specific Dates & Times 22nd of june at 8am 1979-05-27 05:00:00 03/01/2012 07:25:09.234567 2013-08-01T19:30:00.345-07:00 2013-08-01T19:30:00.34-07:00 |
| format | Optional |
DATE_PARSE("30 days from now")
=> "2020-07-29 15:42:57 UTC"
date_subtract(time, time_or_decimal)
stringTakes a timestamp or a number of seconds away from a date.
| Argument | Required | Info |
|---|---|---|
| time | Required | The timestamp to be manipulated. |
| time_or_decimal | Required | The timestamp or decimal that will be subtracted from the first argument time. |
DATE_SUBTRACT([current_time_utc], [started_at_utc]) => "2020-06-29 11:34:25 -0400"
date_to_time_zone(value, time_zone)
stringConverts a date into another time zone.
| Argument | Required | Info |
|---|---|---|
| value | Required | [lead_created_at] |
| time_zone | Required | Examples Time Zones:
|
DATE_TO_TIME_ZONE([lead_created_at], "Eastern Time (US & Canada)") => "2020-07-29 15:42:57"
digest_md5(value)
stringReturns the MD5 hash of a value (RFC 1321): a 128-bit (16-byte) digest.
| Argument | Required | Info |
|---|---|---|
| value | Required |
DIGEST_MD5('text')
=> 90015098...
digest_sha1(value)
stringReturns the SHA-1 hash of a value, as defined by NIST in FIPS PUB 180-1.
| Argument | Required | Info |
|---|---|---|
| value | Required |
DIGEST_SHA1('text')
=> a9993e36...
digest_sha2(value)
stringReturns the SHA-256 hash of a value: a 256-bit digest computed over 512-bit blocks.
| Argument | Required | Info |
|---|---|---|
| value | Required |
DIGEST_SHA2('text')
=> ba7816bf8...
downcase(value)
stringMakes every letter lowercase.
| Argument | Required | Info |
|---|---|---|
| value | Required |
DOWNCASE("HELLO World")
=> "hello world"
find(search, value)
string| Argument | Required | Info |
|---|---|---|
| search | Required | Finds the integer index of [search] in [value]. If [search] is missing in [value] it outputs nothing. |
| value | Required | The string that will be manipulated. |
FIND('BC', 'ABCD')
=> 2
generate_uuid()
stringCreates a new universally unique identifier (UUID).
GENERATE_UUID() => "518e8221-a29e-72c1-a716-486156481234"
left(value, length)
string| Argument | Required | Info |
|---|---|---|
| value | Required | The string that will be manipulated. |
| length | Required | The number of characters to extract starting from the left. |
LEFT('ABCD', 2)
=> "AB"
len(value, length)
string| Argument | Required | Info |
|---|---|---|
| value | Required | The string that will be manipulated. |
| length | Required | Outputs the length of the string as an integer. |
LEN('ABCD')
=> 4
oauth_access_token(oauth_connection_key)
stringFetches an access token from one of your OAuth connections, for authenticated webhooks.
| Argument | Required | Info |
|---|---|---|
| oauth_connection_key | Required | The key that you chose when creating the connection. |
OAUTH_ACCESS_TOKEN('marchex_v2')
=> "sdjf9032fj239fj90sjf90wjf390"
right(value, length)
string| Argument | Required | Info |
|---|---|---|
| value | Required | The string that will be manipulated. |
| length | Required | The number of characters to extract starting from the right. |
RIGHT('ABCD', 2)
=> "CD"
seconds_to_hms(seconds)
stringShows a number of seconds as HH:MM:SS, for example a call duration.
| Argument | Required | Info |
|---|---|---|
| seconds | Required |
SECONDS_TO_HMS(3672) => "01:01:12"
split(value, pattern, index)
stringBreaks a value apart at a delimiter and returns the piece at the index you ask for.
| Argument | Required | Info |
|---|---|---|
| value | Required | The text that will be modified. |
| pattern | Required | The pattern is a String. Its contents are used as the delimiter when splitting str. If pattern is a single space, str is split on whitespace, with leading and trailing whitespace and runs of contiguous whitespace characters ignored. |
| index | Required | Index is the index of the split substrings that will be returned. Examples: SPLIT([full_name], ' ', 2) would return "Smith" |
SPLIT("John Smith", " ", 1)
=> "Smith"
strip(value)
stringTrims whitespace from the start and end of a value.
Whitespace here means null, horizontal tab, line feed, vertical tab, form feed, carriage return and space.
| Argument | Required | Info |
|---|---|---|
| value | Required |
STRIP(" hello world ")
=> "hello world"
substitute(value, search, replacement)
string| Argument | Required | Info |
|---|---|---|
| value | Required | The string that will be manipulated. |
| search | Required | The text that will be replaced. |
| replacement | Required | The replacement text. |
SUBSTITUTE('green cat, blue cat, yellow cat', 'cat', 'dog')
=> "green dog, blue cat, yellow cat"
substitute_all(value, search, replacement)
stringReplaces every occurrence of one piece of text with another.
| Argument | Required | Info |
|---|---|---|
| value | Required | The string that will be manipulated. |
| search | Required | The text that will be replaced. |
| replacement | Required | The replacement text. |
SUBSTITUTE_ALL("green cat, blue cat, yellow cat", "cat", "dog")
=> "green dog, blue dog, yellow dog"
substring(value, start, length)
stringReturns a slice of a string: the characters in the range you specify.
| Argument | Required | Info |
|---|---|---|
| value | Required | The text that will be modified |
| start | Required | The position where to start the extraction. First character is at index 0. |
| length | Required | The number of characters to extract. Pass -1 to extract the rest of the string. |
SUBSTRING([started_at_offer_time_zone], 0, 9) => "2020-09-20"
titleize(value)
stringCapitalizes the first letter of every word.
| Argument | Required | Info |
|---|---|---|
| value | Required |
TITLEIZE(" hello world ")
=> " Hello World "
to_currency(value, symbol)
stringFormats a number as money, with a currency symbol and thousands separators.
| Argument | Required | Info |
|---|---|---|
| value | Required | The numeric amount to be formatted as currency. |
| symbol | Optional | Optional symbol to represent the currency (e.g., $, €, £). Defaults to $. |
TO_CURRENCY("1234567.89")
=> "$1,234,567.89"
TO_CURRENCY("1234567.89", "€")
=> "€1,234,567.89"
to_formatted_number(args, **, block)
stringFormats a phone number the way it is written locally.
| Argument | Required | Info |
|---|---|---|
| args | Optional | |
| ** | Optional | |
| block | Optional |
TO_FORMATTED_NUMBER(" + 1 719-852-2985 ")
=> "(719) 522-0377"
to_integer(value)
stringTurns a value into a whole number.
| Argument | Required | Info |
|---|---|---|
| value | Required |
TO_INTEGER(' 15.15 ')
=> 15
to_json(value)
stringTurns a value into a JSON string.
| Argument | Required | Info |
|---|---|---|
| value | Required |
TO_JSON({example: "value"})
=> {"example": "value"}
to_phone_number(value)
stringNormalizes a phone number into international format.
| Argument | Required | Info |
|---|---|---|
| value | Required |
TO_PHONE_NUMBER(" 1 (719) 852 2985 ")
=> "+17198522985"
upcase(value)
stringMakes every letter uppercase.
| Argument | Required | Info |
|---|---|---|
| value | Required |
UPCASE("Hello World")
=> "HELLO WORLD"
url_decode(value)
stringTurns percent-encoded sequences (a % followed by two hex digits) back into the characters they stand for.
| Argument | Required | Info |
|---|---|---|
| value | Required |
URL_DECODE("hello%20world%2C%20how%20are%20you%3F")
=> "hello world, how are you?"
url_encode(value)
stringPercent-encodes every character that is not a letter or digit, so the value is safe in a URL.
| Argument | Required | Info |
|---|---|---|
| value | Required |
URL_ENCODE("hello world, how are you?")
=> "hello%20world%2C%20how%20are%20you%3F"
usa_zip_code(value)
stringKeeps only the first five digits, turning a ZIP+4 into a standard U.S. ZIP code.
| Argument | Required | Info |
|---|---|---|
| value | Required |
USA_ZIP_CODE("USA 90210 OR")
=> "90210"