Functions
Functions are used to calculate dynamic values in the chat flow, e.g. the current time or the age of a customer. Functions can be used in conditions, in variable value assignments, and in expressions contained in interpolated texts such as chat message bubbles Welcome ${firstname} of age ${customerAgeYears()}
or email templates.
Functions can be combined with other functions or variables such as stringContains(getParam("foo"), "bar")
or stringContains(getParam("foo"), someVariable)
.
The following list of functions can be used in LoyJoy. This list is growing. Please contact us if you are missing a function for your needs.
Where To Use Functions
Variable Value Assignment
A function can be called when assigning a value to a variable name.
Condition
A function can be called when comparing values in a condition.
Interpolated Text
A function can be called as part of an expression in interpolated text.
Math
increment
Increments the number given in argument 1 by number in argument 2.
increment(4, 2) -> 6
increment(someVarWithValue4, 2) -> 6
increment(4, someVarWithValue2) -> 6
increment(4) -> 5
increment(4, null) -> 5
This function is identical to the plus operator.
4 + 2 -> 6
someVarWithValue4 + 2 -> 6
4 + someVarWithValue2 -> 6
max
Returns the max value of two numbers.
max(4, 2) -> 4
max(someVarWithValue4, 2) -> 4
max(4, someVarWithValue2) -> 4
min
Returns the min value of two numbers.
min(4, 2) -> 2
min(someVarWithValue4, 2) -> 2
min(4, someVarWithValue2) -> 2
randomInt
Returns a random integer between the boundaries (argument 1 and argument 2) including the boundaries.
randomInt(6, 8) -> one value of 6, 7, 8
randomInt(someVarWithValue6, 8) -> one value of 6, 7, 8
round
Returns the rounded value of a number.
round(2.0) -> 2
round(2.3) -> 2
round(2.6) -> 3
round(null) -> 0
round(2.0, 1) -> 2.0
round(2.3333, 1) -> 2.3
round(2.6666, 1) -> 2.7
round(2.0, 2) -> 2.00
round(2.3333, 2) -> 2.33
round(2.6666, 2) -> 2.67
The arguments are:
- Argument 1: The variable, whose value you want to round.
- Argument 2: Optionally the number of digits the value should have. Default is
0
.
Strings
padZeroes
This function is used to pad a number or string with zeroes.
padZeroes(12, 4) -> "0012"
padZeroes(someVarWithValue12, 4) -> "0042"
The arguments are:
- Argument 1: The variable, whose value you want to pad with zeroes.
- Argument 2: The amount of digits the value should have in the end.
stringConcat
Returns a concatenated string of all arguments.
stringConcat("foo", "bar") -> "foobar"
stringConcat("foo", "bar", "test") -> "foobartest"
stringConcat("foo", 1) -> "foo1"
stringConcat("foo", someVarWithValue12) -> "foo12"
The arguments are:
- Argument 1 - n: The values to concatenate.
- Requires at least 2 arguments or an error will be thrown.
stringContains
Checks if argument 1 contains the string in argument 2.
stringContains("Hello", "ll") -> true
stringContains(someVarWithValueHello, "ll") -> true
stringReplace
Replaces every occurrence of the string that should be replaced and returns that value. It does not have any impact on the input variable in argument 1.
stringReplace("Hello all", "ll", "bb") -> "Hebbo abb"
stringReplace(someVarWithValueHello, "ll", "bb") -> "Hebbo"
stringReplaceAll
Modifies the string in argument 1 by using a regular expression in argument 2. It does not have any impact on the input variable in argument 1.
stringReplaceAll("this is an example sentence", "\s+", "-") -> "this-is-an-example-sentence"
stringReplaceAll(someVarWithSentence, "\s+", "-") -> "this-is-an-example-sentence"
stringToLowerCase
Converts the string in argument 1 to lower case with English locale.
stringToLowerCase("Hello") -> "hello"
stringToUpperCase
Converts the string in argument 1 to upper case with English locale.
stringToUpperCase("Hello") -> "HELLO"
Date & Time
Formatted
formattedLocalDate
Returns the localized date of now (or as selected in LoyJoy Manager chat preview).
formattedLocalDate() -> "15.02.24" formatted according on process locale (in this example "DE")
formattedLocalDate("YYYY") -> "2024"
The arguments are:
- Argument 1 (Pattern): Optionally the pattern you want to retrieve. For more information check out the official pattern syntax.
formattedLocalDateTime
Returns the localized date and time of now (or as selected in LoyJoy Manager chat preview).
formattedLocalDateTime() -> "15.02.24, 12:30" formatted according on process locale (in this example "DE")
formattedLocalDateTime("YYYY") -> "2024"
The arguments are:
- Argument 1 (Pattern): Optionally the pattern you want to retrieve. For more information check out the official pattern syntax.
ISO 8601
localDate
Returns the localized date in ISO 8601 format of now (or as selected in LoyJoy Manager chat preview).
localDate() -> "2024-02-15"
localDateTime
Returns the localized date time in ISO 8601 format of now (or as selected in LoyJoy Manager chat preview).
localDateTime() -> "2024-02-15T12:30:00.000000000"
localDateTime("Seconds") -> "2024-02-15T12:30:00"
localDateTime("Millis") -> "2024-02-15T12:30:00.000"
localDateTime("Micros") -> "2024-02-15T12:30:00.000000"
localDateTime("Nanos") -> "2024-02-15T12:30:00.000000000"
The arguments are:
- Argument 1: Optionally the precision as one of
Seconds
,Millis
,Micros
,Nanos
. Default isNanos
.
Date Fields
localDateDayOfMonth
Returns the localized day of month (pattern dd
) of now (or as selected in LoyJoy Manager chat preview).
localDateDayOfMonth() -> 15
localDateDayOfWeek
Returns the localized day of the week as number in interval [1-7]
with 1
for monday and 7
for sunday of now (or as selected in LoyJoy Manager chat preview).
localDateDayOfWeek() -> 4
localDateDayOfYear
Returns the localized day of the year as number in interval [1-366]
of now (or as selected in LoyJoy Manager chat preview).
localDateDayOfYear() -> 46
localDateMonthOfYear
Returns the localized month of the year as number in interval [1-12]
of now (or as selected in LoyJoy Manager chat preview).
localDateMonthOfYear() -> 2
localDateYear
Returns the localized year of now (or as selected in LoyJoy Manager chat preview).
localDateYear() -> 2024
Timestamp
timestamp
Returns the number of seconds since 1. January 1970 of now (or as selected in LoyJoy Manager chat preview).
timestamp() -> 1707996600
timestampMs
Returns the number of milliseconds since 1. January 1970 of now (or as selected in LoyJoy Manager chat preview).
timestampMs() -> 1707996600000
Date & Time Arithmetic
The date & time functions
localDate
,localDateTime
formattedLocalDate
,formattedLocalDateTime
localDateDayOfMonth
,localDateDayOfWeek
,localDateDayOfYear
,localDateMonthOfYear
,localDateYear
timestamp
,timestampMs
can be adjusted with the date & time artithmetic functions
plusChronoUnit
,minusChronoUnit
withChronoField
,withTemporalAdjuster
ofLocalDate
,ofLocalDateTime
ofTimestamp
,ofTimestampMs
This enables date & time arithmetic based on the Gregorian calendar and ISO 8601 as implemented by Java Date/Time API.
plusChronoUnit
Chrono units can be added to most date & time functions.
localDateTime(plusChronoUnit(1, "Seconds")) -> "2024-02-15T12:30:01.000000000"
localDateTime(plusChronoUnit(1, "Minutes")) -> "2024-02-15T12:31:00.000000000"
localDateTime(plusChronoUnit(1, "Hours")) -> "2024-02-15T13:30:00.000000000"
localDateTime(plusChronoUnit(1, "Days")) -> "2024-02-16T12:30:00.000000000"
localDateTime(plusChronoUnit(1, "Weeks")) -> "2024-02-22T12:30:00.000000000"
localDateTime(plusChronoUnit(1, "Months")) -> "2024-03-15T12:30:00.000000000"
localDateTime(plusChronoUnit(1, "Years")) -> "2025-02-15T12:30:00.000000000"
localDate(plusChronoUnit(1, "Days")) -> "2024-02-16"
formattedLocalDate(plusChronoUnit(1, "Days")) -> "16.02.24, 12:30"
formattedLocalDateTime(plusChronoUnit(1, "Days")) -> "16.02.24"
timestamp(plusChronoUnit(1, "Days")) -> 1708086600
timestampMs(plusChronoUnit(1, "Days")) -> 1708086600000
Chrono adjustments must be last in the arguments list, i.e. original function arguments must be first.
localDateTime("Seconds", addChronoUnit(1, "Days"))
Multiple adjustments can be combined:
localDate(minusChronoUnit(1, "Days"), plusChronoUnit(2, "Months"))
minusChronoUnit
Chrono units can be subtracted from most date & time functions.
localDateTime(minusChronoUnit(1, "Seconds")) -> "2024-02-15T12:29:59.000000000"
localDateTime(minusChronoUnit(1, "Minutes")) -> "2024-02-15T12:29:00.000000000"
localDateTime(minusChronoUnit(1, "Hours")) -> "2024-02-15T11:30:00.000000000"
localDateTime(minusChronoUnit(1, "Days")) -> "2024-02-14T12:30:00.000000000"
localDateTime(minusChronoUnit(1, "Weeks")) -> "2024-02-08T12:30:00.000000000"
localDateTime(minusChronoUnit(1, "Months")) -> "2024-01-15T12:30:00.000000000"
localDateTime(minusChronoUnit(1, "Years")) -> "2023-02-15T12:30:00.000000000"
localDate(minusChronoUnit(1, "Days")) -> "2024-02-14"
formattedLocalDate(minusChronoUnit(1, "Days")) -> "14.02.24"
formattedLocalDateTime(minusChronoUnit(1, "Days")) -> "14.02.24, 12:30"
timestamp(minusChronoUnit(1, "Days")) -> 1707913800
timestampMs(minusChronoUnit(1, "Days")) -> 1707913800000
Chrono adjustments must be last in the arguments list, i.e. original function arguments must be first.
localDateTime("Seconds", minusChronoUnit(1, "Days"))
Multiple adjustments can be combined:
localDate(minusChronoUnit(1, "Days"), plusChronoUnit(2, "Months"))
withChronoField
Chrono fields can be set to specific values for most date & time functions.
localDate(withChronoField("DayOfMonth", 3)) -> "2024-02-03"
localDate(withChronoField("DayOfWeek", 3)) -> "2024-02-14"
localDate(withChronoField("DayOfYear", 3)) -> "2024-01-03"
localDate(withChronoField("HourOfDay", 3)) -> Exception, as local date does not have time
localDate(withChronoField("MinuteOfHour", 3)) -> Exception, as local date does not have time
localDate(withChronoField("MonthOfYear", 3)) -> "2024-03-15"
localDate(withChronoField("Year", 2023)) -> "2023-02-15"
localDateTime(withChronoField("DayOfMonth", 3)) -> "2024-02-03T12:30:00.000000000"
formattedLocalDate(withChronoField("DayOfMonth", 3)) -> "03.02.24"
formattedLocalDateTime(withChronoField("DayOfMonth", 3)) -> "03.02.24, 12:30"
Chrono adjustments must be last in the arguments list, i.e. original function arguments must be first.
localDateTime("Seconds", withChronoField("Year", 2023))
Multiple adjustments can be combined:
localDate(withChronoField("Year", 2023), plusChronoUnit(2, "Months"))
withTemporalAdjuster
Temporal adjusters can be applied to most date & time functions. Temporal adjusters are a more explicit version of setting chrono fields. E.g. withTemporalAdjuster("FirstDayOfMonth")
is identical to withChronoField("DayOfMonth", 1)
.
localDate(withTemporalAdjuster("FirstDayOfMonth")) -> "2024-02-01"
localDate(withTemporalAdjuster("FirstDayOfNextMonth")) -> "2024-03-01"
localDate(withTemporalAdjuster("FirstDayOfNextYear")) -> "2025-01-01"
localDate(withTemporalAdjuster("FirstDayOfYear")) -> "2024-01-01"
localDate(withTemporalAdjuster("LastDayOfMonth")) -> "2024-02-29"
localDate(withTemporalAdjuster("LastDayOfYear")) -> "2024-12-31"
localDateTime(withTemporalAdjuster("FirstDayOfMonth")) -> "2024-02-01T12:30:00.000000000"
formattedLocalDate(withTemporalAdjuster("FirstDayOfMonth")) -> "01.02.24"
formattedLocalDateTime(withTemporalAdjuster("FirstDayOfMonth")) -> "01.02.24, 12:30"
Chrono adjustments must be last in the arguments list, i.e. original function arguments must be first.
localDateTime("Seconds", withTemporalAdjuster("FirstDayOfMonth"))
Multiple adjustments can be combined:
localDate(withTemporalAdjuster("FirstDayOfNextMonth"), plusChronoUnit(2, "Days"))
ofLocalDate
A local date can be set as the starting value instead of now.
localDate(ofLocalDate("2024-02-10")) -> "2024-02-10"
localDateTime("Seconds", ofLocalDate("2024-02-10")) -> "2024-02-10T00:00:00"
formattedLocalDate(ofLocalDate("2024-02-10")) -> "10.02.24"
formattedLocalDateTime(ofLocalDate("2024-02-10")) -> "10.02.24, 00:00"
timestamp(ofLocalDate("2024-02-10")) -> 1707523200
timestampMs(ofLocalDate("2024-02-10")) -> 1707523200000
ofLocalDateTime
A local date time can be set as the starting value instead of now.
localDate(ofLocalDateTime("2024-02-10T12:30:00")) -> "2024-02-10"
localDateTime("Seconds", ofLocalDateTime("2024-02-10T12:30:00")) -> "2024-02-10T00:00:00"
formattedLocalDate(ofLocalDateTime("2024-02-10T12:30:00")) -> "10.02.24"
formattedLocalDateTime(ofLocalDateTime("2024-02-10T12:30:00")) -> "10.02.24, 12:30"
timestamp(ofLocalDateTime("2024-02-10T12:30:00")) -> 1707568200
timestampMs(ofLocalDateTime("2024-02-10T12:30:00")) -> 1707568200000
ofTimestamp
A seconds timestamps can be set as the starting value instead of now.
localDate(ofTimestamp(1707568200)) -> "2024-02-10"
localDateTime("Seconds", ofTimestamp(1707568200)) -> "2024-02-10T12:30:00"
formattedLocalDate(ofTimestamp(1707568200)) -> "10.02.24"
formattedLocalDateTime(ofTimestamp(1707568200)) -> "10.02.24, 12:30"
timestamp(ofTimestamp(1707568200)) -> 1707568200
timestampMs(ofTimestamp(1707568200)) -> 1707568200000
ofTimestampMs
A milliseconds timestamp can be set as the starting value instead of now.
localDate(ofTimestampMs(1707568200000)) -> "2024-02-10"
localDateTime("Seconds", ofTimestampMs(1707568200000)) -> "2024-02-10T12:30:00"
formattedLocalDate(ofTimestampMs(1707568200000)) -> "10.02.24"
formattedLocalDateTime(ofTimestampMs(1707568200000)) -> "10.02.24, 12:30"
timestamp(ofTimestampMs(1707568200000)) -> 1707568200
timestampMs(ofTimestampMs(1707568200000)) -> 1707568200000
Arrays
arrayIncludes
Given a variable of type JSON array (e.g. produced by a multiple choice question in the questionnaire) this function returns true
if the second argument is contained in the JSON array, or false
if not.
arrayIncludes("[2, 3]", 3) -> true
arrayIncludes(someVarWithJsonArray, 3) -> true
arrayJoin
Given a varaible of type JSON Array (e.g. produced by a multiple choice question in the questionnaire) this function returns a string with all elements of the array joined by the separator in argument 2.
arrayJoin("[2, 3]", ",") -> "2,3"
arrayJoin(someVarWithJsonArray, ";") -> "2;3"
arrayLength
Given a variable of type JSON array (e.g. produced by a multiple choice question in the questionnaire) this function returns the number of elements within that array. You can use this function on any kind of array variable and check if it is empty or has a value stored by checking if arrayLength
returns 0
.
arrayLength("[2, 3]") -> 2
arrayLength(someVarWithJsonArray) -> 2
pushLiteral
This function adds a value in argument 2 to the variable in argument 1. The variable has to be in an array from before (e.g. multiple choice question).
pushLiteral("[2]", 3) -> "[\"2\", \"3\"]"
pushLiteral(someVarWithJsonArray, 3) -> "[\"3\"]"
pushVariable
Just like 'pushVariable' but it adds the value of a variable to the array. Keep in mind that if you do change the value of the variable you added afterwards, it wont change the values inside the array.
pushVariable("[2]", someVarWithValue3) -> "[\"2\", \"3\"]"
pushVariable(someVarWithJsonArray, someVarWithValue3) -> "[\"3\"]"
Type Conversion
toBigDecimal
Convert a string or number to a decimal number. The maximum number is unlimited.
toBigDecimal(4) -> 4
toBigDecimal(4.0) -> 4
toBigDecimal(4.3) -> 4.299... due to rounding error as 4.3 is handled as a double
toBigDecimal("4") -> 4
toBigDecimal("4.0") -> 4.0
toBigDecimal("4.3") -> 4.3
toBigDecimal(someVarWithValue4Dot3) -> 4.3
toBigInteger
Convert a string or number to an integer. The maximum integer is unlimited.
toBigInteger(4) -> 4
toBigInteger(4.0) -> 4
toBigInteger(4.3) -> 4
toBigInteger(4.9) -> 4
toBigInteger("4") -> 4
toBigInteger("4.0") -> 4
toBigInteger(someVarWithValue4) -> 4
toBoolean
toBoolean(true) -> true
toBoolean(false) -> false
toBoolean("true") -> true
toBoolean("false") -> false
toBoolean(someVarWithValueTrue) -> true
toFloat
Convert a string or number to a decimal number. The maximum number is unlimited.
toFloat(4) -> 4.0
toFloat(4.0) -> 4.0
toFloat(4.3) -> 4.3
toFloat("4") -> 4.0
toFloat("4.0") -> 4.0
toFloat("4.3") -> 4.3
toFloat(someVarWithValue4Dot3) -> 4.3
toInteger
Convert a string or number to an integer. The maximum integer is 2147483647.
toInteger(4) -> 4
toInteger(4.0) -> 4
toInteger(4.3) -> 4
toInteger(4.9) -> 4
toInteger("4") -> 4
toInteger("4.0") -> 4
toInteger(someVarWithValue4) -> 4
toString
toString("test") -> "test"
toString(1) -> "1"
toString(true) -> "true"
toString(false) -> "false"
toString(someVarWithValueTrue) -> "true"
Consents & Opt-Ins
hasDeniedAnySingleOptIn
Returns true
if the signed-in user has ever denied any single opt-in, and false
if not.
hasDeniedAnySingleOptIn() -> true
newsletterDoubleOptIn
Returns true
, if the current user has a double opt-in in the Newsletter Opt-In process module and false
if not. If you have different newsletters with different tags, use the tag as argument in this function.
newsletterDoubleOptIn() -> true
newsletterDoubleOptIn("some_tag") -> true
newsletterDoubleOptInUrl
Returns the URL which is used as double opt-in confirmation.
newsletterDoubleOptInUrl() -> "https://app-stable.loyjoy.com/bot/opt_in/newsletter/confirm?token=eyJ0e..."
newsletterSingleOptIn
Returns true
, if the current user has a single opt-in in the Newsletter Opt-In process module and false
if not. If you have different newsletters with different tags, use the tag as argument in this function.
newsletterSingleOptIn() -> true
newsletterSingleOptIn("some_tag") -> true
profilingDoubleOptIn
Returns true
, if the current user has a double opt-in in the Profiling Opt-In process module and false
if not.
profilingDoubleOptIn() -> true
profilingDoubleOptInUrl
Returns the URL which is used as double opt-in confirmation.
profilingDoubleOptInUrl() -> "https://app-stable.loyjoy.com/bot/opt_in/profiling/confirm?token=eyJ0e..."
profilingSingleOptIn
Returns true
, if the current user has a single opt-in in the Profiling Opt-In process module and false
if not.
profilingSingleOptIn() -> true
reminderSingleOptIn
Returns true
, if the current user has a single opt-in in the Reminder Opt-In process module and false
if not.
reminderSingleOptIn() -> true
smsDoubleOptIn
Returns true
, if the current user has a double opt-in in the SMS Opt-In process module and false
if not.
smsDoubleOptIn() -> true
smsSingleOptIn
Returns true
, if the current user has a single opt-in in the SMS Opt-In process module and false
if not.
smsSingleOptIn() -> true
webPushDoubleOptIn
Returns true
if the user in process module Web Push Opt-In allowed a subscription for web push notifications in the webbrowser. Else it returns false
webPushDoubleOptIn() -> true
webPushSingleOptIn
Returns true
if the user process module Web Push Opt-In allowed a subscription for web push notifications in the chat. Else it returns false
.
webPushSingleOptIn() -> true
Web Browser & Website
clientLocale
This function returns the language setting of the webrowser as a string. For example an English webbrowser might return en
and a German webbrowser might return de
.
clientLocale() -> "de"
clientLocale() -> "de-CH"
clientLocale() -> "fr-CH"
To check out all possible values, read documentation of the language codes.
getCookie
This function can provide any cookie from the hosting website the LoyJoy chatbot is published on. The cookie must not be HTTP-only, i.e. it must be accessible from JavaScript.
getCookie("foo") -> "bar"
The arguments are:
- Argument 1: The key (or name) of the cookie you want to extract.
getParam
This function can extract parameters from any of three sources:
- URL parameters (see below for more information)
- Widget URL parameters
- Widget boot parameters
URL parameters (also known as query strings or URL query parameters) are elements inserted in your URLs to help you filter and organize content. Or implement tracking on your website, e.g. with UTM tracking parameters. To identify the name of a URL parameter, look at the portion of the URL that comes after a question mark (?). URL parameters include a key and a value that are separated by an equals sign (=). Multiple parameters are then separated by an ampersand (&). This is a powerful tool to use with your ads, e.g. on Meta and Google Adwords.
A complete URL string with parameters looks like this:
https://example.org/some_path?foo=bar
The function to extract the parameter value from the URL above looks like this:
getParam("foo") -> "bar"
The arguments are:
- Argument 1: The key (or name) of the URL or other parameter you want to extract.
Parameters are separate from variables for security reasons, as technically they can be freely modified by customers. With this function you can fetch a specific parameters consciously and e.g. store it as a variable with the Variable process module.
For example, URL query parameters can look like https://example.org/some_path?foo=bar
or https://example.org/some_path?foo1=bar1&foo2=bar2
for multiple query parameters.
ipAddress
Returns the IP address of the current device.
ipAddress() -> "127.0.0.1"
isMobile
Returns true
if the current user uses a mobile device and false
if not.
isMobile() -> true
locale
This function returns the language setting of the experience as a string. For example an English webbrowser might return en
and a German webbrowser might return de
, if those languages are activated on the experience.
locale() -> "de"
locale() -> "en"
locale() -> "fr"
Formal German ("Siezen") ist not standardized by IETF and thus expressed in LoyJoy with a BCP 47 private use subtag.
locale() -> "de-x-formal"
To check out all possible values, read documentation of the language codes.
locationHrefHost
Returns the host of the current URL, where the widget is embedded.
E.g. for https://www.Example.org/some/Path.html?foo=bAr&Baz=qux#somE-hash
:
locationHrefHost() -> "www.Example.org"
locationHrefHostLowerCase
Returns the host of the current URL, where the widget is embedded. All letters are converted to lower case.
E.g. for https://www.Example.org/some/Path.html?foo=bAr&Baz=qux#somE-hash
:
locationHrefHostLowerCase() -> "www.example.org"
locationHrefPath
Returns the path of the current URL, where the widget is embedded.
E.g. for https://www.Example.org/some/Path.html?foo=bAr&Baz=qux#somE-hash
:
locationHrefPath() -> "/some/Path.html"
locationHrefPathLowerCase
Returns the path of the current URL, where the widget is embedded. All letters are converted to lower case.
E.g. for https://www.Example.org/some/Path.html?foo=bAr&Baz=qux#somE-hash
:
locationHrefPathLowerCase() -> "/some/path.html"
userAgent
Returns the the version string of the customer webbrowser.
userAgent() -> "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36"
Other
chatHistory
Returns the full chat history of the user including the current user message.
chatHistory() -> "Assistant: Do you want to continue?<br />Human: OK<br />"
chatHistoryKnowledge
Returns the past question and answer chat history of the user, i.e. when the user has entered a question in the footer and previously received an answer from GPT. Includes the current user message.
chatHistoryKnowledge() -> "Human: How are you?<br />Assistant: I'm fine and you?<br />Human: I'm fine too<br />"
conversationId
Returns the ID of the current conversation.
conversationId() -> "cd7e8264-7464-4fad-a553-cbcba23f7a2d"
customerAgeYears
This function calculates the age of the customer based on his date of birth, which is stored in the variable birthdate
. The variable will be filled automatically when you use the birthdate module.
customerAgeYears() -> 18
deviceId
Returns the ID of the current device. LoyJoy assigns a random ID as a device ID to each chat UI client and to each third-party client such as WhatsApp. The device ID then allows to push web notifications or chat messages to the device. When a customer uses multiple browsers or devices the customer will have multiple device IDs.
deviceId() -> "c5182f8e-aa28-4ebd-a4ad-c28d38b2c6ab"
hasBpmnProcessVariable
Returns true
if the provided variable in argument 1 exists, and false
if the variable does not exist.
hasBpmnProcessVariable("someVar") -> true
hasBpmnProcessVariable(stringConcat("some", "Var")) -> true
getBpmnProcessVariable
Returns the value of the provided variable name in argument 1, and null
if the variable does not exist.
getBpmnProcessVariable("someVar") -> "someValue"
getBpmnProcessVariable(stringConcat("some", "Var")) -> "someValue"
getBpmnProcessVariable("someUnknownVar") -> null
i18nTranslate
This function returns the i18n text value in the users current language for a given key. The function expects the i18n key for the text as argument, which you can fetch from the texts tab.
i18nTranslate("welcome_greeting/1f6fb69a-49a8-47c6-ab8e-b6cd290fa196") -> "Welcome" as the welcome text entered in the welcome module with ID `1f6fb69a-49a8-47c6-ab8e-b6cd290fa196`. All i18n keys can be found in the texts table of an experience.
interpolate
Interpolates the string entered in argument 1.
interpolate("Hello ${firstname}") -> "Hello Joe"
isAuthenticated
Returns true
if the user is authenticated and false
if not. A user can be authenticated via multipe process modules such as Sign-In, Auth0, ReachFive and ProCampaign.
isAuthenticated() -> true
jsonParse
Mainly to be used with the API client module. Can parse JSON to convert strings to objects. This is useful when the API you communicate with expects an array and you e.g. used a multiple choice questionnaire to create the array.
jsonParse("[\"a\", \"b\"]") -> ["a", "b"]
jsonStringify
Mainly to be used for every dynamic mapping of a JSON object to a string e.g. in the API client module or Keycloak module. It may be use to convert JSON arrays to strings.
jsonStringify(jsonObject.some_array) -> ["a", "b"]
numParticipations
This function calculates the number of the over all participations in any giveaway of the current user. To calculate this number there needs to be a Participation process module before.
numParticipations() -> 3
numParticipationsBpmnProcess
The number of participations a customer has made in the current process summed over all participation process modules. To calculate this number there needs to be a Participation process module before.
numParticipationsBpmnProcess() -> 3
numRedemptionsRemaining
This function calculates the number of remaining redemptions, if a maximum total number of redemptions is configured in a loyalty redemption module.
numRedemptionsRemaining("37b68834-04ed-4f1b-9193-89c789dd0545") -> 99
The arguments are:
- Argument 1: The ID of the Loyalty redemption process module.
objectKeys
Given a variable of type JSON object (e.g. produced by an API request) this function returns an array of the property keys of that object.
E.g. for someVariableWithJsonObject
containing string {"a":1,"b":2}
:
objectKeys(jsonParse(someVariableWithJsonObject)) -> ["a","b"]
objectValues
Given a variable of type JSON object (e.g. produced by an API request) this function returns an array of the property values of that object.
E.g. for someVariableWithJsonObject
containing string {"a":1,"b":2}
:
objectValues(jsonParse(someVariableWithJsonObject)) -> [1,2]
postbackPayloadValue
Returns the ID of the selected value by the user. E.g. if the user selects an element in the product gallery module, you can identify its ID.
printR
Returns for all variables in the current conversation the variable name and its value. For all questionnaire questions it returns the question and the answer. This function is useful for debugging or to print all variables into an email or PDF.
printR() -> "someQuestion: someAnswer
someVar: someValue"
processInstanceId
Returns the ID of the current process instance. When a customer executes a process (experience) in the background a process instance ID is generated and saved in the conversation. All process-specific variables are scoped with the process and process instance ID, so that variables from different process executions can be distinguished. A new process instance ID can be enforced with process module Process Instance Create.
processInstanceId() -> "99a5a7ef-127f-4513-99e1-1df95618f539"
processId
Returns the ID of the current process (experience).
processId() -> "9f1baa74-de18-4ae6-ab54-550e4472beb0"
productsCount
Returns the number of products in the database. You can use a SQL statement to count the number of products in the database for the given query.
productsCount() -> 5
productsCount("SELECT * FROM products WHERE price <= 100") -> 3
productsToCsv
Format the products in the database as a CSV string. You can use a SQL statement to select the products from the database and format them as a CSV string.
productsToCsv() -> "
id,title,price
1, Product 1,100
2, Product 2,200
"
productsToCsv("SELECT title, price FROM products WHERE price <= 100") -> "
title,price
Product 1,100
"
productsValueRanges
Returns the value ranges of the products in the database. You can use a SQL statement to select the products from the database and calculate the value ranges.
productsValueRanges() -> "
title: Product 1, Product2
price: 100, 200
"
productsValueRanges("SELECT title, price FROM products WHERE price <= 100") -> "
title: Product 1
price: 100
"
randomUuid
Returns a random UUID.
randomUuid() -> "71fae7ba-39e0-427b-b052-4fb8add08754"
senderId
Returns the ID of the current client. In case of third-party clients such as WhatsApp the sender ID is given by WhatsApp, e.g. as the telephone number. In case of the LoyJoy chat UI client the sender ID is randomly set by LoyJoy, e.g. from the device ID. If you want to determine the device ID use function call deviceId()
.
senderId() -> "b0d6950b-06bc-4e6d-88d6-ca7442eb13c9"
signInToken
Returns a token unique per session even if you are not signed in.
signInToken() -> "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3Mi..."
subProcessId
Returns the ID of the current process module, i.e. sub process.
subProcessId() -> "bf918b9e-fc27-4577-9bcc-28b4e98d8517"
urlEncode
Takes a string as input and applies URL encoding (also known as percent-encoding) to it. This process is crucial when a string, which may contain reserved characters, is intended to be used as a path or query parameter in a URL. URL encoding ensures that the URL is valid and can be correctly interpreted by web browsers and servers.
urlEncode("test@loyjoy.com") -> "test%40loyjoy.com"