Integrating with WebOS
This guide provides instructions on how to integrate the AI Gateway Module into your WebOS application using the provided aigw.js and associated service.
Don't forget to generate your AI Gateway Module API Key and download Module from Developers dashboard first.
Prerequisites
x
- WebOS development environment set up
- Basic knowledge of WebOS app development
- AI Gateway Module files (
aigw.jsand service files)
Integration Steps
1. Add Module Files
- Copy
aigw.jsto your app's directory. - Add the service files to your project's
servicedirectory.
2. Include the Module in your app
In your main HTML file (e.g., index.html), include the Module:
<script src="path/to/aigw.js"></script>
3. Initialize the Module
To initialize the AI Gateway Module, you need to create an instance of the AIGW class with your API key. Here's an example of how to do this in your main JavaScript file:
var instance = new AIGW({
apiKey: 'your-api-key-here'
});
4. Use methods of Module
Once you have initialized the Module, you can use its methods to interact with the AI Gateway service. Below are the methods provided by the class:
instance.start() // Starts Module if opted in or consented
instance.stop() // Stops Module
instance.optIn() // Opts in without showing consent screen
instance.optOut() // Opts out and stops Module
instance.requestConsent() // Shows consent screen
instance.isOptedIn() // Returns a boolean
instance.isRunning(function (isRunning) {}) // Returns a callback with boolean
// event listeners
instance.on('consent', function (consent) {
console.log('Consent received:', consent);
});
instance.on('running', function (running) {
console.log('AI Gateway is running:', running);
});
5. Update service configuration files
To ensure that the Module can find and use the service, you need to update two configuration files: package.json and services.json.
Update package.json
Update the service package.json file according to your application. Change the name value to have a suffix of .ai_gw_module_service.
For example, if the app id is com.aigw.app, package.json should be updated as such:
{
"name": "com.aigw.app.ai_gw_module_service",
// ...
}
Update services.json
Similarly, update the services.json file to match your application's identifier. The id and name fields should be updated to include the .ai_gw_module_service suffix, matching the package.json file.
For example, if your app id is com.aigw.app, the services.json file should be updated as follows:
{
"id": "com.aigw.app.ai_gw_module_service",
"description": "AIGW module",
"services": [
{
"id": "com.aigw.app.ai_gw_module_service",
"name": "com.aigw.app.ai_gw_module_service",
// ...
}
]
}
6. Package the app with service
To package your WebOS app with the AI Gateway Module service, follow these steps:
- If you do not have a service besides AI Gateway Module, ensure your app directory structure looks like this:
your-app/
├── app/
│ ├── index.html
│ ├── aigw.js
│ └── ... (other app files)
├── service/
│ ├── package.json
│ ├── services.json
│ └── service.js
└── appinfo.json
If you have more, it should look like this:
your-app/
├── app/
│ ├── index.html
│ ├── aigw.js
│ └── ... (other app files)
├── service/
│ ├── service1/
│ │ ├── package.json
│ │ ├── services.json
│ │ └── service.js
│ ├── service2/
│ │ ├── package.json
│ │ ├── services.json
│ │ └── service.js
│ └── ... (other service folders)
└── appinfo.json
-
Package your app using the ares-package command:
ares-package ./app ./serviceThis command will create a
.ipkfile in your current directory. -
Install the packaged app on your WebOS device or emulator:
ares-install --device <your-device-name> <your-app-name>.ipk -
Launch the app:
ares-launch --device <your-device-name> <your-app-id>
Logging
To enable logging to console by default, you can set the enableLogging option to true when creating the Module instance:
var instance = new AIGW({
apiKey: 'your-api-key-here',
enableLogging: true,
});
This will log all Module events to the console, including session start, stop, and heartbeat events. You can also customize the logging by providing a custom logger function that takes a message as an argument. This allows you to log messages to a file or any other logging service of your choice.
var instance = new AIGW({
apiKey: 'your-api-key-here',
enableLogging: true,
loggerCallback: function (message) {
// Custom logging logic
// For example, log to a file or send to a logging service
console.log(message);
}
});
Example log messages include:
info: Session started <session-id>
info: Heartbeat received
info: Heartbeat sent
info: Session stopped
error: Unable to resolve host
error: Unable to connect to server
Conclusion
By following these steps, you'll successfully package your WebOS app with the AI Gateway Module service. The service will run in the background, allowing your app to interact with it using the Module methods described earlier.
Remember to replace com.aigw.app with your actual app ID, and adjust other fields in the appinfo.json file as necessary for your specific application.
If you have any questions or encounter issues during integration, please reach out to us at [email protected] for support. Happy coding!