About

@nlxai/core is the lowest-level package used to handle bot communication in a completely headless, platform- and UI-agnostic way.

This package can be used to:

  • communicate with an application on a website without rendering a widget.

  • communicate with an application on a Node.js server, passing along responses to a third-party chat system.

Sample code

After installing the package, you can start a basic headless conversation using the following code snippet:

import { createConversation } from "@nlxai/core";

// Create some configuration
const config = {
  botUrl: "", // obtain from NLX deployments page
  headers: {
    "nlx-api-key": "", // obtain from NLX deployments page
  },
  conversationId: "", // start with a specific conversation ID - useful if you want to resume a previous conversation
  languageCode: "es-US", // optional language code for standard bots that do not run on US English
  environment: "production", // optional environment name for multi-environment bots to control which data request environment should be used.  "production" or "development" are the only supported values.
};

// Start the conversation
const convo = createConversation(config);

// Subscribe to changes in the list of responses; the newest response is sent as a second argument
convo.subscribe((responses, newResponse) => {
  console.log(responses);
});

// Send a message from the user's end
convo.sendText("hello");

Last updated