Skip to content

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

Screenshot

Schedule Tab

Screenshot

  • Note: Make sure to use 0 for seconds and minutes!

Speak Node Configuration

Screenshot

  • Listening resumes after the TTS on the client.
  • Use the Test... button to test the TTS.

Activating the Scenario

Screenshot

  • Scenario activation is performed in the Calendar node.

Adding an Action Node

Delete the Edge

  1. Delete the edge between the Speak node and the end node:
  2. Left-click on the edge.

    Screenshot

  3. Add an Action node in the editor.

  4. Rearrange the nodes to format the layout.
  5. Click on the parent node Speak and then on the child node Action.
  6. Click on the parent node Action and then on the child node End.
  7. The edge will be created.

Modifying the Speak Node

Screenshot

  • 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

Screenshot

  1. Enter a name for the action (e.g., getWeather).
  2. Select the client that sends the task.
  3. Leave the "client executing the task" selection empty (the executing client will be the same as the sending client).
  4. Choose the Meteomatics plugin.
  5. Modify the language parameter to the appropriate language code (for example, 'fr').
  6. 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:

  1. Open the meteomatics.js file from the meteomatics plugin in your favorite editor.
  2. Locate the action function.
  3. 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 via data.action (e.g., data.action.command).

  4. Add getWeather to the command parameter so that it conforms to what must be sent to the plugin.

  5. There is no need to check the Wait for the action to complete... box since this is the last node to execute.

  6. Click the "Test..." button to test the command.


Modifying the Action Node

Screenshot

  1. Add the byScenario parameter so that the execution order is preserved.
    (Refer to the Wait for the action to complete chapter for more information.)

  2. Check the Wait for the action to complete... box.


Adding a New Branch

Configuring the Calendar Node

Execution Tab

Screenshot

  1. Check By voice rule.
  2. Check Enable the rule.

Rule Tab

Screenshot

  1. Add the rule stop * alarm clock.
  2. 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.

  1. Add a Javascript node in the programmed branch between the Calendar node and the Speak node.
  2. 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 }
        };
    
    }
    

    Screenshot

    Expected result:

    Screenshot

  3. 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);
    
        }
    
    }
    

    Screenshot