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 and Google Assistant.

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

Example usage

const TIE = require('@artificialsolutions/tie-api-client');

const teneoEngineUrl = 'https://some.teneo/engine-instance/';
const logResponse = (response) => {
  console.log(response.output);
  return response;
}

TIE.sendInput(teneoEngineUrl, null, { text: 'My name is John' })
  .then(logResponse)
  .then(({ sessionId }) => TIE.sendInput(teneoEngineUrl, sessionId, { text: 'What is my name?' }))
  .then(logResponse)
  .then(({ sessionId }) => TIE.close(teneoEngineUrl, sessionId));

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:

npm i @artificialsolutions/tie-api-client

API Documentation

TIE.sendInput

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

Signature

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

Parameters

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"
}

TIE.close

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

Signature

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

Parameters

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.

TIE.init

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

Signature

TIE.init(url: string)

Parameters

Parameter Description
url URL to a running engine instance.

Example

// Initialize engine with url
const teneoApi = TIE.init('http://some.teneo/engine-instance/');

// Once initialized, you no longer need to provide the url in subsequent api calls:
teneoApi.sendInput(null, { text: 'Sending some text to the prefilled url' })
    .then(response =>
      console.log(response);
      return teneoApi.close(response.sessionId);
    });

Was this page helpful?