Overview

Basic ChatBot

This demo displays a basic ChatBot, which includes:

  1. The <ChatbotToggle> that controls the <Chatbot> container.
  2. A <ChatbotHeader> with all built sub-components laid out, including a <ChatbotHeaderTitle> that changes its presentation depending on the display mode.
  3. The ability to swap display modes via <ChatbotHeaderOptionsDropdown>
  4. <ChatbotContent> and <MessageBox> with:
  • A <ChatbotWelcomePrompt>
  • An initial user <Message> and an initial bot message with message actions.
  • Logic for enabling auto-scrolling to the most recent message whenever a new message is sent or received using a scrollToBottomRef
  1. A <ChatbotFooter> with a <ChatbotFootNote> and a <MessageBar> that contains the abilities of:
  • Speech to text.
  • Sending a message to the ChatBot.
  • Receiving a response from a backend AI tool with a loading message state.
  1. A <ChatbotConversationHistoryNav> toggled open and closed by the <ChatbotHeaderMenu> in the <ChatbotHeader>.

  2. A "Skip to chatbot" button that allows you to skip to the chatbot content via the PatternFly skip to content component. To display this button you must tab into the main window.

Basic ChatBot screenshot

Compact ChatBot

This demo displays a basic compact ChatBot

Compact ChatBot screenshot

Embedded ChatBot

This demo displays an embedded ChatBot. Embedded ChatBots are meant to be placed within a page in your product. This demo includes:

  1. A PatternFly page with a sidebar, "Skip to chatbot" button, and masthead. To display the "Skip to chatbot" button you must tab into the main window.
  2. A <Chatbot> container.
  3. A <ChatbotHeader> with all built sub-components laid out, including a <ChatbotHeaderTitle>
  4. <ChatbotContent> and <MessageBox> with:
    • A <ChatbotWelcomePrompt>
    • An initial user <Message> and an initial bot message with message actions.
    • Logic for enabling auto-scrolling to the most recent message whenever a new message is sent or received using a scrollToBottomRef
  5. A <ChatbotFooter> with a <ChatbotFootNote> and a <MessageBar> that contains the abilities of:
    • Speech to text.
    • Sending a message to the ChatBot.
    • Receiving a response from a backend AI tool with a loading message state.
  6. A <ChatbotConversationHistoryNav> that can be toggled by the <ChatbotHeaderMenu> in the <ChatbotHeader>.
Embedded ChatBot screenshot

Inline drawer ChatBot

This demo displays a ChatBot in a static, inline drawer. This demo includes:

  1. An empty PatternFly page with a sidebar and masthead.
  2. A basic ChatBot, placed beside the page content. It does not overlay the page content, cannot be minimized, and does not allow you to change the display mode by default.

Note: The inline drawer ChatBot is built to fit and perform within a drawer, but the implementation of the drawer is up to you. This drawer can look different for each product, but will often be placed to the side of the page, inline with the page content.

Inline drawer ChatBot screenshot

Comparing ChatBots

To let users compare how different ChatBots respond to the same prompt, you can add multiple ChatBots within the same window. The following demo illustrates a comparison view pattern that allows users to toggle between different conversations in a single ChatBot window.

Your code structure should look like this:

<Page ... >
  <div className="pf-chatbot__compare-container">
    <Compare ... />
    <ChatbotFooter ... >
      <MessageBar ... />
    </ChatbotFooter>
  </div>
</Page>
Comparing ChatBots screenshot

Props

Chatbot

*required
NameTypeDefaultDescription
childrenrequiredReact.ReactNodeContent to be displayed in the chatbot
ariaLabelstringCustom aria label applied to focusable container
classNamestringCustom classname for the Chatbot component
displayModeChatbotDisplayModeDisplay Mode for the Chatbot
innerRefReact.Ref<HTMLDivElement>Ref applied to chatbot
isCompactbooleanDensity of information within the ChatBot
isVisiblebooleanVisibility flag for the chatbot

ChatbotToggle

*required
NameTypeDefaultDescription
tooltipLabelrequiredReact.ReactNodeContents of the tooltip applied to the toggle button
classNamestringClass name applied to toggle
closedToggleIcon() => JSX.ElementAn image displayed in the chatbot toggle when it is closed
innerRefReact.Ref<HTMLButtonElement>Ref applied to toggle
isChatbotVisiblebooleanFlag indicating visibility of the chatbot appended to the toggle
isRoundbooleanWhether toggle is a circle
onToggleChatbot() => voidCallback fired when toggle button is clicked
openIconTestIdstringTest id applied to default open icon
toggleButtonLabelstringAccessible label for the toggle button
tooltipPropsOmit<TooltipProps, 'content'>Props spread to the PF Tooltip component

ChatbotContent

*required
NameTypeDefaultDescription
childrenrequiredReact.ReactNodeContent to be displayed in the chatbot
classNamestringCustom classname for the ChatbotContent component

ChatbotWelcomePrompt

