Once you've created a JS scenario, its code can be used as a part of a chain of scenarios bound to one rule.
Each Voximplant application has a Routing tab where rules should be created. Rules group scenarios within an application and provide a way to start one or more scenarios to handle a single session. You can assign more than one scenario to a rule; therefore, those scenarios will be executed one by one in a similar way as web browsers execute scripts mounted on a web page.
Try to do the following: first, create two scenarios with the names of 01_foo_call and 02_foo_declaration accordingly:
Next, switch to the Routing tab, create a foo-test rule, and assign the created scenarios to it. Place them in one after another, as follows:
It's time to check how this rule operates: being in the Routing tab, click the Run rule button on the right, then click Run rule in the opened window. A notification of successful execution will appear.
Finally, go to the Call history tab and see the most recent log. You'll see no error there, both scenarios would be executed successfully.
Note that if the first scenario didn't have a timeout, its execution would have failed. This is so because VoxEngine:
- immediately executes all the lines of the first scenario;
- only then it switches to the second scenario and started to execute its lines of code.
Additionally, VoxEngine not only executes scenarios one-by-one, but it also merges them into one block of code, so during execution all the scenarios have a common lexical scope. This explains how it's possible to call a function in the first scenario whereas the function itself is declared in the consequent scenario(s).