The module concept

Modules are, along with Skills, the key building blocks of FurhatOS. A module is a class that receive and send asynchronous events. Examples of modules in the system are: voice recognizers, sensors and text-to-speak synthesizers. In other words, most components in the system that your application (or skills as they are called in the Furhat universe) talk to.

Creating modules

To create a new module, similar to how you can create a skill, you run the command furhat create module <module_name> [path]. You are recommended to add a path to a folder outside of the FurhatSDK repo but you are not required to do so. To import the module into Eclipse you have to run the command furhat eclipse in the package folder.

Subscribing to events

Modules by default receive all events the system distributes (except for events raised in flows with the <raise> tag). You can chose to only subscribe to a subset of events by using the subscribe() method (events are added with a space-separated string).

Acting on events

Modules implements an onEvent() method and can here chose to act on the events received and send it's own events to the system. An example implementation below:

// SomeModule.java

@Override
  public void onEvent(Event event) {

  // We have received an event from some other module,
  // check if we should react to it
  if (event.getName().equals("action.hello")) {

    // Do the hello here together with the parameter "text"
          System.out.println("Hello: " + event.get("text"));

          // Send a monitor event in response
          Event newEvent = new Event("monitor.hello");

          // Add the parameter text, if anyone should be interested
          newEvent.put("text", event.get("text"));

          // Send the event
          send(newEvent);
      }
  }

Bundling a module with a skill

Using the generate command above, you will create your module as a separate package. You can also bundle your module with a skill by

  1. Copying the module file to the skill src folder
  2. Adding the row <class type="iristk.system.IrisModule" name="iristk.addon.$PackageName$.$ClassName" /> to the <provide> part of the package.xml. Important: $PackageName$ is your skill's package name and $ClassName$ is the class name of your module.