Developer Docs

Touchpoint

Setup

The NLX Touchpoint widget provides a customizable chat interface that you can embed in your web applications. This widget allows users to interact with your application and provides a seamless conversational experience.

Quick Start

Add the following code to your HTML file:

1<!-- Touchpoint sample HTML --> 2<!-- Downloaded from https://developers.nlx.ai --> 3<html lang="en"> 4 <head> 5 <title>Touchpoint Sample HTML</title> 6 <meta name="viewport" content="width=device-width, initial-scale=1"> 7 </head> 8 <body> 9 <script defer src="https://unpkg.com/@nlxai/touchpoint-ui/lib/index.umd.js"></script> 10 <script> 11 const contentLoaded = () => { 12 if (document.readyState === "loading") { 13 return new Promise((resolve) => { 14 window.addEventListener("DOMContentLoaded", () => { 15 resolve(); 16 }); 17 }); 18 } else { 19 return Promise.resolve(); 20 } 21 }; 22 contentLoaded().then(() => { 23 return nlxai.touchpointUi.create({ 24 config: { 25 applicationUrl: "REPLACE_WITH_APPLICATION_URL", 26 headers: { 27 "nlx-api-key": "REPLACE_WITH_API_KEY" 28 }, 29 languageCode: "en-US" 30 }, 31 }) 32 }); 33 </script> 34 </body> 35</html>

Configuration Options

Required Fields

FieldTypeDescription
config.applicationUrlstringThe URL endpoint for your NLX bot
config.headers["nlx-api-key"]stringYour NLX API key

Core Optional Fields

FieldTypeDefaultDescription
config.languageCodestring"en-US"The language code for the chat interface
windowSize"half" | "full""half"Controls whether the chat window takes up half or full screen
colorMode"light" | "dark""dark"Sets the color theme of the widget
brandIconstringundefinedURL for your brand icon in the chat header
launchIconstringundefinedURL for the icon shown on the launch button
themeThemeSee ThemingCustom theme configuration

Component Configuration

The customModalities field connects your custom components to specific bot responses. Each key in this object maps to a component that handles that modality type.

FieldDescription
customModalitiesMaps modality types to their handling components

HTML Template Syntax

You can use the provided html function to create components in a more readable syntax. This function supports all available components listed below:

1import { html } from "@nlxai/touchpoint"; 2 3const MyComponent = () => { 4 return html` <BaseText>Hello World</BaseText> `; 5};

Available Components

These components can be imported and used within your custom modality components:

Display Components

ComponentDescription
BaseTextPrimary text component for main content
SmallTextSecondary text for supporting information
IconsStylized Icons

Layout Components

ComponentDescription
CarouselContainer for multiple card elements
CustomCardIndividual card component
CustomCardRowHorizontal layout within cards
CustomCardImageRowSpecialized row for image content

Interactive Components

ComponentDescription
TextButtonText-based button with optional icon
IconButtonIcon-only button for compact actions
DateInputComponent for date selection

Instance Methods and Properties

The async create() function returns a promise that will be fulfilled with a TouchpointInstance with these methods and properties:

Method/PropertyTypeDescription
expandedboolean (property)Gets or sets the expanded state of the chat widget
conversationHandlerobject (property)Returns the current conversation handler
teardown()functionRemoves the widget from the DOM

Example usage:

1import { create } from "@nlxai/touchpoint"; 2 3const touchpoint = await create({ 4 config: { 5 applicationUrl: 'YOUR_APPLICATION_URL"', 6 headers: { 7 "nlx-api-key": "your-api-key", 8 }, 9 }, 10}); 11 12// Toggle expanded state 13touchpoint.expanded = true; 14 15// Access conversation handler 16const conversationHandler = touchpoint.conversationHandler; 17 18// Remove widget 19touchpoint.teardown();