Intents

JavaScript

Registering Intents

Intents can be registered through the application configuration file. User defined application files are usually located in the %LocalAppData%\Tick42\UserData\<REG-ENV>\apps folder, where <REG-ENV> should be replaced by the region and environment of your Glue42 Enterprise copy (e.g., T42-DEMO). Intents can be configured under the intents top-level key of the application configuration file.

It is possible for several applications to register an Intent with the same name, which is useful when several applications can perform the same action or can work with the same data structure. This also allows for easy replacement of applications. You may have an old app that has registered an Intent called "ShowChart" which you want to replace with a new app. Your new app only needs to register the same Intent (you can either remove the old app or leave it as an additional option for the users who prefer it). You don't need to make any changes to the calling application - when it raises the "ShowChart" Intent, the new app will be called.

Below is an example configuration for an Intent:

"intents": [
    {
        "name": "ShowChart",
        "displayName": "BBG Instrument Chart",
        "contexts": ["Instrument"]
    }
]
  • name - Required. The name of the Intent;
  • displayName - The human readable name of the Intent. Can be used in context menus, etc., to visualize the Intent;
  • contexts - Required. The type of predefined data structures that the application can work with;

Finding Intents

You can search for registered Intents in several ways.

  • Find all registered Intents:
const allIntents = await glue.intents.all();
  • Find a specific Intent or all Intents that fit certain criteria:
const intents = await glue.intents.find("ShowChart");

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

  • name - name of the Intent to look for;
  • contextType - context type (pre-defined data structure - e.g., "Instrument") that the Intent handler works with;

If no argument is supplied, glue.intents.find() returns all registered Intents.

  • Find an Intent by context type:
const intents = await glue.intents.findByContext("Instrument");

The glue.intents.findByContext() method returns all Intents that work with the specified context type.

Raising Intents

Your calling application can use glue.intents.raise() to raise an Intent:

glue.intents.raise("ShowChart");

The glue.intents.raise() accepts a required string or an IntentRequest object as a parameter. The only required property of an IntentRequest is intent which should specify the name of the Intent to be raised.

Targeting Intent Handlers

When raising an Intent, you can 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: intentHandler.applicationName
}

glue.intents.raise(intentRequest);

You can also pass starting context to the Intent handler by using the context property which accepts an IntentContext object as a value:

const intentRequest = {
    intent: "ShowChart",
    target: intentHandler.applicationName
    context: {
        type: "Instrument",
        data: {
            // Context for the started application.
            selectedClientID: 1 
        }
    },
    // Specify application start options for the Intent handler.
    options: {
        width: 300,
        height: 200
    }
}

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 context object data to be passed to the Intent handler(s).

The options property of the Intent request can be used to pass custom ApplicationStartOptions to the Intent handler.

If no Intent handlers are specified, the first one will be called.

Intent Handler Instances

Sometimes you may want to spawn a new instance of an Intent handler each time the same Intent is raised. In other cases, you may want to handle that with only one instance of an Intent handler. You can use glue.intents.addIntentListener() to achieve that. This method listens for raised Intents targeted at your application. This way, an application will not be started again when the same Intent is raised more than once, but rather, it will only update the data (context):

function handleIntent (context) {
    // application specific logic here
}

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

If an Intent handler does not register an Intent listener, every time the same Intent is raised, a new instance of the Intent handler will be spawned.

Reference

Reference