Teneo Developers

Node.js

You can use the Teneo JavaScript tie-api-client to chat with your bot from a Node.js application. You can use this to make your bot available on messenger platforms, like for example Facebook Messenger or Google Assistant. See Channels for more examples of connectors that make use of this SDK.

The source code and installation instructions can be found on GitHub.

Example usage

javascript

1const TIE = require('@artificialsolutions/tie-api-client');
2
3const teneoEngineUrl = 'https://some.teneo/engine-instance/';
4const logResponse = (response) => {
5  console.log(response.output);
6  return response;
7}
8
9TIE.sendInput(teneoEngineUrl, null, { text: 'My name is John' })
10  .then(logResponse)
11  .then(({ sessionId }) => TIE.sendInput(teneoEngineUrl, sessionId, { text: 'What is my name?' }))
12  .then(logResponse)
13  .then(({ sessionId }) => TIE.close(teneoEngineUrl, sessionId));
14

The example above first sends an input 'My name is John' to engine. Because this input does not contain a sessionId, engine will start a new session. The response contains a sessionId which is used when the second input 'What is my name?' is sent to engine. Lastly, the session is closed.

Note that when used as a Node.js module, you need to manually handle the session by passing the session ID to the API functions.

Installation

Ensure you have supported versions of Node and NPM installed (see the engines property in package.json). Then 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.

Signature

javascript

1TIE.init(url: string)
2

Parameters

ParameterDescription
urlURL to a running engine instance.

Example

javascript

1// Initialize engine with url
2const teneoApi = TIE.init('https://some.teneo/engine-instance/');
3
4// Once initialized, you no longer need to provide the url in subsequent api calls:
5teneoApi.sendInput(null, { text: 'Sending some text to the prefilled url' })
6    .then(response => {
7      console.log(response);
8      return teneoApi.close(response.sessionId);
9    });
10