com.webos.service.contextintentmgr
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:
- The CIM service interacts with an app and workflow (defined by the Workflow Designer toolkit).
- 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.
- The workflow is packaged with the app.
- The packaged app is then deployed on the device.
Overview of the API
Before using the service, you must:
- Include the webOS.js file in the app
- Add necessary permissions (cim.release) in the appinfo.json file (see below)
- "requiredPermissions":["cim.release"]
Methods
injectDataToWorkflow
Description
Injects data from the app to the workflow.
Parameters
Name | Required | Type | Description |
---|---|---|---|
key | Required | String | 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. |
data | Required | String | The actual data that must be sent to the workflow. It must be a stringified object. |
Call Returns
Name | Required | Type | Description |
---|---|---|---|
returnValue | Required | Boolean | Indicates the status of operation. Possible values are:
|
errorCode | Optional | Number | The error code for the failed operation. |
errorText | Optional | String | Indicates the reason for the failure of the operation. See the "API Error Codes Reference" section for details. |
result | Required | Object: result | Contains the result. |
Example
// 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.
var request = webOS.service.request("luna://com.webos.service.contextintentmgr/", {
method: "injectDataToWorkflow",
parameters: {
key: "6bb6c4ab.00e67c_128e776f.c57939", // Key generated in the data-inject node
data: <>
},
onSuccess: function (inResponse) {
console.log(inResponse);
},
onFailure: function (inError) {
console.log(inError);
},
onComplete: function (inResponse) {
console.log(inResponse);
},
subscribe: false,
resubscribe: false
});
getDataFromWorkflow
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 |
---|---|---|---|
key | Required | String | 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. |
subscribe | Required | Boolean | Subscribe for notifications when value changes. Possible values are:
|
Call Returns
Name | Required | Type | Description |
---|---|---|---|
returnValue | Required | Boolean | Indicates the status of operation. Possible values are:
|
errorCode | Optional | Number | The error code for the failed operation. |
errorText | Optional | String | Indicates the reason for the failure of the operation. See the "API Error Codes Reference" section for details. |
subscribed | Required | Boolean | Indicates if subscribed to get notified when there is a change in value.
|
result | Required | Object: result | Contains the result. |
Subscription Returns
Name | Required | Type | Description |
---|---|---|---|
subscribed | Required | Boolean | Indicates if subscribed to get notified when there is a change in value.
|
result | Required | Object: result | Contains the result. |
Example
// 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.
var request = webOS.service.request("luna://com.webos.service.contextintentmgr/", {
method: "getDataFromWorkflow",
parameters: {
key: "6bb6c4ab.00e67c_d89eafda.fe87f" // Key generated in the data-publish node
},
onSuccess: function (inResponse) {
console.log(inResponse);
},
onFailure: function (inError) {
console.log(inError);
},
onComplete: function (inResponse) {
console.log(inResponse);
},
subscribe: true, //subscription should be set to true
resubscribe: true
});
Objects
result
Contains the results.
Name | Required | Type | Description |
---|---|---|---|
data | Required | Object | Depending on the method:
|
API Error Codes Reference
Error Code | Error Text | Error Description |
---|---|---|
0 | Not a JSON data in the data-inject request. | The 'data-inject' request does not include JSON data. |
0 | Invalid call to API | Invalid call to API |
0 | Could not inject data | Could not inject the data. |
0 | Associated flow is disabled, calls to APIs does not work | This error is thrown when workflow is disabled. |
0 | Caller 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. |