*required
NameTypeDefaultDescription
descriptionrequiredstringWelcome message
titlerequiredstringTitle for the welcome message
classNamestringCustom classname for the WelcomePrompt component
isCompactbooleanfalse
promptsWelcomePrompt[]Custom basic prompts to help users coming for the first time to chatbot
testIdstringCustom test id for the WelcomePrompt component

ChatbotFooter

*required
NameTypeDefaultDescription
childrenReact.ReactNodeChildren for the Footer that supports MessageBar and FootNote components
classNamestringCustom classname for the Footer component
isCompactboolean

MessageBar

*required
NameTypeDefaultDescription
onSendMessagerequired(message: string | number) => voidCallback to get the value of input message by user
allowedFileTypesAcceptSpecifies the file types accepted by the attachment upload component. Files that don't match the accepted types will be disabled in the file picker. For example, allowedFileTypes: { 'application/json': ['.json'], 'text/plain': ['.txt'] }
alwayShowSendButtonbooleanFlag to always to show the send button. By default send button is shown when there is a message in the input field
attachMenuPropsMessageBarWithAttachMenuPropsProps to enable a menu that opens when the Attach button is clicked, instead of the attachment window
buttonProps{ attach?: { tooltipContent?: string; props?: ButtonProps; inputTestId?: string; tooltipProps?: Omit<TooltipProps, 'content'>; }; stop?: { tooltipContent?: string; props?: ButtonProps; tooltipProps?: Omit<TooltipProps, 'content'> }; send?: { tooltipContent?: string; props?: ButtonProps; tooltipProps?: Omit<TooltipProps, 'content'> }; microphone?: { tooltipContent?: { active?: string; inactive?: string }; language?: string; props?: ButtonProps; tooltipProps?: Omit<TooltipProps, 'content'>; }; }Prop to allow passage of additional props to buttons
classNamestringClass Name for the MessageBar component
displayModeChatbotDisplayModeDisplay mode of chatbot, if you want to message bar to resize when the display mode changes
dropzonePropsDropzoneOptionsAdditional props passed to react-dropzone
handleAttach(data: File[], event: DropEvent) => voidCallback function for when attach button is used to upload a file
handleStopButton(event: React.MouseEvent<HTMLButtonElement>) => voidCallback function for when stop button is clicked
hasAttachButtonbooleanFlag to disable/enable the Attach button
hasMicrophoneButtonbooleanFlag to enable the Microphone button
hasStopButtonbooleanFlag to enable the Stop button, used for streaming content
innerRefReact.Ref<HTMLTextAreaElement>Ref applied to message bar textarea, for use with focus or other custom behaviors
isAttachmentDisabledbooleanWhether attachments are disabled
isCompactbooleanWhether message bar is compact
isSendButtonDisabledbooleanFlag to provide manual control over whether send button is disabled
listeningTextstringPlaceholder text when listening
maxFilesnumberMax number of files allowed
maxSizenumberMax file size allowed
minSizenumberMinimum file size allowed
onAttach<T extends File>(acceptedFiles: T[], fileRejections: FileRejection[], event: DropEvent) => voidCallback when file(s) are attached
onAttachRejected(fileRejections: FileRejection[], event: DropEvent) => voidCallback function for AttachButton when an attachment fails
onChange(event: React.ChangeEvent<HTMLTextAreaElement>, value: string | number) => voidA callback for when the text area value changes.
placeholderstringPlaceholder for message input
validator<T extends File>(file: T) => FileError | readonly FileError[] | nullValidator for files; see https://react-dropzone.js.org/#!/Custom%20validation for more information

ChatbotFootnote

*required
NameTypeDefaultDescription
labelrequiredstringLabel to show for the footnote
classNamestringCustom classname for the Footnote component
popoverChatbotFootnotePopoverConfig for the popover which opens up when footnote is clicked

MessageBox

*required
NameTypeDefaultDescription
childrenrequiredReactNodeContent to be displayed in the message box
announcementstringContent that can be announced, such as a new message, for screen readers
ariaLabelstring'Scrollable message log'Custom aria-label for scrollable portion of message box
classNamestringCustom classname for the MessageBox component
enableSmartScrollbooleanfalseFlag to enable automatic scrolling when new messages are added
Deprecated: innerRefReact.Ref<HTMLDivElement>innerRef has been deprecated. Use ref instead. Ref applied to message box
onScrollToBottomClick() => voidClick handler for additional logic for when scroll to bottom jump button is clicked
onScrollToTopClick() => voidClick handler for additional logic for when scroll to top jump button is clicked
position'top' | 'bottom''top'Modifier that controls how content in MessageBox is positioned within the container

Message

