Chatlayer Documentation
Get in touchAbout Chatlayer
  • Welcome
  • What's new
  • Send feedback
  • start quickly
    • Leadzy tutorial
      • 0. Introduction
      • 1. New bot, new block
      • 2. Understand your users
      • 3. Collect and display user input
      • 4. Steer the conversation with Conditions
      • 5. Empower your bot with Actions
      • 6. Set up a channel and publish your bot
    • Templates
      • Banking
      • E-Commerce Returns
      • E-Bike Shop
      • E-Scooter Support
      • Feedback
      • Find Nearest Location
      • GPT
      • 🆕Gym
      • Job applications
      • Knowledge base AI template
      • Lead generation
      • 🆕NPS
      • Restaurant
      • Retail
  • navigation
    • Analytics
      • Dashboard
      • Customers
      • Conversations
      • User flow
      • Intents
      • 🆕Funnels [Beta]
    • Bot builder
      • Flows
        • Canvas functionalities
        • Collaborate with team members
        • Manage your flows
        • 🆕[Beta] Export and import flows
      • Bot dialogs view
      • Translations
      • Events
    • NLP
      • Dashboard
      • Intents
      • Expressions
      • Entities
      • Train
      • NLP settings
      • Improve
    • Knowledge base AI
      • Add content to your KBAI
      • Build your KBAI flow
      • Use your KBAI source URL in a button
      • Use tags to limit your KBAI content
      • 🆕Use Tables to store your KBAI questions
      • 🆕Manage handover where KBAI is unsatisfactory
    • History
      • Conversations
      • Execution logs
      • Versions
    • Channels
    • Tables
      • Create a table with records
      • Column types
      • Operate on your records
        • Insert record
        • Update record
        • Retrieve record
        • Delete record
      • API
    • Settings
      • Bot settings
      • Offloading
      • Variables
      • Voice
      • Import/Export
  • build your bot
    • Conversation design
      • Plan your bot
      • Conversation design workflow
    • Flow logic
      • Blocks
        • Message
        • Condition
        • Collect input
        • Action
      • Go-to connections
    • 🆕Emulator
    • Tips & best practices
      • Route your flow depending on the time
      • Improve the Not understood block
        • How to create better not understood messages
        • Not understood counter
        • Not understood Google search
      • Go to previous block
      • Recognizing a returning user
      • Skip introduction message
      • Route your flow depending on the channel
      • Reuse flows
      • Connect two bots to each other
  • understand users
    • Natural language processing (NLP)
      • Basic NLP concepts
      • Detect information with entities
        • Match entities
        • Contextual entities
        • System entities
        • Composite entities
      • NLP best practices
        • Word order and diversity of expressions
      • AI intent booster
      • Train your NLP
      • Context
      • NLP import & export
      • Sentiment analysis
    • Languages
      • Supported languages
      • Make your bot multilingual
      • Change language within the conversation
  • set up channels
    • Add a channel to your bot
    • All channels
      • 🚨Facebook Messenger [Deprecated soon]
        • Facebook Admin Removal
        • Facebook Webview Whitelisting
        • Facebook Messenger API updates for Europe
      • 🚨Google Assistant [Deprecated soon]
      • Webhook
      • Web
        • 🚨Web V1 [Deprecated]
          • Customize web widget
          • Live example web widget
        • 🆕Web V2
          • 🆕From Web V1 to V2
          • 🆕Web V2 methods and options
    • Sinch Conversation API
      • Configure your Sinch Conversation API
      • 🆕 Make the most of RCS with Carousels
      • WhatsApp Business API
  • integrate & code
    • API calls
      • Configure your API integration
      • Advanced API features
      • V1 API Reference
      • Custom integrations 101
    • Code editor
      • [Example] Sending data to Airtable (POST)
      • [Example] Retrieving data from Airtable (GET)
      • [Example] Making SOAP requests
    • App integrations
      • Airtable
      • Freshdesk
      • Freshdesk Messaging
      • 🆕Gmail
      • Intercom
      • Mailgun
      • OpenAI: GPT-3, ChatGPT and GPT-4
      • Salesforce
      • 🆕Slack
      • Topdesk
      • Zendesk Support
      • Zendesk Sunshine (beta)
    • 🆕Expression syntax
    • Human handover & live chat
      • Sinch Contact Pro
      • #Interact
      • Genesys Cloud
      • Offloading Webhook
      • Salesforce Service Cloud
      • Sparkcentral by Hootsuite
      • Zendesk Chat
    • Chatlayer messages specifications
  • Publish
    • Publish your bot
      • Publish a flow
  • Analyze & maintain
    • Analytics definitions
    • Data retention
    • Maintenance
    • Session
    • Track events for analytics
  • VOICE
    • 🆕Send bot response as audio
    • Voicebots
      • Create a voicebot
      • Voicebot-specific actions
      • Test your voicebot
      • From chat to voice
  • access & support
    • Identity & Access
      • Single Sign-On (SAML SSO)
    • Billing & subscription
    • Get in touch
    • Chatlayer glossary
    • SaaS Regions & IP Ranges
    • Status
    • Debug your bot
      • No correct response
      • Collect input not working
      • Video isn't working
