Chat Widget

Chat Widget

Add an AI-powered chat widget to your application. The chat widget provides instant AI assistance to your users, powered by your knowledge base and system prompt.

Overview

The chat widget is a separate feature from the SDK tracking and user flows. You can:

  • Use just the SDK (user flows, session recording, event tracking)
  • Use just the chat widget
  • Use both together (recommended)

Quick Start

React / Next.js

import { ProduckProvider, ProduckChat } from '@prodact.ai/sdk/react';
 
function App() {
  return (
    <ProduckProvider
      config={{
        sdkKey: 'your-sdk-key',
        apiUrl: 'https://api.prodact.ai/api/v1',
      }}
    >
      <YourApp />
      
      {/* Add the chat widget */}
      <ProduckChat 
        position="bottom-right"
        theme="auto"
        title="Support"
      />
    </ProduckProvider>
  );
}

Vue.js

import { createProduck } from '@prodact.ai/sdk';
 
const produck = createProduck({
  sdkKey: 'your-sdk-key',
  apiUrl: 'https://api.prodact.ai/api/v1',
});
 
await produck.init();
 
// Show chat widget
produck.showChat({
  position: 'bottom-right',
  theme: 'auto',
});

Vanilla JavaScript

<script src="https://api.prodact.ai/api/v1/sdk/sdk.js"></script>
<script>
  Produck.init({
    sdkKey: 'your-sdk-key',
    apiUrl: 'https://api.prodact.ai/api/v1',
    position: 'bottom-right',
    theme: 'auto',
    title: 'Support',
  });
</script>

ProduckChat Props

PropTypeDefaultDescription
position'bottom-right' | 'bottom-left''bottom-right'Widget position
theme'light' | 'dark' | 'auto''auto'Color theme
titlestring'Chat'Widget header title
primaryColorstring'#6366f1'Brand color
welcomeMessagestring-Initial greeting message
placeholderstring'Type a message...'Input placeholder
showBrandingbooleantrueShow "Powered by Prodact"
initialOpenbooleanfalseStart with widget open
hideWhenClosedbooleanfalseHide button when closed

Customization Examples

Custom Branding

<ProduckChat 
  position="bottom-right"
  theme="light"
  title="Acme Support"
  primaryColor="#ff6b35"
  welcomeMessage="Hi! 👋 How can we help you today?"
  placeholder="Ask us anything..."
/>

Dark Theme

<ProduckChat 
  position="bottom-left"
  theme="dark"
  title="Need Help?"
/>

Auto Theme (Follows System)

<ProduckChat 
  theme="auto"  // Matches user's system preference
/>

Programmatic Control

Control the chat widget from your code using the useProduck hook:

import { useProduck } from '@prodact.ai/sdk/react';
 
function SupportButton() {
  const { openChat, closeChat, toggleChat } = useProduck();
 
  return (
    <button onClick={openChat}>
      Open Support Chat
    </button>
  );
}

Available Methods

MethodDescription
openChat()Open the chat widget
closeChat()Close the chat widget
toggleChat()Toggle open/closed state
sendMessage(text)Send a message programmatically
clearChat()Clear chat history

Without the Widget (Headless Mode)

Use chat functionality without the default UI:

import { useProduckMessages, useProduck } from '@prodact.ai/sdk/react';
 
function CustomChat() {
  const { messages, sendMessage, isLoading } = useProduckMessages();
  const [input, setInput] = useState('');
 
  const handleSend = () => {
    sendMessage(input);
    setInput('');
  };
 
  return (
    <div className="my-custom-chat">
      {messages.map((msg, i) => (
        <div key={i} className={msg.role}>
          {msg.content}
        </div>
      ))}
      
      <input 
        value={input} 
        onChange={(e) => setInput(e.target.value)}
        placeholder="Type a message..."
      />
      <button onClick={handleSend} disabled={isLoading}>
        Send
      </button>
    </div>
  );
}

Integration with Operations

The chat can trigger Operations in your application:

import { useProduckAction } from '@prodact.ai/sdk/react';
 
function App() {
  // Register action handlers
  useProduckAction('navigate', ({ path }) => {
    router.push(path);
  });
 
  useProduckAction('open-modal', ({ modal }) => {
    setActiveModal(modal);
  });
 
  return (
    <ProduckProvider config={{ sdkKey: 'your-key' }}>
      <YourApp />
      <ProduckChat />
    </ProduckProvider>
  );
}

When the AI decides an action is needed, it will automatically call your registered handlers.


Mobile Responsiveness

The chat widget automatically adapts to mobile screens:

  • Full-screen mode on small devices
  • Touch-optimized interactions
  • Keyboard handling for input

Accessibility

The chat widget includes:

  • ARIA labels for screen readers
  • Keyboard navigation (Tab, Enter, Escape)
  • Focus management
  • High contrast support

Troubleshooting

Widget Not Appearing

  1. Check that ProduckProvider wraps your app
  2. Verify your SDK key is correct
  3. Check browser console for errors

Chat Not Responding

  1. Verify apiUrl is set correctly
  2. Check network tab for failed requests
  3. Ensure your knowledge base has content

Styling Conflicts

If your CSS conflicts with the widget:

/* Increase specificity for widget styles */
.produck-chat-widget {
  /* Your overrides */
}

Next Steps