*required
NameTypeDefaultDescription
avatarrequiredstringAvatar src for the user
rolerequired'user' | 'bot'Role of the user sending the message
actions{ [key: string]: ActionProps; }Props for message actions, such as feedback (positive or negative), copy button, share, and listen
additionalRehypePluginsPluggableListAdditional rehype plugins passed from the consumer
attachmentsMessageAttachment[]Array of attachments attached to a message
avatarPropsOmit<AvatarProps, 'alt'>Any additional props applied to the avatar, for additional customization
botWordstringLabel for the English word "AI," used to tag messages with role "bot"
cancelWordstringLabel for the English word "Cancel" used in edit mode.
codeBlockProps{ /** Aria label applied to code blocks */ 'aria-label'?: string; /** Class name applied to code blocks */ className?: string; /** Whether code blocks are expandable */ isExpandable?: boolean; /** Length of text initially shown in expandable code blocks; defaults to 10 characters */ maxLength?: number; /** Additional props passed to expandable section if isExpandable is applied */ expandableSectionProps?: Omit<ExpandableSectionProps, 'ref'>; /** Additional props passed to expandable toggle if isExpandable is applied */ expandableSectionToggleProps?: ExpandableSectionToggleProps; /** Link text applied to expandable toggle when expanded */ expandedText?: string; /** Link text applied to expandable toggle when collapsed */ collapsedText?: string; }Props for code blocks
contentstringMessage content
editFormPropsFormPropsProps for edit form
editPlaceholderstringPlaceholder for edit input
errorAlertPropsOptional inline error message that can be displayed in the message
extraContentMessageExtraContentExtra Message content
hasRoundAvatarbooleanWhether avatar is round
idstringUnique id for message
innerRefRef<HTMLDivElement>Ref applied to message
isCompactbooleanSets message to compact styling.
isEditablebooleanWhether message is in edit mode
isLiveRegionbooleanTurns the container into a live region so that changes to content within the Message, such as appending a feedback card, are reliably announced to assistive technology.
isLoadingbooleanSet this to true if message is being loaded
linkPropsButtonPropsProps for links
loadingWordstringLabel for the English "Loading message," displayed to screenreaders when loading a message
namestringName of the user
onEditCancel(event: ReactMouseEvent<HTMLButtonElement, MouseEvent>) => voidCallback functionf or when edit cancel update button is clicked
onEditUpdate(event: ReactMouseEvent<HTMLButtonElement, MouseEvent>) => voidCallback function for when edit mode update button is clicked
openLinkInNewTabbooleanWhether to open links in message in new tab.
quickResponseContainerPropsOmit<LabelGroupProps, 'ref'>Props for quick responses container
quickResponsesQuickResponse[]Props for quick responses
quickStarts{ quickStart: QuickStart; onSelectQuickStart: (id?: string) => void; minuteWord?: string; minuteWordPlural?: string; prerequisiteWord?: string; prerequisiteWordPlural?: string; quickStartButtonAriaLabel?: string; className?: string; onClick?: () => void; action?: QuickstartAction; }Props for QuickStart card
sourcesSourcesCardPropsSources for message
tablePropsRequired<Pick<TableProps, 'aria-label'>> & TablePropsProps for table message. It is important to include a detailed aria-label that describes the purpose of the table.
timestampstringTimestamp for the message
updateWordstringLabel for the English word "Update" used in edit mode.
userFeedbackCompleteOmit<UserFeedbackCompleteProps, 'ref'>Props for user feedback response
userFeedbackFormOmit<UserFeedbackProps, 'ref'>Props for user feedback card

MessageBarWithAttachMenuProps

*required
NameTypeDefaultDescription
attachMenuItemsrequiredReact.ReactNodeItems in menu
isAttachMenuOpenrequiredbooleanFlag to enable whether attach menu is open
onAttachMenuInputChangerequired(value: string) => voidA callback for when the input value in the menu changes.
onAttachMenuToggleClickrequired() => voidA callback for when the attachment menu toggle is clicked
setIsAttachMenuOpenrequired(isOpen: boolean) => voidCallback to close attach menu
attachMenuInputPlaceholderstringPlaceholder for search input
onAttachMenuOnOpenChangeKeysstring[]Keys that trigger onOpenChange, defaults to tab and escape. It is highly recommended to include Escape in the array, while Tab may be omitted if the menu contains non-menu items that are focusable.
onAttachMenuOpenChange(isOpen: boolean) => voidCallback to change the open state of the menu. Triggered by clicking outside of the menu.
onAttachMenuSelect(event?: React.MouseEvent<Element, MouseEvent>, value?: string | number) => voidFunction callback called when user selects item in menu.

CompareProps

*required
NameTypeDefaultDescription
firstChildrequiredReact.ReactNodeFirst of two children to render
firstChildDisplayNamerequiredstringDisplay name for first child, used in mobile toggle
secondChildrequiredReact.ReactNodeSecond of two children to render
secondChildDisplayNamerequiredstringDisplay name for second child, used in mobile toggle
onToggleClick(event: MouseEvent | React.MouseEvent<any, MouseEvent> | React.KeyboardEvent<Element>) => voidCallback for when mobile toggle is used
toggleGroupAriaLabelstringAria label for mobile toggle group
We use cookies on our websites to deliver our online services. Details about how we use cookies and how you may disable them are set out in our Privacy Statement. By using this website you agree to our use of cookies.