npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@artificialsolutions/tie-api-client

v1.3.7

Published

Javascript SDK that handles communication with the Teneo Interaction Engine.

Downloads

1,409

Readme

TIE API Client for Javascript

This module provides a way of communicating with a Teneo Engine instance either on the server as a NodeJS module or in a browser loaded through a script node.

Usage

Node.js

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: 'Hello there' })
  .then(logResponse)
  .then(({ sessionId }) => TIE.sendInput(teneoEngineUrl, sessionId, { text: 'How are you doing?' }))
  .then(logResponse)
  .then(({ sessionId }) => TIE.close(teneoEngineUrl, sessionId));

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.

Browser

When using the API in the browser, you need to first have a bundled version of the API that you can load on the page. You can generate a bundled version of the API by executing the npm run build script (see section on local development). The bundled file will be placed in the /dist directory.

Example usage

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));

Gernerally, 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) 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 sendInput method will solve this.

A note on CORS

TIE API Client needs to send a cookie to the Teneo Engine instance in order for the session to be maintained. This requires CORS communication to be setup between the place where the TIE API Client is and the Teneo Engine instance. The TIE API Client handles this by sending the value of document.location.origin to the Teneo Engine instance as a parameter.

By default the Teneo Engine includes CORS headers in the responses to browser requests coming from any domain. This means any site can interact with a Teneo Engine. If you want to restrict your engine to only include CORS headers for specific domains, you can add a file called tieapi_cors_origins.txt to your solution. You can upload this file in Teneo Studio in the Teneo Resource Manager where you should add it to the views folder. The file should contain the list of allowed origin domains (one domain per line, domains should include port numbers if applicable).

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

url: URL to a running Teneo Engine instance.

sessionId: Session id to be passed to the Teneo Engine instance. Pass null if unknown.

inputData: An object taking the shape:

{
  text: "Some input text",
  someParam: "foo",
  anotherParam: "bar"
}

All properties 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.

TIE.close

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

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

url: URL to a running Teneo 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.

const teneoApi = TIE.init('https://some.teneo/engine-instance');
teneoApi.sendInput(null, { text: 'Sending some text to the prefilled url' })
  .then(response => {
    console.log(response);
    return teneoApi.close(response.sessionId);
  });
Signature
TIE.init(url: string)
Parameters

url: URL to a running Teneo Engine instance.

TeneoEngineResponse

Response from the Teneo Interaction Engine API.

Normal response:

{
  "status": 0,
  "input": {
	  "text": "input text",
	  "parameters": {}
	 },
   "output": {
	   "text": "output text",
	   "emotion":"",
	   "link":"",
	   "parameters": {}
	 },
   "sessionId": "current session id"
}

Error response:

{
  "status": -1,
  "input": {
    "text": "input text",
    "parameters": {}
  },
  "message": "ERROR MESSAGE"
}

Setting up the project for local development

  1. Ensure you have supported versions of Node and NPM installed (see the engines property in package.json)
  2. Run npm install
  3. Run npm test

Build tie-client.js

To create a version of tie-client.js that can be included in web based projects, run:

npm run build

The file will be added to the /dist folder.