Skip to main content

Smash Chat Events

Hook into chat interactions to trigger custom application logic.

Overview

The Smash widget provides a set of event callbacks that allow you to respond to user actions and AI responses. This is useful for tracking usage, updating application state, or triggering other UI elements.

Available Events

onMessageSent

Triggered when the user clicks the send button or presses enter.

<SmashChatWidget onMessageSent={(message) => console.log('User sent:', message)} />

onResponseReceived

Triggered when the AI finishes generating a response.

<SmashChatWidget onResponseReceived={(response) => console.log('AI responded:', response)} />

onOpen / onClose

Triggered when the chat window is opened or closed.

<SmashChatWidget 
onOpen={() => console.log('Chat opened')}
onClose={() => console.log('Chat closed')}
/>

onError

Triggered when an error occurs during communication with the backend.

<SmashChatWidget onError={(error) => console.error('Chat error:', error)} />

Use Cases

  • Analytics: Track how many messages users are sending to the AI.
  • State Management: Update the dashboard data based on the AI's suggestions.
  • Notifications: Show a toast notification when the AI provides a specific type of answer.

Best Practices

  • Do this: Use the onError event to provide helpful feedback to the user if the AI service is unavailable.
  • Do this: Keep your event handlers lightweight to avoid blocking the UI thread.
  • Don't do this: Perform heavy data processing directly in the event handlers; use a background worker or a separate service if needed.