JavaScript
More advanced users are able use JavaScript, instead of Expression language.
Where to use JS
Just like Expression language, you can use JS in:
- Bot responses
- Output Conditions in every block that has them
- Conditional responses and Conditions in Say conditional block
- Memory values
- Commands params
- Integration input params (if needed - it depends on the integration type)
- and Metadata item values
How to use JS in bot responses
To enable JavaScript in bot responses, start by typing: ${ \\some code }
.

This is what this response looks like in a bot:

How to use JS in other fields
To enable JS in other fields use the Enable JavaScript toggle above the text editor.

Below you can find a complete example of using JS in Output conditions:

Multi-line editor
It's a joy to use JS thanks to our beautiful multi-line editor!

More complex code
If you wish to write more complex code that contains assignments, loops or functions, you have to put it in a function using this exact snippet:
(function() {
// put your code here
// remember to return the result
})()
(function() {
const fruitArray = [{name: "Apple", price: 10}, {name: "Grape", price: 5}, {name: "orange", price: 15}];
const moreFruitsArray = [...fruitArray, {name: "lemon", price: 2}];
const onStockFruits = moreFruitsArray.map(el => ({...el, available: true}));
const prettyPrint = (fruit) => {
return "Fruit: " + fruit.name + " price: " + fruit.price + " on stock: " +fruit.available;
};
return onStockFruits
.map(prettyPrint)
.join("\n");
})()
Fruit: Apple price: 10 on stock: true
Fruit: Grape price: 5 on stock: true
Fruit: orange price: 15 on stock: true
Fruit: lemon price: 2 on stock: true
Looking for help with JS?
See JavaScript Guide by MDN - an overview of the language.
Updated about 2 months ago