Menu

API reference

<CopilotChat>

The CopilotChat is the default chat UI for the Copilot assistant. You can see it in our live demo, and customize it via appearance prop. The CopilotChat must be wrapped in a CopilotProvider.

// Example.jsx
import { CopilotProvider, CopilotChat } from '@copilotjs/react'
import '@copilotjs/styles/default.css'  // Don't forget the styles.

export default function Example() {
  return (
    <CopilotProvider appId="..." userId="..." companyId="..." context={...}>
      <CopilotChat appearance={...} />   // The default chat UI.
    </CopilotProvider>
  )
}

Props

Use these properties to configure the CopilotChat component.

PropDescriptionTypeRequired
isOpenA flag to open or close the chat UI. Default is true.booleanno
appearanceThe visual properties of the chat UI. See details below.objectno
idHTML attribute passed through to the component's container.stringno
classNameHTML attribute passed through to the component's container.stringno
styleHTML attribute passed through to the component's container. Used for inline styling.objectno
onCloseFunction invoked when the user closes the chat UI. See close event example.(event) => voidno
onUndoFunction invoked when the user undoes an action in the chat UI. See undo event example.(event) => voidno
onRedoFunction invoked when the user redoes an action in the chat UI. See redo event example.(event) => voidno

appearance

KeyDescriptionTypeRequired
showHeaderShow/hide the chat header bar.booleanno, default is true
headerTitleThe title on the chat header. Use empty string to hide title.stringno, default is 'Copilot'
welcomeTitleThe title on the welcome panel. Use empty string to hide title.stringno, default is 'How can I help?'
welcomeSubtitleThe subtitle on the welcome panel. Use empty string to hide subtitle.stringno, default is ''
welcomePromptsThe example prompts on the welcome panel. Use empty array to hide examples.string[]no, default is []
showSpeakerNamesShow/hide the full names of user and assistant.booleanno, default is true
userNameThe name of user, shown if showSpeakerNames is true.stringno, default is 'You'
userInitialsThe letter initials of the user avatar.stringno, default is 'Y'
userColorThe background color of the user avatar.stringno, default is '#1f2937'
assistantNameThe name of assistant, shown if showSpeakerNames is true.stringno, default is 'Copilot'
assistantInitialsThe letter initials of the assistant avatar.stringno, default is 'AI'
assistantColorThe background color of the assistant avatar.stringno, default is '#4f46e5'
enableUndoEnable/disable the user to undo actions performed by the assistant, directly in chat UI.booleanno, default is false

Example

<CopilotProvider appId="..." userId="..." companyId="..." context={...}>
  <CopilotChat
    isOpen={true}
    appearance={{
      showHeader: true,
      headerTitle: 'Copilot',
      welcomeTitle: 'How can I help?',
      welcomeSubtitle: 'Describe the action you want to perform.',
      welcomePrompts: ['Add 2 concentric circles.', 'Clear the canvas.'],
      showSpeakerNames: true,
      userName: 'You',
      userInitials: 'Y',
      userColor: '#1f2937',
      assistantName: 'Copilot',
      assistantInitials: 'AI',
      assistantColor: '#4f46e5',
      enableUndo: false,
    }}
    id="my-custom-id"
    className="my-custom-class"
    style={{ width: '300px', height: '500px' }}
    onClose={(event) => console.log('The user closed the chat UI.')}
    onUndo={(event) => console.log('The user undid an action.')}
    onRedo={(event) => console.log('The user redid an action.')}
  />
</CopilotProvider>

Events

The CopilotChat emits multiple types of events, described below.

close

When the user closes the chat UI, the onClose handler is invoked with an event such as:

{
  "type": "close",
  "data": {}
}

undo

When the user undoes an action in the chat UI, the onUndo handler is invoked with an event such as:

{
  "type": "undo",
  "data": {}
}

redo

When the user redoes an action in the chat UI, the onRedo handler is invoked with an event such as:

{
  "type": "redo",
  "data": {}
}
Previous
<CopilotProvider>