Intents

Overview

Available since Glue42 Enterprise 3.9

The Intents API is accessible through the glue.intents object.

See the JavaScript Intents example on GitHub.

Finding Intents

To find all registered Intents, use the all() method:

const allIntents = await glue.intents.all();

To get a collection of all Intents that fit certain criteria, use the find() method:

const intents = await glue.intents.find("ShowChart");

The find() method accepts a string or an IntentFilter object as an optional argument. The IntentFilter has the following optional properties:

Property Description
name Name of the Intent for which to search.
contextType Context type (pre-defined data structure - e.g., "Instrument") with which the Intent handler works.

If no filter is supplied, find() returns all registered Intents.

Raising Intents

To raise an Intent, use the raise() method:

await glue.intents.raise("ShowChart");

The raise() method accepts an Intent name as a string or an IntentRequest object as a required argument. The only required property of the IntentRequest object is intent which must specify the name of the Intent to be raised.

Targeting Intent Handlers

When raising an Intent, optionally target one or more Intent handlers using the target property of the IntentRequest object:

const intent = (await glue.intents.find("ShowChart"))[0];
const intentHandler = intent.handlers[0];

const intentRequest = {
    intent: "ShowChart",
    target: { app: intentHandler.applicationName }
}

await glue.intents.raise(intentRequest);

The target property of the IntentRequest object accepts the following values:

Value Description
"startNew" Will start a new instance of the first available Intent handler.
"reuse" Will reuse the first available running instance of an Intent handler or will fall back to "startNew" if there are no running instances available.
{ app?: string, instance?: string} An object with optional app and instance properties. The app property accepts an app name, the instance property - an ID of a running app instance. Provide a value for the app property to start a new instance of a specific Intent handler app. The app name is available in the applicationName property of the IntentHandler object. Provide a value for the instance property to reuse a specific running instance of an Intent handler. The ID of an Intent handler instance is available in the instanceId property of the IntentHandler object. Using this targeting option gives you full control over the choice of an appropriate Intent handler.

The default value for the target property is "startNew" when the Intent has been defined in an app configuration. If the Intent has been registered dynamically, the default value is "reuse".

The IntentHandler object has a type property which shows whether the Intent handler is an app that will be started (type: "app"), or an already running instance of an Intent handler (type: "instance").

Note that in order for the running Intent handler instance to be registered as type "instance", the app must use the addIntentListener() method in its code to handle context updates (see Handling Context Updates) or to register an Intent at runtime (see Registering Intents at Runtime). Otherwise, the running Intent handler instance will be of type "app".

Context

Passing Initial Context

To pass initial context to the Intent handler, use the context property of the IntentRequest object. It accepts an IntentContext object as a value:

const intentRequest = {
    intent: "ShowChart",
    target: "startNew",
    context: {
        type: "Instrument",
        data: {
            // Context for the started app.
            RIC: "MSFT"
        }
    },
    // Specify app start options for the Intent handler.
    options: {
        width: 300,
        height: 200
    }
}

await glue.intents.raise(intentRequest);

The type property of the IntentContext object is required and specifies the structure of the context object. The data property is the actual data to be passed to the Intent handler.

The options property of the IntentRequest object is used to pass custom ApplicationStartOptions to the Intent handler.

Handling Context Updates

To handle the context data passed when an Intent is raised and targeted at your app, use the addIntentListener() method. It has two required parameters - an Intent name and a context handler definition:

// Context handler definition.
function contextHandler (context) {
    // Check the context type.
    const contextType = context.type;

    if (contextType === "Instrument") {
        // Extract the context data.
        const data = context.data;
        // Аpplication specific logic for handling the new context data.
    };
};

glue.intents.addIntentListener("ShowChart", contextHandler);

Registering Intents at Runtime

To register an Intent at runtime, use the addIntentListener() method. Besides an Intent name, this method also accepts an object describing an Intent as a first required parameter:

// Intent definition.
const intent = {
    intent: "ShowChart",
    contextTypes: ["Instrument"],
    displayName: "Fidessa Instrument Chart",
    icon: "https://example.com/resources/icon.ico"
};

// Context handler.
function contextHandler (context) {
    // Check the context type.
    const contextType = context.type;

    if (contextType === "Instrument") {
        // Extract the context data.
        const data = context.data;
        // Аpplication specific logic for handling the new context data.
    };
};

glue.intents.addIntentListener(intent, contextHandler);

Note that when you register an Intent only at runtime (the Intent isn't defined in an app configuration), your app must be running in order to handle the Intent and it will always be of type "instance". If your app isn't running when this Intent is raised, it won't be available as a possible Intent handler.

Reference

For a complete list of the available Intents API methods and properties, see the Intents API Reference Documentation.