Powered by GitBook
On this page
  • How to use expression syntax
  • Use syntax functions in your bot
  • Functions
  • Operators
  • Data types
  • Expression syntax use cases
  • Get the time
  • Downcase
  • Create a list
  • 🚨 Breaking changes
  • Variable name restriction
  • JavaScript identifier requirement
  • Removal of the| operator
  • JSON.stringif no longer compatible

Was this helpful?

  1. integrate & code

Expression syntax

Get the flexibility to use code syntax functions in your bot without the need of extensive coding skills.

PreviousZendesk Sunshine (beta)NextHuman handover & live chat

Last updated 5 months ago

Was this helpful?

Expression syntax refers to the structure of statements in code language used to incorporate dynamic content, variables, or specific built-in functions in your chatbot.

For existing bots Please note that expression syntax needs to be enabled on your account. To enable expression syntax on your account, please . For new bots Expression syntax is enabled by default.

Please also be aware about the taking place for existing bots.

Unlike traditional code actions, which require JavaScript knowledge and can be resource-intensive, expression syntax on Chatlayer makes advanced functionalities accessible without the need for extensive coding skills.

How to use expression syntax

Use syntax functions in your bot

To use expression syntax in your chatbot:

  1. Go to your text field.

  2. Type ‘{' inside a text field or type the name of a built-in function. Some use-cases are shown below.

Text step

Use expression syntax inside a text step to display the result inside your bot message.

Condition block

Read below for use case examples:

Functions

Built-in functions

Here is the list built functions that you can use:

Name
Summary
Example

ABS

Returns the absolute value of a number.

operation: (n: any) => Math.abs(n)

APPEND

Adds one or more items to the end of a list.

operation: (arr: any, ...items: any[]) => arr.concat(...items)

BASE64_DECODE

Decode Base64 encoded text.

operation: (text: any) => Buffer.from(text, 'base64').toString('utf8')

BASE64_ENCODE

Encode text using the Base64 encoding algorithm.

operation: (text: any) => Buffer.from(text + '', 'utf8').toString('base64')

CAPITALIZE

Makes the first character of text uppercase and converts the remaining characters to lowercase.

operation: (value: any) => lodash.capitalize(value)

CEIL

Rounds up and returns the smallest integer greater than or equal to a given number.

operation: (n: any) => Math.ceil(n)

DAY

Returns the day from the given date or the current day if no date given (1-12).

operation: (d: any) => DateTime.fromMillis(d || DateTime.now().toMillis()).day

DOWNCASE

Makes each character in text lowercase.

operation: (value: any) => lodash.toLower(value)

FIRST

Returns the first element of a list.

operation: (value: any) => lodash.first(value)

FLOOR

Rounds down and returns the largest integer less than or equal to a given number.

operation: (n: any) => Math.floor(n)

FORMAT

Returns the date formatted according to the format string.

operation: (d: any, format: any, locale: any) => DateTime.fromMillis(d).toFormat(format, { locale: locale || 'en' })

HOUR

Returns the hour from the given date or the current hour if no date given (0-23).

operation: (d: any) => DateTime.fromMillis(d || DateTime.now().toMillis()).hour

INCLUDES

Returns TRUE if target (which can be text, an object, or an array) includes value otherwise returns FALSE.

operation: (haystack: any, needle: string) => lodash.includes(haystack, needle)

JSON_PARSE

Parses a serialized JSON value.

operation: (value: any) => JSON.parse(value)

LAST

Returns the last element of a list.

operation: (value: any) => lodash.last(value)

MAX

Returns the max value from the given args.

operation: (...args: any) => Math.max(...args)

MD5

Calculates the hex encoded MD5 hash of some text.

operation: (t: any) => crypto.createHash('md5').update(t + '').digest('hex')

MINUTE

Returns the minute from the given date or the current minute if no date given (0-59).

operation: (d: any) => DateTime.fromMillis(d || DateTime.now().toMillis()).minute

MONTH

Returns the month from the given date or the current month if no date given (1-12).

operation: (d: any) => DateTime.fromMillis(d || DateTime.now().toMillis()).month

NOW

Returns the current date and time.

operation: () => DateTime.now().toMillis()

PARSE

Parses a date formatted according to the format string.

operation: (d: string, format: any, locale: any) => DateTime.fromFormat(d, format, { locale }).toMillis()

ROUND

Returns the value of a number rounded to the nearest precision.

operation: (n: any, precision = 0) => Math.round(n * Math.pow(10, precision)) / Math.pow(10, precision)

SPLIT

Divides the input text into a list using the delimiter as a separator.

operation: (text: any, delimiter: any) => (text + '').split(delimiter + '')

STRINGIFY

Serializes a value into a JSON string.

operation: (value: any) => stringify(value, null, 0)

TODAY

Returns today's date with time set to 00:00.

operation: () => DateTime.now().startOf('day').toMillis()

TOMORROW

Returns tomorrow's date with time set to 00:00.

operation: () => DateTime.now().startOf('day').plus({ days: 1 }).toMillis()

TO_NUMBER

Converts a value to a number.

operation: (value: any) => value - 0

TO_STRING

Converts a value to string.

operation: (value: any) => value?.toString()

UUID

Generates a universally unique identifier (V4).

operation: () => uuid()

WEEKDAY

Get the day of the week. 1 is Monday and 7 is Sunday.

operation: (d: any) => DateTime.fromMillis(d || DateTime.now().toMillis()).weekday

YEAR

Returns the year from the given date or the current month if no date given.

operation: (d: any) => DateTime.fromMillis(d || DateTime.now().toMillis()).year

YESTERDAY

Returns yesterday's date with time set to 00:00.

operation: () => DateTime.now().startOf('day').plus({ days: -1 }).toMillis()

Custom functions

Some examples of custom functions:

  • 1 + 2

  • 1 + (2 * 3)

  • MAX(1,2)

  • a ? b : c

  • a.b.c.d

Operators

Operations encompass a range of actions, calculations, and data manipulations in the code. Using operators provides more dynamic and context-aware responses to your chatbot.

Precedence
Operator
Description
Associativity

1

()

Function call

Left-to-right

.

Qualified name or field access

[]

Indexing

2

- (unary)

Negation

Right-to-left

!

Logical NOT

3

*

Multiplication

Left-to-right

/

Division

%

Remainder

4

+

Addition

- (binary)

Subtraction

5

== != < > <= >=

Relations

6

&&

Logical AND

7

?:

Conditional

Right-to-left

Data types

We support a subset of JavaScript types to provide flexibility in your bot-building journey:

  • number

  • string

  • boolean

  • map

  • list

  • null

Expression syntax use cases

In this section, find some use case examples where expression syntax is used

Get the time

There are multiple ways that you can return information about time with expression syntax functions.

Get the current time

Imagine that you your bot to know or display the current time. Time is easy to retrieve with the following functions:

  • FORMAT() returns the time according to a string.

  • NOW() returns the current date and time based on the UTC timezone.

Combine these to create a function that returns the time with hours and minutes:

 {FORMAT(NOW(), "T")}

Get a UTC+1 timezone

Imagine a scenario where your end-users are located on a UTC+1 timezone. For them to know if your store is open now, your bot needs to determine what time it is in Belgium.

You can use the functions:

  • NOW() returns the current date and time based on the UTC timezone.

  • HOUR() extracts the hour from the current time.

  • HOUR(NOW()) extracts the hour component from the current UTC timezone.

  • +1 adds 1.

Combine these functions into the following custom expression:

{HOUR(NOW())+1}

This expression extracts the hour of the current UTC timezone and adds 1 to it so that it fits the Belgian time.

Downcase

Let's say that your customer has given its name in capital letters. You want to convert all the input characters to lowercase so that it can follow a standardized process.

  • DOWNCASE() converts all characters in a given text to lowercase.

  • @username is the variable name under which your customer name is saved.

Combine these elements into a custom function which downcases all the characters in your user name:

DOWNCASE(@userName)

Create a list

Let's say you have a message that consists in a list of elements which you would like to handle separately, for instance a list of pieces of fruit.

Your example message would be the following string:

"Apple Banana Orange"
  • SPLIT() divides a string into a list

  • FIRST() and LAST() retrieve the first and last elements of a list, respectively

Combine those functions so that you return the first and last element of the fruit list:

{FIRST(SPLIT("Apple Banana Orange"," "))}
{LAST(SPLIT("Apple Banana Orange"," "))}

🚨 Breaking changes

To ensure a smooth transition to expression syntax, it's crucial to address some breaking changes that might impact your current bot flows.

Variable name restriction

Existing variable names like a-b, a b, number or using '-' under Go to variables are not compatible anymore.

Please make sure to adjust your variable names according to the new expression syntax.

JavaScript identifier requirement

Removal of the| operator

The | operator is no longer supported. If it's part of your bot flow, make the necessary adjustments to align with the new syntax.

Before the upgrade, if your bot flow involved using the | operator, it might look like this:

notUnderstoodCounter|increment

With the expression syntax upgrade, the | operator is no longer be supported. Please modify your variable name.

JSON.stringif no longer compatible

Ensure to review your previous variables and confirm that none of them rely on JSON.stringify. Please use STRINGIFY or TO_STRING instead.

In this article, the term 'expression' refers to combining identifiers by using functions, operators, constants, and values when coding. Therefore, it should not be confused with the concept of in your NLP model.

Expression syntax can be used inside and , using specific , and .

Open your .

Use expression syntax within a statement as a .

Functions, whether or , form the backbone of expression syntax. They drive specific tasks and operations within the conversational flow of your chatbot.

You can create your own as you please, using the available .

To learn more about time formatting, have a look at .

Only valid JavaScript identifiers is supported. If your variables don't comply, tweak them now to avoid any hiccups. Refer to this documentation for guidelines.

🆕
expressions
Text steps
Conditions
data types
operators
functions
block
Condition
variable
Get the current time
Downcase
Create a list
built-in
custom
functions
operators
this table
detailed
contact support
breaking changes
Example of expression syntax within a text message.
Use functions of expression syntax inside a Text step
Use variable of expression syntax inside a Text step
Use a variable of expression syntax as a variable inside a Condition statement.
Use expression syntax to return the current time within a conversation.
Use a custom expression syntax to get the current time in your customer's timezone.
Use expression syntax to standardize your user input.
Retrieve list elements by using expression syntax.
Examples of variable names that are not compatible anymore with expression syntax.