Example Solutions
Page Objective
This solutions page provides detailed configuration guidance for each element added to the scenario. At every step, you can click on the "Check the configuration for this step" link to verify that your setup is correct.
Basic Example
Calendar Node Configuration
Execution Tab
Schedule Tab
- Note: Make sure to use 0 for seconds and minutes!
Speak Node Configuration
- Listening resumes after the TTS on the client.
- Use the
Test...
button to test the TTS.
Activating the Scenario
- Scenario activation is performed in the
Calendar
node.
Adding an Action Node
Delete the Edge
- Delete the edge between the
Speak
node and theend
node: -
Left-click on the edge.
-
Add an
Action
node in the editor. - Rearrange the nodes to format the layout.
- Click on the parent node
Speak
and then on the child nodeAction
. - Click on the parent node
Action
and then on the child nodeEnd
. - The edge will be created.
Modifying the Speak Node
- The new
Action
node must be executed after the complete vocalization of the TTS. - Tip: Check the box
Wait for TTS to finish...
Configuring the Action Node
- Enter a name for the action (e.g.,
getWeather
). - Select the client that sends the task.
- Leave the "client executing the task" selection empty (the executing client will be the same as the sending client).
- Choose the
Meteomatics
plugin. - Modify the
language
parameter to the appropriate language code (for example, 'fr'). - Modify the
command
parameter to call the function to be executed.
How to Modify the command
Parameter
Let's examine what the meteomatics
plugin needs for the function to be executed:
- Open the meteomatics.js file from the
meteomatics
plugin in your favorite editor. - Locate the
action
function. -
The weather call is made using:
- The parameter
data.action.command
- The key
getWeather
- The parameter
data.client
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
export async function action(data, callback) { try { Locale = await Avatar.lang.getPak("meteomatics", data.language); if (!Locale) { throw new Error (`meteomatics: Unable to find the '${data.language}' language pak.`); } // Table of actions const tblActions = { getWeather : () => getWeather(data.client, data.action?.byScenario, callback) } info("meteomatics:", data.action.command, L.get("plugin.from"), data.client); // Calls the function that should be run tblActions[data.action.command](); } catch (err) { if (data.client) Avatar.Speech.end(data.client); if (err.message) error(err.message); } if (!data.action?.byScenario) callback(); }
Important
The node automatically creates a
data.action
object and adds all the parameters specifically created for the plugin into this object. All these parameters will be available to the plugin viadata.action
(e.g.,data.action.command
). - The parameter
-
Add
getWeather
to thecommand
parameter so that it conforms to what must be sent to the plugin. -
There is no need to check the
Wait for the action to complete...
box since this is the last node to execute. -
Click the "Test..." button to test the command.
Modifying the Action Node
-
Add the
byScenario
parameter so that the execution order is preserved.
(Refer to the Wait for the action to complete chapter for more information.) -
Check the
Wait for the action to complete...
box.
Adding a New Branch
Configuring the Calendar Node
Execution Tab
- Check
By voice rule
. - Check
Enable the rule
.
Rule Tab
- Add the rule
stop * alarm clock
. - Use the
Translate
icon to convert the text into English if needed.
Configuring the Javascript Nodes
To verify if the scenario is active, there are several possibilities.
The simplest is to test a variable that we can add to the global Config object, named Config.scenarios["alarm clock"].enable, and then add a check in the Javascript function.
Since this variable does not exist yet, first modify the programmed branch of the scenario that triggers the alarm to add the configuration of this variable.
- Add a
Javascript
node in the programmed branch between theCalendar
node and theSpeak
node. -
Name the action
setAlarmVar
and add the following code to define the variable:1 2 3 4 5 6 7
async function setAlarmVar(payload, state){ Config.scenarios = { "alarm clock": { enable: true } }; }
Expected result:
-
Configure the
Javascript
node in the new branch to test the variable.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
async function isAlarmEnabled(payload, state){ if (Config.scenarios && Config.scenarios["alarm clock"] && Config.scenarios["alarm clock"].enable === true) { // Set the parameter to false to stop the loop // of all mp3 files Config.scenarios["alarm clock"].enable = false; // Stop the music Avatar.stop(state.client); } }