Use formatters to manipulate your variables
Last updated: 05 January 2022
Data comes in all shapes and sizes.
Whether it is a date from an external software sent as DDMMYYYY
or a token hidden away behind a query string, when you need to access these data points, you need them in the right format.
Formatters allow you to do just that.
Everywhere you can use variables, you have a choice to use formatters to transform a value hidden inside a variable from one format to another.

Below, we dive into each formatter and illustrate them with use cases.
Date formatter
The date formatter allows you to convert any supported date-time format into a format of your choice.
What is the use case?
Imagine you are creating a chatbot capable of booking meetings using our date picker. Our date picker uses the following date format: dd-mm-yyyy
.
This is all well and good. But, if you need to send this date to an external software (a CRM, for example), they might require a yyyy-mm-dd
date format.
This is where the date formatter comes in.
As you enter your variable inside the integration, use the formatter to convert the original format (dd-mm-yyyy
) into the new one.

The date formatter supports the following date-time parameter strings:
String | Description | Example |
---|---|---|
Days | ||
| Day of the month with leading zeros |
|
| Three letter name of the day. |
|
| Day of the month without leading zeros. |
|
| Complete name of the day. |
|
| Numeric representation of the day of the week, starting at 1 for Monday. |
|
| English ordinal suffix for the day of the month, two characters. |
|
| Numeric representation of the day of the week, starting a 0 for Sunday. |
|
| The day of the year (starting from 0). |
|
Week | ||
| Number of the week in the year (weeks starting on Monday). | Example: |
Month | ||
| Complete name of the month. |
|
| Numeric representation of a month, two characters. |
|
| Three letter shortcut for the month of the year. |
|
| Numeric representation of a month, without leading zeros. |
|
| Number of days in the given month. |
|
Year | ||
| Boolean showing whether it is a leap year. |
|
| Week-numbering year. This has the same value as | Examples: |
| Numeric representation of a year, four digits. | Examples: |
| A two digit representation of a year. | Examples: |
Time | ||
| Lowercase am or pm. |
|
| Uppercase AM or PM. |
|
| Swatch Internet time |
|
| 12-hour format of an hour without leading zeros. |
|
| 24-hour format of an hour without leading zeros. |
|
| 12-hour format of an hour with leading zeros. |
|
| 24-hour format of an hour with leading zeros. |
|
| Minutes with leading zeros. |
|
| Seconds with leading zeros. |
|
| Microseconds. | Example: |
| Milliseconds. | Example: |
Timezone | ||
| Timezone name or identifier. | Examples: |
| Boolean showing whether or not the date is in daylight saving time. |
|
| Difference to Greenwich time (GMT) without colon between hours and minutes. | Example: |
| Difference to Greenwich time (GMT) with colon between hours and minutes. | Example: |
| The same as | Example: |
| Timezone abbreviation. | Examples: |
| Timezone offset in seconds. |
|
Full Date/Time | ||
| ISO 8601 date | 2004-02-12T15:19:21+00:00 |
| Date formatted using RFC 2822. | Example: |
| Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). |
Escape formatter
The escape formatter allows you to remove characters that might be interpreted as HTML code. To escape a variable, simply type |escape
after the variable name.
What is the use case?
Imagine your chatbot is about to grab a message sent by a user and send it to a third-party software. You want to make sure that characters such as &
and <
, which have a specific meaning in HTML, are instead understood as plain text.
Using the following formatter on the message
variable will format the content before sending it across to the external software: {{message.message|escape}}
.
Explode to JSON
The explode to JSON formatter allows you to convert a simple string of text into a JSON array. This may be explicitly required for some integrations.
What is the use case?
Imagine you are trying to send the following message from your chatbot to an external piece of software which requires it in JSON: one,two,three
Your API expects a JSON array, such as ["one","two","three"]
.
You can use this formatter to do exactly that: {{message.message|explode_to_json_array}}
Extract value formatter
The extract value formatter allows you to extract a value appended to a postback.
What is the use case?
Imagine your business sells five different services, such as gardening services, cleaning services, and so on. You are creating a chatbot that would allow users to book your services. This chatbot contains:
Five FAQs, one for each service.
One conversation, to capture the user’s personal details.
To go from an FAQ to the conversation, you cleverly use an action message and a postback such as enquire_services
. While this works perfectly, it would be quite cool to slightly modify the copy of the very first message inside the enquiry conversation to reflect which service the user was asking about originally.
With the value extract formatter, this is now possible.
Simple append the postback on each FAQ with from(cleaning services)
.

Then, inside your conversation’s first message, attach a variable {{message extract=from}}
to resurface the value inside from()
.

Number formatter
The number formatter allows you to format a number to up to 10 decimal places.
What is the use case?
Imaging you are capturing the budget of a potential customer through your lead generation chatbot. You offer them free rein to write their budget in any format they want, but you really prefer to display it with two decimal points.
This number formatter allows you to do just that: {{message.message|number_format(2)}}
Regex formatter
The extract value with regex formatter works like the extract value formatter, except it will grab the first item that matches the inputted regex.
Query parameters
The URL parameters formatter allows to extract a value behind the parameter of a URL.
What is the use case?
Imagine your chatbot lives on a page of your website. To get to that page, users need to log into your web portal. Once logged in, they are redirected to a page where they can interact with your chatbot. This page URL has the following format:
https://my-website.com/welcome?token=lwpl2aow12019kda
What you would really like to do is verify that every single user talking to your chatbot is actually logged in. The URL parameter formatter allows you to do that by extracting the value behind token=
. Once extracted, this token can be used in an integration to verify the user is, indeed, logged in.
Convert variable type formatter
The convert variable type formatter allows you to convert data format into another.
What is the use case?
Imagine you are setting up an integration. This integration allows you to capture data inside your chatbot and send it to an external software.
Alas, the data captured inside your platform adheres to a number format and the external software only accepts JSON format. Here comes the convert variable type formatter!
Use this formatter to change number, float, or JSON formats for another.
