ChatBot
- Last Updated: May 5, 2026
- 4 minute read
- MarkLogic Server
- Documentation
The FastTrack ChatBot widget displays an interactive console that lets a user participate in a chat session with a large language model (LLM) by accepting text prompts and returning natural human-like responses to those prompts. By connecting the ChatBot to a backend that leverages the AI capabilities of MarkLogic RAG (Retrieval Augmented Generation), it receives contextually relevant responses with fewer inaccuracies that may contribute to data biases.
![]() |
Implementing a chatbot in a React application
import { ChatBot } from "ml-fasttrack"
function App() {
const bot = {
id: 0,
name: "ExampleBot",
avatarUrl: "/bot-icon.jpg"
}
const user = {
id: 1,
name: "User",
avatarUrl: "/user-icon.jpg"
}
const initialMessages = [
{
author: bot,
timestamp: new Date(),
text: "Hello, ask me anything",
}
];
const [messages, setMessages] = useState(initialMessages);
return (
<>
<ChatBot
bot={bot}
user={user}
messages={messages}
placeholder="Type a question"
noResponseText="No response available"
onSourceClick={(event, srcId) => console.log("Clicked", srcId)}
parameters={{
host: '127.0.0.1',
port: 4015,
path: '/api/fasttrack/chat',
}}
/>
</>
)
}
export default App
In the example above:
- The
botanduserobjects configure the bot and user outputs. - A
messagesarray holds the conversation messages and initializes with an introductory message from the bot. - The
onSourceClickcallback executes when a source item from the response is clicked. - The
parametersobject defines how the UI connects to the chat backend. Ifparametersis not defined, the connection properties set in MarkLogicProvider are used with apathvalue ofapi/fasttrack/chat. - The ChatBot widget uses the
postChat()method in MarkLogicContext to handle messages.
These widget props are optional and default to plain configurations if none is provided. The example code output:
![]() |
Implementing ChatBot with custom message handling
import { useState, useContext } from "react";
import { ChatBot, MarkLogicContext } from "ml-fasttrack"
function App() {
const bot = {
id: 0,
name: "ExampleBot",
avatarUrl: "/bot-icon.jpg"
}
const user = {
id: 1,
name: "User",
avatarUrl: "/user-icon.jpg"
}
const initialMessages = [
{
author: {bot},
timestamp: new Date(),
text: "Hello, ask me anything",
}
];
const context = useContext(MarkLogicContext);
const [messages, setMessages] = useState(initialMessages);
const addNewMessage = async (event) => {
const latestUserMessage = event.message;
// Add user message and then show loading indicator
setMessages((oldMessages) => [...oldMessages, event.message]);
setMessages((oldMessages) => [...oldMessages,
{
author: bot,
typing: true,
}
]);
await context.postChat(latestUserMessage.text, context.combinedQuery, {})
.then((response) => {
setMessages((oldMessages) => [...oldMessages,
{
author: bot,
timestamp: new Date(),
// Remove any bracketed text from the response
text: response.output.replace(/ *\[[^)]*\] */g, ""),
}
]
)});
};
return (
<>
<ChatBot
bot={bot}
user={user}
messages={messages}
onSendMessage={addNewMessage}
customBotResponse={true}
/>
</>
)
}
export default App
In the example above:
- The callback function
addNewMessage:- Receives an event object containing the message from the user.
- Adds message text from the user to the conversation console and displays a typing indicator.
- Executes the
postChat()method from MarkLogicContext to retrieve a response to the message text. - Creates a new message object when a response is returned and adds to the
messagesarray. The new message then appears in the conversation console. In this example, the message is transformed to remove any bracketed text.
- The
customBotResponsemethod is set to true to prevent the ChatBot widget from adding extra messages to the messages array.
ChatBot API
Prop |
Type |
Description |
|---|---|---|
user |
|
Represents the user participant in the chat. See the KendoReact UserProps. |
bot |
|
Represents the bot participant in the chat. See the KendoReact UserProps. |
messages |
|
Represents an array of Chat Messages. See the KendoReact MessageProps. |
timestampFormat |
|
Format for the timestamp of the chat messages. The default is |
placeholder |
|
Placeholder text for the message input field when it is empty. |
width |
|
Sets the width of the ChatBot. The default is |
responseTransform |
|
Callback function for transforming the chat response. Accepts the chat response and returns a transformed response to be used by the widget. |
messageBox |
|
Custom component to render the message input field and the Send button. See the KendoReact ChatMessageBoxProps. |
messageContentTemplate |
|
Custom template for rendering message content. Overrides the component's default template that displays bot responses with source citations when available. See the KendoReact ChatMessageTemplateProps. |
onSendMessage |
|
Callback function triggered when the user types a message and clicks the Send button or presses Enter. |
onSourceClick |
|
Callback function triggered when a source is clicked. The function can receive the event and respective source ID as arguments. |
sourceTruncation |
|
Number of characters to display for each source item label. If the source label text exceeds the truncation value, it is truncated and an ellipsis is added. |
customBotResponse |
|
Boolean value which controls whether to use the widget's default bot response or not. When set to true, create a custom method to update the 'messages' object with your ideal bot response. The default is |
noResponseText |
|
Text to display when the bot has no response to the user message. This is displayed as a chat message. |
className |
|
Class name applied to the widget. |
showRestart |
|
Whether the restart button to clear the conversation is rendered. The default is |
onRestart |
|
Callback function triggered when the restart button is clicked. The function receives the event. |
showSources |
|
Whether source citations for bot responses are displayed in the chat, assuming `customBotResponse` is set to |
parameters |
|
An object of parameters for connecting to the ChatBot service. These will override the connection settings defined with MarkLogicProvider. |

