How can I create dynamic content in my text messages?

You can create dynamic content (like a price) in the message, based on all that is stored on the users and what he or she has answered to questions such as a text or a number. This article shows you how.

We can create dynamic content with ICU Expressions:

ICU Expressions are used to format messages. They are used to insert context variables from the running conversation into a message template.

For example:

Hello from {country_name}!

If the country_name variable is "Norway", the message will be formatted as Hello from Norway!.

ICU Expressions also support displaying different text based on the value of a variable:

{country_name, select, Norway {Hello from Norway!} other {Hello from another country!}}

In this example, if the country_name variable is "Norway", the message will be formatted as Hello from Norway!, Otherwise, it will be formatted as Hello from another country!.

These can be chained together to create dynamic messages based on multiple variables:

Take the following price mode

Where are you from? Are you a student? Price
Norway Yes 100
Norway No 200
Sweden Yes 300
Sweden No 400
other other 500

The corresponding ICU Expression would be:

{country, select,
Norway {
{student, select,
Yes {Your price is 100}
No {Your price is 200}
other {Your price is 500}
}
}
Sweden {
{student, select,
Yes {Your price is 300}
No {Your price is 400}
other {Your price is 500}
}
}
other {Your price is 500}
}

If the user has answered these questions in the flow, the message will be formatted with the correct price.

Like smoc expressions, the questions and answers need to be the id of the question / answer:

question_1 question_2 Price
3 5 100
3 6 200
4 5 300
4 6 400
other other 500

The corresponding ICU Expression would be:

{question_1, select,
3 {
{question_2, select,
5 {Your price is 100}
6 {Your price is 200}
other {Your price is 500}
}
}
4 {
{question_2, select,
5 {Your price is 300}
6 {Your price is 400}
other {Your price is 500}
}
}
other {Your price is 500}
}

Tools

Creating ICU Expressions can be a bit tricky, so using tools to make them is recommended:

Variables

The variables available for ICU Expressions are the same as the ones available for SMOC Expressions