Understanding the Syntax for SMOC Expressions in Decision Elements

Expressions
The bot currently supports two types of expressions:
- Smoc Expressions: Used in decision elements to decide where to go to next. Smoc Expressions always return numbers.
- ICU Expressions: Used in messages (text, buttons, etc) for dynamic content. ICU Expressions always return strings.
Smoc Expressions in decision elements
When the Smoc bot engine makes a decision about what edge to follow next,
it uses Smoc Expressions to assign a numeric score to each possible edge.
It then selects an edge to follow:
- If no edges have a positive score, no edge is followed.
- IMPORTANT: Always add a default edge with a score of
0.5
to ensure the bot does not get stuck.
- IMPORTANT: Always add a default edge with a score of
- If one edge has a higher score than all other edges, it will be followed.
- If multiple edges have the highest score, a random one amongst them is followed.
Smoc Expressions are infix arithmetic expressions.
Valid operators are +
, -
, *
and /
. You can also use (
and )
to group sub-expressions.
Each operand is either a number or a variable. Most variables expect a case insensitive argument following the =
sign.
For example:
2 * ${answer=34}
In this example, the first operand is 2
(a number), and the second operand is ${answer=34}
(a variable).
A variable evaluates to either 0
or 1
. The ${answer=34}
variable will evaluate to 1
only if the visitor
has given a survey question answer with the id 34
.
There are many Smoc Expression variables to choose from, and most of them represent facts we know about the visitor before
they have started interacting with the bot (such as geolocation, decive type, utm_
variables etc).
ICU Expressions in messages
ICU Expressions are used to format messages. They can reference context variables from the running conversation.
For example:
Hello from {country_name}!
If the country_name
variable is "Norway"
, the message will be formatted like this:
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 expressionscan be chained together to create dynamic messages based on multiple variables:
Take the following price model:
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 |
---|---|---|
answer_3 | answer_5 | 100 |
answer_3 | answer_6 | 200 |
answer_4 | answer_5 | 300 |
answer_4 | answer_6 | 400 |
other | other | 500 |
The corresponding ICU Expression would be:
{question_1, select,
answer_3 {
{question_2, select,
answer_5 {Your price is 100}
answer_6 {Your price is 200}
other {Your price is 500}
}
}
answer_4 {
{question_2, select,
answer_5 {Your price is 300}
answer_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:
ChatGPT is very proficient at creating ICU expressions from tables
After you have a ICU template you can test it out with this tool
Variables
The table below lists all the available Smoc Expression variables.
Name | Smoc Expression Example | ICU Expression Example | Description |
---|---|---|---|
accept_language |
${accept_language=some_accept_language} |
{accept_language} |
A string |
browser |
${browser=115} |
{browser} |
Browser identifier. See full list for all supported values (100+ options) |
city |
${city=some_city} |
{city} |
A string |
conversation_url |
${conversation_url=some_conversation_url} |
{conversation_url} |
A string |
country_name |
${country_name=some_country_name} |
{country_name} |
A string |
device_type |
${device_type=console} |
{device_type} |
Device type. See full list for all supported values |
lang |
${lang=da-DK} |
{lang} |
Language code. See full list for all supported values |
os |
${os=AIX} |
{os} |
Operating system. See full list for all supported values (100+ options) |
os_version |
${os_version=some_os_version} |
{os_version} |
A string |
referrer |
${referrer=some_referrer} |
{referrer} |
A string |
referring_domain |
${referring_domain=some_referring_domain} |
{referring_domain} |
A string |
region |
${region=some_region} |
{region} |
A string |
user_agent |
${user_agent=some_user_agent} |
{user_agent} |
A string |
utm_campaign |
${utm_campaign=some_utm_campaign} |
{utm_campaign} |
A string |
utm_content |
${utm_content=some_utm_content} |
{utm_content} |
A string |
utm_medium |
${utm_medium=some_utm_medium} |
{utm_medium} |
A string |
utm_source |
${utm_source=some_utm_source} |
{utm_source} |
A string |
utm_term |
${utm_term=some_utm_term} |
{utm_term} |
A string |
Browser Values
115
/ 2345
/ 360
/ Alipay
/ Amaya
/ Android Browser
/ Arora
/ Avant
/ Avast Secure Browser
/ AVG Secure Browser
/ Baidu Browser
/ Basilisk
/ Blazer
/ Bolt
/ Bowser
/ Brave
/ Camino
/ Chimera
/ Chrome
/ Chrome Headless
/ Chrome WebView
/ Chromium
/ Cobalt
/ Coc Coc
/ Conkeror
/ Dillo
/ Dolphin
/ Doris
/ Dragon
/ DuckDuckGo
/ Edge
/ Epiphany
/ Facebook
/ Falkon
/ Fennec
/ Firebird
/ Firefox
/ Firefox Focus
/ Firefox Reality
/ Flock
/ Flow
/ GoBrowser
/ GSA
/ Helio
/ HeyTap
/ Honor
/ Huawei Browser
/ iCab
/ ICE Browser
/ IceApe
/ IceCat
/ IceDragon
/ IceWeasel
/ IE
/ Instagram
/ Iridium
/ Iron
/ Jasmine
/ K-Meleon
/ KakaoTalk
/ KHTML
/ Kindle
/ Klar
/ Klarna
/ Konqueror
/ LBBROWSER
/ LibreWolf
/ Line
/ LinkedIn
/ Links
/ Lunascape
/ Lynx
/ Maemo Browser
/ Maxthon
/ Midori
/ Minimo
/ MIUI Browser
/ Mobile Chrome
/ Mobile Firefox
/ Mobile Safari
/ Mosaic
/ Mozilla
/ Naver
/ NetFront
/ Netscape
/ Netsurf
/ Nokia Browser
/ Obigo
/ Oculus Browser
/ OmniWeb
/ Opera
/ Opera Coast
/ Opera Mini
/ Opera Mobi
/ Opera Tablet
/ Opera Touch
/ OviBrowser
/ PaleMoon
/ PhantomJS
/ Phoenix
/ Pico Browser
/ Polaris
/ Puffin
/ QQBrowser
/ QQBrowserLite
/ Quark
/ QupZilla
/ rekonq
/ Rockmelt
/ Safari
/ Sailfish Browser
/ Samsung Internet
/ SeaMonkey
/ Silk
/ Skyfire
/ Sleipnir
/ SlimBoat
/ SlimBrowser
/ Slimjet
/ Smart Lenovo Browser
/ Snapchat
/ Sogou Explorer
/ Sogou Mobile
/ Swiftfox
/ Tesla
/ TikTok
/ Tizen Browser
/ Twitter
/ UCBrowser
/ UP.Browser
/ Vivaldi
/ Vivo Browser
/ w3m
/ Waterfox
/ WebKit
/ WeChat
/ Weibo
/ Whale
/ Wolvic
/ Yandex
Device Type Values
console
/ desktop
/ embedded
/ mobile
/ smarttv
/ tablet
/ wearable
/ xr
Language Values
da-DK
/ en-GB
/ es-ES
/ fi-FI
/ nb-NO
/ sv-SE
Operating System Values
AIX
/ Amiga OS
/ Android
/ Android-x86
/ Arch
/ Bada
/ BeOS
/ BlackBerry
/ CentOS
/ Chrome OS
/ Chromecast
/ Chromecast Android
/ Chromecast Fuchsia
/ Chromecast Linux
/ Chromecast SmartSpeaker
/ Contiki
/ Debian
/ Deepin
/ DragonFly
/ elementary OS
/ Fedora
/ Firefox OS
/ FreeBSD
/ Fuchsia
/ Gentoo
/ GhostBSD
/ GNU
/ Haiku
/ HarmonyOS
/ HP-UX
/ Hurd
/ iOS
/ Joli
/ KaiOS
/ Linpus
/ Linspire
/ Linux
/ macOS
/ Maemo
/ Mageia
/ Mandriva
/ Manjaro
/ MeeGo
/ Minix
/ Mint
/ Morph OS
/ NetBSD
/ NetRange
/ NetTV
/ Nintendo
/ OpenBSD
/ OpenHarmony
/ OpenVMS
/ OS/2
/ Palm
/ PC-BSD
/ PCLinuxOS
/ Pico
/ Plan9
/ PlayStation
/ QNX
/ Raspbian
/ RedHat
/ RIM Tablet OS
/ RISC OS
/ Sabayon
/ Sailfish
/ SerenityOS
/ Series40
/ Slackware
/ Solaris
/ SUSE
/ Symbian
/ Tizen
/ Ubuntu
/ Unix
/ VectorLinux
/ watchOS
/ WebOS
/ Windows
/ Windows Mobile
/ Windows Phone
/ Xbox
/ Zenwalk