Skip to main content

script

Description

script — reaction scripts can execute functions and other pieces of conversation business logic, make external system calls, interact with data storages, etc.

Value type

  • multiline string — valid JavaScript code

Parameters

  • none

Nested data

  • multiline data

Syntax

Use JavaScript (ECMAScript 5 revision) in the script tag body. Scripts can be specified:

  • Directly in the state.
require: name/nameEn.sc
module = sys.zb-common

theme: /

state: Hello
q!: * my name is $Name *
script:
$session.name = $parseTree._Name.name;
a: Hi, {{$session.name}}!
  • With a function call. In this case, declare the function in a separate JS file and call it from the state after the script tag.

For example, declare a script in a JS file called functions.js:

function setName(value) {
var $session = $jsapi.context().session;
$session.name = value;
}

Import the file into the script to call the function from the state:

require: name/nameEn.sc
module = sys.zb-common

require: functions.js

theme: /

state: Hello
q!: * my name is $Name *
script:
setName($parseTree._Name.name);
a: Hi, {{$session.name}}!