Chat
Overview
The Chat component is a core UI component of the Shopping Assistant SDK that renders the complete chat interface, including conversation messages, initial prompts, loading states, and message rendering. It provides a fully functional chat experience with support for user messages, AI responses, product displays, and customizable styling.
Usage
// importing component
import { Chat } from "@unbxd-ui/react-shopping-assistant-components";Code Example
import { UnbxdShoppingAssistantWrapper } from "@unbxd-ui/react-shopping-assistant-hooks";
import { Chat } from "@unbxd-ui/react-shopping-assistant-components";
function ShoppingAssistantApp() {
return (
<UnbxdShoppingAssistantWrapper siteKey="YOUR_SITE_KEY" convStorageType="LOCALSTORAGE">
<div className="chat-container">
<Chat />
</div>
</UnbxdShoppingAssistantWrapper>
);
}The Chat component must be used within the UnbxdShoppingAssistantWrapper to ensure that the component and the shopping assistant functionality work properly.
Props
- A custom component to display an initial welcome message when the chat loads.
- This component appears above the chat messages and initial prompts.
- Default Value:
const InitialMessageComponent = () => {
return (
<div className="initial-message-component">
Hi there! 👋
<br />
I'm your Furniture Shopping Assistant, ready to help you find exactly what you're looking for. ✨ — What would you like to shop for today?
</div>
);
};- A custom component that displays clickable prompt suggestions to help users get started with the shopping assistant.
- Shows predefined example questions that users can click to automatically ask the AI agent.
- Useful for onboarding new users and showcasing the types of queries the assistant can handle.
- Each prompt is interactive and will trigger a conversation when clicked.
- In props it receives
promptswhich are the questions received from the api through questions api. - Default Value:
const InitialPrompts = (props: InitialPromptsProps) => {
const {
onPromptClick = defaultInitialPromptsProps.onPromptClick,
prompts=[]
} = props;
const { askAgent } = useShoppingAssistant();
const handlePromptClick = (prompt: string) => {
onPromptClick && onPromptClick(prompt);
askAgent(prompt);
};
const renderInitialPrompts = () => {
if (!prompts) return null;
return prompts.map((prompt: string) => <InitialPrompt prompt={prompt} onPromptClick={() => handlePromptClick(prompt)} key={prompt} />);
};
return (
<div className="initial-prompts-container">
<div className="initial-prompts-label">{""}</div>
<div className="initial-prompts-wrapper">{renderInitialPrompts()}</div>
</div>
);
};- A custom component to display while the AI is processing and generating responses.
- Shows during API calls and conversation loading states.
- Default Value:
const LoadingComponent = () => {
return <div className="loading-component">Awaiting response...</div>;
};- A custom icon component to display next to user messages.
- Helps distinguish user messages in the conversation.
- Default Value:
const UserIconComponent = () => {
return <>Me</>;
};- A custom icon component to display next to AI assistant messages.
- Helps distinguish AI responses in the conversation.
- Default Value:
const AIIconComponent = () => {
return <>AI</>;
};- A custom component for rendering user messages in the chat.
- Receives
message,UserIconComponent, and optionallyimageas props. When visualAssistant is enabled in the wrapper, user messages can include an attached image (base64 string); passimageto show a preview or indicator in the message. - Default Value:
const UserMessage = ({ message, image, UserIconComponent }: UserMessageProps) => {
return <div className="user-message-container">
<div className="user-message-text">
{message}
</div>
{image && <img src={image} alt="Attached" className="user-message-image" />}
<div className="user-message-icon-wrapper">
{UserIconComponent && <UserIconComponent />}
</div>
</div>;
};- A custom component for rendering AI assistant messages in the chat.
- Receives
response,AIIconComponent, andResponseChatComponents(used internally to render message, filters, products, and any extra response keys). - Render components inside pass
index,allData(full response payload), anddata(for dynamic keys only) instead of spreading the value as props. - Default Value: Built-in AIMessage component with product display support.
const AIMessage = ({ response, AIIconComponent, ResponseChatComponents }: AIMessageProps) => {
const { message, products = [], filters = [] } = response;
const {
message: MessageComp = MessageComponent,
filters: FiltersComponent = Filters,
products: ProductsComponent = ProductCarousel,
} = ResponseChatComponents ?? {};
return (
<div className="ai-message-container">
<div className="ai-message-icon-wrapper">{AIIconComponent && <AIIconComponent />}</div>
<div className="ai-message-wrapper">
{message && <MessageComp message={message} />}
{filters.length > 0 && filters.map((f) => <FiltersComponent key={f.field} field={f.field} options={f.options} onFilterClick={...} />)}
{products.length > 0 && <ProductsComponent products={products} />}
</div>
</div>
);
};- An object of React components used to render parts of the AI response inside AIMessageComponent. Keys map response data to components: message (text), filters (filter chips), products (product list/carousel), and any other keys present in the API response (e.g. custom blocks).
- Default Value:
{ message: MessageComponent, filters: Filters, products: ProductCarousel }
Shape:
{
message?: React.ElementType; // Renders the assistant text message (receives: message, allData, index)
filters?: React.ElementType; // Renders filter options (receives: field, options, onFilterClick, allData, index, data)
products?: React.ElementType; // Renders product recommendations (receives: products, allData, index, data)
table_info?: React.ElementType; // Renders table information (receives: data, allData, index)
[key: string]: React.ElementType | undefined; // Extra keys from API response (receives: index, allData, data)
}message
Component receives message (string). Renders the AI’s text.
filters
Component receives field, options, onFilterClick. Renders clickable filter options that call askAgent with the selected filter.
products
Component receives products (array). Renders a product carousel or list.
table_info
Component receives data (array) that contains the comparison data that can be used to compare products side by side to find the best option for your needs. Use the type="comparison" prop to display the comparison table.
- Any other keys on the response object can have a matching component in ResponseChatComponents; they will be rendered with the corresponding value as props.










