The JavaScipt SDK allows add a custom chat experience to web pages. For example, you can use the JavaScript SDK to create your own web based chat widget.
The source code can be found on GitHub.
const teneoEngineUrl = 'https://some.teneo/engine-instance/';
const logResponse = (response) => {
console.log(response.output);
return response;
}
TIE.sendInput(teneoEngineUrl, null, {text: 'Hello there'})
.then(logResponse)
.then(() => TIE.sendInput(teneoEngineUrl, null, {text: 'How are you doing?'}))
.then(logResponse)
.then(() => TIE.close(teneoEngineUrl));
To use the Teneo JavaScript client api in a web project, the tie-client.js file needs to be added to your project. You can obtain it in the following ways:
You can download the latest release of the tie-client.js file from the releases on Github.
If you prefer to download the repository from github and compile the tie-client.js file yourself, proceed as follows:
Download or clone the SDK repository from Github:
git clone https://github.com/artificialsolutions/tie-api-client-js.git
Install dependencies:
npm install
Run the build script:
npm run build
You can now find tie-client.js file in the /dist folder.
If you have an existing project and you want to add the SDK to your project using NPM, run:
npm i @artificialsolutions/tie-api-client
Sends inputData to the url. Returns a Promise if no callback is provided.
TIE.sendInput(url: string, sessionId: string, inputData: object, [callback: function])
Parameter | Description |
---|---|
url | URL to a running engine instance. |
sessionId | Session id to be passed to the Teneo Engine instance. Pass null if unknown. |
inputData | Object containing input data. All keys except text will be sent to the Teneo Engine instance as extra parameters. |
callback(error: Error, response: TeneoEngineResponse) | Optional. Callback for handling the response from the Teneo Engine instance |
The inputData can look as follows:
{
text: "Some input text",
someParam: "foo",
anotherParam: "bar"
}
Closes the running (or specified session). Returns a Promise if no callback is provided.
TIE.close(url: string, sessionId: string, [callback: function])
Parameter | Description |
---|---|
url | URL to a running engine instance. |
sessionId | Session id to be passed to the Teneo Engine instance. Pass null if unknown. |
callback(error: Error, response: TeneoEngineResponse) | Optional. Callback for handling the response from the Teneo Engine instance. |
Returns a version of the Teneo Interaction Engine API with the Teneo Engine url prefilled.
const teneoApi = TIE.init('http://some.teneo/engine-instance/');
Once initialized, you no longer need to provide the url subsequent api calls. The same usage example as above then looks like this:
const teneoEngineUrl = 'https://some.teneo/engine-instance/';
const teneoApi = TIE.init(teneoEngineUrl);
const logResponse = (response) => {
console.log(response.output);
return response;
}
teneoApi.sendInput(null, {text: 'Hello there'})
.then(logResponse)
.then(() => teneoApi.sendInput(null, {text: 'How are you doing?'}))
.then(logResponse)
.then(() => teneoApi.close());
TIE.init(url: string)
Parameter | Description |
---|---|
url | URL to a running engine instance. |
Generally, you should not need to pass the session ID when using the API in the browser. Note however, Prevent cross-site tracking features in some browsers (like Safari) may prevent the browser from sending cookies to the Teneo engine when your site is hosted on a different domain than the Teneo engine. Manually passing on the engine session ID in the sendInput method will solve this.
Was this page helpful?