com.webos.service.contextintentmgr

Note
This API has been available since API level 11.

API Summary

CIM is a service that adds AI logic to your web app, without actually modifying its source code. This makes your web app context-aware and therefore provide a better experience to your customers.

How does it work:

  1. The CIM service interacts with an app and workflow (defined by the Workflow Designer toolkit).
  2. The workflow must specify:
    • The AI engine to be used.
    • The condition, and the action to be performed when that condition is satisfied.
    • Whether the app and workflow need to share data.
      • If yes, then the workflow must include the 'data-inject' and/or 'data-publish' nodes.
      • The app must correspondingly invoke the 'injectDataToWorkflow' and/or 'getDataFromWorkflow' methods.
  3. The workflow is packaged with the app.
  4. The packaged app is then deployed on the device.

Before using the Service

Add necessary permissions (cim.release) in the appinfo.json file (see below)

  • "requiredPermissions":["cim.release"]

Overview of the API

NA

 

    Methods

    getDataFromWorkflow

    ACG: contextintent.operation
    • Added: API level 11

    Description

    Publishes data from the workflow to the app.

    The data can be consumed by an app which has subscribed to it.

    Parameters

    Name

    Required

    Type

    Description

    keyRequiredString

    Identifies the 'data-publish' node that is defined in the workflow.

    Note: Make sure that the key is associated with the relevant 'data-publish' node.

    subscribeRequiredBoolean

    Subscribe for notifications when value changes. Possible values are:

    • true - Get notifications
    • false - Notifications are not required

    Call Returns

    Name

    Required

    Type

    Description

    returnValueRequiredBoolean

    Indicates the status of operation. Possible values are:

    • true - Indicates that the operation was successful.
    • false - Indicates that the operation failed. Check the "errorCode" and "errorText" fields for details.
    errorCodeOptionalNumber

    The error code for the failed operation.

    errorTextOptionalString

    Indicates the reason for the failure of the operation. See the "API Error Codes Reference" section for details.

    subscribedRequiredBoolean

    Indicates if subscribed to get notified when there is a change in value.

    • true - Subscribed for changes
    • false - Not subscribed
    resultRequiredObject: result

    Contains the result.

    Subscription Returns

    Name

    Required

    Type

    Description

    subscribedRequiredBoolean

    Indicates if subscribed to get notified when there is a change in value.

    • true - Subscribed for changes
    • false - Not subscribed
    resultRequiredObject: result

    Contains the result.

    Example

    Example scenario

    // This API must be called within an app. Below is a sample app code snippet. Do not try to run the code directly from the terminal as it will fail.

    function getDataFromWorkflow(){
        var bridge = new WebOSServiceBridge();
        var url = 'luna://com.webos.service.contextintentmgr/getDataFromWorkflow';

        bridge.onservicecallback = callback;

        function callback(msg){
            var response = JSON.parse(msg);
            console.log(response.returnValue);
        }

        var params = '{key: "6bb6c4ab.00e67c_d89eafda.fe87f" }';// Key generated in the data-publish node
        bridge.call(url, params);
    }

    injectDataToWorkflow

    ACG: contextintent.operation
    • Added: API level 11

    Description

    Injects data from the app to the workflow. 

    Parameters

    Name

    Required

    Type

    Description

    keyRequiredString

    Identifies the 'data-inject' node that is defined in the workflow. 

    Note: Make sure that the key is associated with the relevant 'data-inject' node.

    dataRequiredString

    The actual data that must be sent to the workflow. It must be a stringified object.

    Call Returns

    Name

    Required

    Type

    Description

    returnValueRequiredBoolean

    Indicates the status of operation. Possible values are:

    • true - Indicates that the operation was successful.
    • false - Indicates that the operation failed. Check the "errorCode" and "errorText" fields for details.
    errorCodeOptionalNumber

    The error code for the failed operation.

    errorTextOptionalString

    Indicates the reason for the failure of the operation. See the "API Error Codes Reference" section for details.

    resultRequiredObject: result

    Contains the result.

    Example

    Example scenario

    // This API must be called within an app. Below is a sample app code snippet. Do not try to run the code directly from the terminal as it will fail.

    function injectDataToWorkflow(){
        var bridge = new WebOSServiceBridge();
        var url = 'luna://com.webos.service.contextintentmgr/injectDataToWorkflow';

        bridge.onservicecallback = callback;

        function callback(msg){
            var response = JSON.parse(msg);
            console.log(response.returnValue);
        }

        var params = '{
          key: "6bb6c4ab.00e67c_128e776f.c57939", // Key generated in the data-inject node 
          data: <>
        }';
        bridge.call(url, params);
    }

    Objects

    result

    Contains the results.

    Name

    Required

    Type

    Description

    dataRequiredObject

    Depending on the method:

    • For injectDataToWorkflow: It is the same data that is sent in the input of the method.
    • For getDataFromWorkflow: The data that is published from the flow (the msg object of the flow).
    • Example:
      {
          data: {
              payload: {
                  winner: undefined,
                  depth: 8,
                  nextBestGameState: ['X', '', '', '', 'O', '', '', '', '']
              },
              _msgid: 'bb8697a9.d885e8'
          }
      }

    API Error Codes Reference

    Error Code

    Error Text

    Error Description

    0Not a JSON data in the data-inject request.

    The 'data-inject' request does not include JSON data.

    0Invalid call to API

    Invalid call to API

    0Could not inject data

    Could not inject the data.

    0Associated flow is disabled, calls to APIs does not work

    This error is thrown when workflow is disabled.

    0Caller does not have permission for this API.

    This error is thrown when the calling application does not include a 'data-inject' or 'data-publish' node with the specified key.

    Contents