Documentation
Components
Message

Message Component

The Message component renders individual chat messages with support for different roles, timestamps, and actions.

Import

import { Message } from 'aichatkit'

Usage

Basic Example

basic-message.tsx
import { Message } from 'aichatkit'
 
function BasicMessage() {
  const message = {
    id: '1',
    role: 'assistant',
    content: 'Hello! How can I help you today?',
    timestamp: new Date()
  }
 
  return <Message message={message} />
}

With Actions

message-with-actions.tsx
<Message 
  message={message}
  showActions={true}
  onCopy={(content) => navigator.clipboard.writeText(content)}
  onRetry={() => console.log('Retry message')}
  onEdit={(newContent) => console.log('Edit message:', newContent)}
/>

API Reference

Props

PropTypeDefaultDescription
messageMessage-The message object to render
showActionsbooleanfalseWhether to show message actions
showTimestampbooleanfalseWhether to show timestamp
showAvatarbooleanfalseWhether to show user avatar
onCopy(content: string) => void-Copy action callback
onRetry() => void-Retry action callback
onEdit(content: string) => void-Edit action callback

The Message component automatically handles different message types and provides appropriate styling for each role.