Integrating with Tizen
This guide provides instructions on how to integrate the AI Gateway Module into your Tizen application using the provided files and associated service.
Don't forget to generate your AI Gateway Module API Key and download Module from Developers dashboard first.
Prerequisites
- Tizen development environment set up
- Basic knowledge of Tizen app development
- AI Gateway Module files (
background.js)
Integration Steps
1. Add Module Files
Copy background.js files to your application source directory.
2. Include the Module background service in your config.xml file
In your application config file (e.g., config.xml), include the Module background service inside of a <widget> element:
<tizen:service id="<yourpackage>.BackgroundService">
<tizen:content src="<path/to/background.js>" />
<tizen:name>BackgroundService</tizen:name>
<tizen:description>Service Application</tizen:description>
<tizen:metadata key="meta-key" value="meta-value" />
<tizen:category name="http://tizen.org/category/service" />
</tizen:service>
- Replace
<yourpackage>with your package name. - Replace
<path/to/background.js>with path to your copiedbackground.jsfile.
Please remember this service id value as it going to be needed in further steps.
3. Include the Module in your app
In your main HTML file (e.g., index.html), include the Module(.js file):
<script src="path/to/module.js"></script>
4. 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>',
backgroundServiceId: '<background-service-id>',
applicationId: '<your-application-id>'
});
- Replace
<your-api-key>with API key you got while creating the app. - Replace
<background-service-id>with id from step #2. - Replace
<your-application-id>with application id from yourconfig.xmlfile.
IMPORTANT! If invalid configuration is provided initialization throws error so you should wrap this inside of a try block.
5. 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.isRunning() // Returns a boolean status is Module already running
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
IMPORTANT! If user is not opted in start method throws an error so you should wrap it's call inside of a try block.
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>',
backgroundServiceId: '<background-service-id>',
applicationId: '<your-application-id>',
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>',
backgroundServiceId: '<background-service-id>',
applicationId: '<your-application-id>',
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
After completing these steps you should have successful integration of the AI Gateway Tizen Module in your application.
If you'd still encounter any issues or have questions, you can always reach out to us at [email protected] for additional support.