Jovo Properties

Jovo properties are reserved variables that part of the Jovo this object.

Introduction

The Jovo context object (also referenced as this) includes many properties that are instantiated with each request.

In the this context, you can access them like this:

this.$propertyName;

// Example: $request
this.$request;

The properties can be grouped into RIDR, input, and context properties.

RIDR Properties

Jovo app execution follows the RIDR lifecycle that includes four steps: request, interpretation, dialogue & logic, response.

Each of the steps result in a Jovo property: $request, $input, $output, $response.

$request

The $request property contains all information about a request. It is the result of the first step of the RIDR lifecycle.

this.$request;

$input

The $input property contains structured data that is derived from a request. For example, speech recognition (ASR) and natural language understanding (NLU) data. It is the result of the second step of the RIDR lifecycle.

this.$input;

Learn more about the $input property here.

$output

The $output array contains one or more structured output templates that are later turned into one or more native platform responses. It is the result of executing a handler and the third step of the RIDR lifecycle.

this.$output;

Learn more about the $output array here.

$response

The $response property contains the native response that gets sent back to the platform. It is the result of the fourth step of the RIDR lifecycle.

this.$response;

Input Properties

Alongside $input, there are additional properties that contain interpreted information about the user's request.

The properties include $entities and $route.

$entities

The $entities property contains entities as part of the structured input.

this.$entities;

$route

The $route property is the result of the routing process.

this.$route;

Learn more about routing here.

Context Properties

Context properties contain information that was not explicitly stated by the user, but rather information accompanying the request.

The properties include $id, $data, $session, $user, $device, and $history.

$id

The $id property is a unique identifier for each request going through the RIDR Lifecycle. This could be used for logging or analytics integrations, for example.

this.$id;

The value is either retreived from the $request object (if the platform provides a request ID) or generated using UUID v4.

$data

The $data property allows you to store data for the current request.

this.$data;

Learn more about request data here.

$session

The $session property contains data and features about the current session.

this.$session;

One of the most used features of $session is to write and access session data:

this.$session.data.key = value;

Learn more about session data here.

$state

The $state property is the state stack that gets built as part of the routing and state management.

this.$state;

Learn more about the $state stack here.

$user

The $user property contains data and features about the specific user interacting with the app.

this.$user;

One of the most used features of $user is to write and access data that is persisted in a user database:

this.$user.data.key = value;

Learn more user data here.

$device

The $device property contains data and features about the specific device the user is interacting with.

this.$device;

Learn more about the $device property here.

$history

The $history property contains data about previous user interactions.

this.$history;

Learn more about the $history property here.

$server

The $server property contains data and features about the server requests and responses.

this.$server;

Learn more about the $server property here.

Custom Properties

You can also add your own properties to the Jovo object, for example:

this.$myProperty;

Here is an example Jovo plugin implementation that adds $myProperty to the Jovo object and also adds type declarations:

// MyPropertyPlugin.ts

import {
  Jovo,
  HandleRequest,
  Plugin,
  PluginConfig,
  Extensible,
  InvalidParentError,
} from '@jovotech/framework';

// Add the $myProperty type to the Jovo class
declare module '@jovotech/framework/dist/types/Jovo' {
  interface Jovo {
    $myProperty: MyPropertyPlugin;
  }
}

export class MyPropertyPlugin extends Plugin {
  mount(extensible: Extensible) {
    if (!(extensible instanceof HandleRequest)) {
      throw new InvalidParentError(this.constructor.name, HandleRequest);
    }

    // Add the $myProperty property to the Jovo object
    extensible.middlewareCollection.use('before.request.start', (jovo) => {
      jovo.$myProperty = new MyPropertyPlugin(this);
    });
  }

  // Sample method that can be called using $myProperty
  myFunction(jovo: Jovo) {
    // ...
  }

  getDefaultConfig(): PluginConfig {
    return {};
  }
}

As a result, you can use this in your handler:

this.$myProperty.myFunction();

You can also take a look at the Slack plugin for an example.