Teneo Developers

Javascript

The JavaScipt SDK allows you to 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.

Usage example

javascript

1const teneoEngineUrl = 'https://some.teneo/engine-instance/';
2
3const logResponse = (response) => {
4  console.log(response.output);
5  return response;
6}
7
8TIE.sendInput(teneoEngineUrl, null, {text: 'Hello there'})
9  .then(logResponse)
10  .then(() => TIE.sendInput(teneoEngineUrl, null, {text: 'How are you doing?'}))
11  .then(logResponse)
12  .then(() => TIE.close(teneoEngineUrl));
13

Download options

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:

Download compiled tie-client.js

You can download the latest release of the tie-client.js file from the releases on Github.

Download source code and compile it yourself

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.

Use NPM to include the SDK in your project

If you have an existing project and you want to add the SDK to your project using NPM, run:

javascript

1npm i @artificialsolutions/tie-api-client
2

API Documentation

TIE.sendInput

Sends inputData to the url. Returns a Promise if no callback is provided.

Signature

javascript

1TIE.sendInput(url: string, sessionId: string, inputData: object, [callback: function])
2

Parameters

ParameterDescription
urlURL to a running engine instance.
sessionIdSession id to be passed to the Teneo Engine instance. Pass null if unknown.
inputDataObject 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:

javascript

1{
2  text: "Some input text",
3  someParam: "foo",
4  anotherParam: "bar"
5}
6

TIE.close

Closes the running (or specified session). Returns a Promise if no callback is provided.

Signature

javascript

1TIE.close(url: string, sessionId: string, [callback: function])
2

Parameters

ParameterDescription
urlURL to a running engine instance.
sessionIdSession 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.

TIE.init

Returns a version of the Teneo Interaction Engine API with the Teneo Engine url prefilled.

javascript

1const teneoApi = TIE.init('http://some.teneo/engine-instance/');
2

Once initialized, you no longer need to provide the url subsequent api calls. The same usage example as above then looks like this:

javascript

1const teneoEngineUrl = 'https://some.teneo/engine-instance/';
2const teneoApi = TIE.init(teneoEngineUrl);
3
4const logResponse = (response) => {
5  console.log(response.output);
6  return response;
7}
8
9teneoApi.sendInput(null, {text: 'Hello there'})
10  .then(logResponse)
11  .then(() => teneoApi.sendInput(null, {text: 'How are you doing?'}))
12  .then(logResponse)
13  .then(() => teneoApi.close());
14

Signature

javascript

1TIE.init(url: string)
2

Parameters

ParameterDescription
urlURL to a running engine instance.

Managing sessions

Generally, you should not need to pass the session ID when using the API in the browser. !!! Note however that Prevent cross-site tracking features in some browsers (like Safari and Firefox) 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.