Touchpoint Guides
Conversation Handler
The Touchpoint SDK provides access to the ConversationHandler through the Touchpoint Instance returned from the top-level create method.
Accessing the ConversationHandler
1import { create } from "@nlxai/touchpoint-ui"; 2// Instantiate touchpoint with your configuration options 3const touchpointOptions = { 4 config: { 5 applicationUrl: "YOUR_APPLICATION_URL", 6 headers: { "nlx-api-key": "YOUR_API_KEY" }, 7 languageCode: "en-US", 8 }, 9}; 10const touchpoint = await create(touchpointOptions); 11 12// Access conversationHandler 13const conversationHandler = touchpoint.conversationHandler;
Examples
Touchpoint can be configured with a number of custom behaviors with the ConversationHandler.
Example 1: Open Touchpoint after user inactivity
1// Simple countdown to show Touchpoint 2const showTouchpointAfterInactivity = (seconds) => { 3 let remaining = seconds; 4 5 const countdown = setInterval(() => { 6 remaining--; 7 8 if (remaining <= 0) { 9 // Clear the interval 10 clearInterval(countdown); 11 12 // Open Touchpoint 13 touchpoint.expanded = true; 14 } 15 }, 1000); 16}; 17 18// Start a 30 second countdown 19showTouchpointAfterInactivity(30);
Example 2: Detecting Modalities in Conversation Responses
Uses subscribe to listen for a modality named "MapDirections".
1const myListenerFunction = (history, message) => { 2 // Only process if we have a new bot message 3 if (!message || message.type !== "bot") return; 4 const modalities = message.payload?.modalities; 5 if (!modalities) return; 6 if (modalities.MapDirections) console.log(modalities.MapDirections); 7}; 8 9// Start listening to the conversation 10conversationHandler.subscribe(myListenerFunction);