How to use JavaScript
In the chat responses, you can use a script tag and thereby utilize JavaScript, allowing for almost limitless flexibility. In the chat responses, you can use a script tag and thereby utilize JavaScript, allowing for almost limitless flexibility.
Call a function from template
In this example, "Hello world!" will be displayed in the response. The word "world" here is sourced from the JavaScript section. This serves to illustrate how to use returned values from a JavaScript function within the template.
js
<template>
Hello {{script.Call "testFunction"}}!
</template>
<script>
function testFunction() {
return 'world';
}
</script>
Get a variable from template
In this example, "Hello world!" is rendered as the output. The word "world" is obtained directly from a JavaScript variable named "worldVariable". This demonstrates how to reference and utilize JavaScript variables within the template.
js
<template>
Hello {{script.Var "worldVariable"}}!
</template>
<script>
let worldVariable = 'world';
</script>