Web widget
Setup
The simplest way to talk to a bot is to include an out-of-the-box chat widget on your existing website.
1<!-- Chat widget sample HTML --> 2<!-- Downloaded from https://nlxai.github.io/chat-sdk --> 3<html lang="en"> 4 <head> 5 <title>NLX Widget 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/chat-widget/lib/index.umd.js"></script> 10 <script> 11 window.addEventListener("DOMContentLoaded", () => { 12 const widget = nlxai.chatWidget.create({ 13 config: { 14 botUrl: "REPLACE_WITH_BOT_URL", 15 headers: { 16 "nlx-api-key": "REPLACE_WITH_API_KEY" 17 }, 18 languageCode: "en-US" 19 }, 20 titleBar: { 21 "title": "Support chat" 22 }, 23 24 }); 25 }); 26 </script> 27 </body> 28</html>
In this snippet, the script is deferred in order to reduce impact on page speed. After the script is initialized, we use the nlxai.chatWidget
global to instantiate the widget. The following parameters are used:
config
: the bot configuration, including the bot URL obtained and headers obtained from the deployment of your bot.titleBar
: configuration for the header bar of the widget, containing the following fields:title
: the text content of the title, e.g. "Support chat".logo
: the static URL of a logo image that appears left of the title.
- Previous
- Introduction: Installation